Skip to content

Commit

Permalink
Better workflow caching (#5006)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert authored May 22, 2023
1 parent 47a2f73 commit 6797d57
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/clean-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Clean Up Caches By Branch
on:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 7 additions & 1 deletion .github/workflows/repl-artefacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 14
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- name: Build artefacts
run: npm run build:cjs && npm run build:bootstrap
Expand Down
40 changes: 35 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- name: Run tests with coverage
run: npm run ci:coverage
Expand All @@ -47,8 +53,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- name: Lint
run: npm run ci:lint
Expand All @@ -73,8 +85,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- name: Run tests
run: npm run ci:test:only
Expand All @@ -95,8 +113,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- name: Run tests
run: npm run ci:test:only
Expand All @@ -117,8 +141,14 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- name: Run tests
run: npm run ci:test:only
Expand Down

0 comments on commit 6797d57

Please sign in to comment.