Skip to content

Commit

Permalink
fix(cicd): added cache cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JBBianchi committed Nov 29, 2023
1 parent 542b21c commit 8ac04de
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/js-cleanup-cache.yml
Original file line number Diff line number Diff line change
@@ -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 }}
25 changes: 23 additions & 2 deletions .github/workflows/js-package-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
# path: ${{ fromJSON(needs.config.outputs.package-config).path }}

publish:
needs:
needs:
- config
- build
# - test
Expand All @@ -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 }}
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 }}

0 comments on commit 8ac04de

Please sign in to comment.