diff --git a/.github/workflows/js-cleanup-cache.yml b/.github/workflows/js-cleanup-cache.yml new file mode 100644 index 0000000..5fcf238 --- /dev/null +++ b/.github/workflows/js-cleanup-cache.yml @@ -0,0 +1,33 @@ +name: Cleanup caches + +on: + workflow_call: + inputs: + path: + required: true + type: string + name: + required: true + type: string + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Cleanup + run: | + gh extension install actions/gh-actions-cache + + echo "Fetching list of cache key" + cacheKeys=$(gh actions-cache list -R ${{ github.repository }} --key ${{ inputs.name }} -L 100 | cut -f 1 ) + + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeys + do + gh actions-cache delete $cacheKey -R ${{ github.repository }} --confirm + done + echo "Done" + env: + GH_TOKEN: ${{ github.token }} \ No newline at end of file diff --git a/.github/workflows/js-package-pipeline.yml b/.github/workflows/js-package-pipeline.yml index 6d29283..0ccde77 100644 --- a/.github/workflows/js-package-pipeline.yml +++ b/.github/workflows/js-package-pipeline.yml @@ -80,7 +80,7 @@ jobs: # path: ${{ fromJSON(needs.config.outputs.package-config).path }} publish: - needs: + needs: - config - build # - test @@ -90,4 +90,25 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} with: name: ${{ fromJSON(needs.config.outputs.package-config).name }} - path: ${{ fromJSON(needs.config.outputs.package-config).path }} \ No newline at end of file + path: ${{ fromJSON(needs.config.outputs.package-config).path }} + + cleanup-after-build: + if: (github.event_name != 'push' || github.ref_name != 'main') && github.event_name !='workflow_dispatch' + needs: + - config + - build + # - test + # - lint + with: + name: ${{ fromJSON(needs.config.outputs.package-config).name }} + path: ${{ fromJSON(needs.config.outputs.package-config).path }} + + cleanup-after-publish: + if: (github.event_name == 'push' && github.ref_name == 'main') || github.event_name =='workflow_dispatch' + needs: + - config + - publish + with: + name: ${{ fromJSON(needs.config.outputs.package-config).name }} + path: ${{ fromJSON(needs.config.outputs.package-config).path }} +