Skip to content

Commit

Permalink
Timed expiration of npm cache
Browse files Browse the repository at this point in the history
Similar to what is added in actions/setup-node#702, prevents the npm cache from growing indefinitely while still providing a general fallback
  • Loading branch information
Pelle Wessman committed Feb 28, 2023
1 parent db7b634 commit b91a8a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/reusable-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,28 @@ jobs:
if: runner.os != 'Windows'
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT

# New prefix generated every 120 days, to ensure npm cache doesn't grow too large
- name: Get npm cache timed expiration
id: npm-timed-expiration
run: echo "prefix=$(( $(date +%s) / 60 / 60 / 24 / 120 ))" >> $GITHUB_OUTPUT

- name: Restore cache using package-lock.json hash
uses: actions/cache@v3
if: ${{ !inputs.no-lockfile }}
with:
path: ${{ steps.npm-cache-dir-windows.outputs.dir || steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
key: ${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-
- name: Restore cache using package.json hash
uses: actions/cache@v3
if: ${{ inputs.no-lockfile }}
with:
path: ${{ steps.npm-cache-dir-windows.outputs.dir || steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package.json') }}
key: ${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-
- run: npm ci --no-audit --no-fund
if: ${{ !inputs.no-lockfile }}
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/reusable-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,28 @@ jobs:
if: (inputs.npm-pre-sync-script || inputs.npm-post-sync-script) && runner.os != 'Windows'
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT

# New prefix generated every 120 days, to ensure npm cache doesn't grow too large
- name: Get npm cache timed expiration
id: npm-timed-expiration
run: echo "prefix=$(( $(date +%s) / 60 / 60 / 24 / 120 ))" >> $GITHUB_OUTPUT

- name: Restore cache using package-lock.json hash
uses: actions/cache@v3
if: (inputs.npm-pre-sync-script || inputs.npm-post-sync-script) && !inputs.no-lockfile
with:
path: ${{ steps.npm-cache-dir-windows.outputs.dir || steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
key: ${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-
- name: Restore cache using package.json hash
uses: actions/cache@v3
if: (inputs.npm-pre-sync-script || inputs.npm-post-sync-script) && inputs.no-lockfile
with:
path: ${{ steps.npm-cache-dir-windows.outputs.dir || steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package.json') }}
key: ${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-
- run: npm ci --no-audit --no-fund
if: (inputs.npm-pre-sync-script || inputs.npm-post-sync-script) && !inputs.no-lockfile
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,28 @@ jobs:
if: runner.os != 'Windows'
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT

# New prefix generated every 120 days, to ensure npm cache doesn't grow too large
- name: Get npm cache timed expiration
id: npm-timed-expiration
run: echo "prefix=$(( $(date +%s) / 60 / 60 / 24 / 120 ))" >> $GITHUB_OUTPUT

- name: Restore cache using package-lock.json hash
uses: actions/cache@v3
if: ${{ !inputs.no-lockfile }}
with:
path: ${{ steps.npm-cache-dir-windows.outputs.dir || steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
key: ${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-
- name: Restore cache using package.json hash
uses: actions/cache@v3
if: ${{ inputs.no-lockfile }}
with:
path: ${{ steps.npm-cache-dir-windows.outputs.dir || steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package.json') }}
key: ${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-node-${{ steps.npm-timed-expiration.outputs.prefix }}-
- run: npm ci --no-audit --no-fund
if: ${{ !inputs.no-lockfile }}
Expand Down

0 comments on commit b91a8a5

Please sign in to comment.