Skip to content

Commit

Permalink
feat(action): use packages for primary cache key
Browse files Browse the repository at this point in the history
Slight twist on suggestion from #72 using `pwsh` to keep windows agents functional (And play around with how to get it done in pwsh).
  • Loading branch information
peterjokumsen committed Aug 25, 2024
1 parent 7a2fbbe commit fa5f6ca
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ runs:
Write-Output "path=${input}" >> $env:GITHUB_OUTPUT
}
- name: Create packages-only packge-lock
shell: pwsh
run: |
$packageLocks = Get-ChildItem -Path ${{ steps.working_directory.outputs.path }} -Filter 'package-lock.json' -Recurse
foreach ($packageLock in $packageLocks)
{
$lockDirectory = $packageLock.Directory.FullName
$lockPath = $packageLock.FullName
$lockContent = Get-Content -Path $lockPath -Raw `
| ConvertFrom-Json -AsHashTable
$packagesOnly = @{
packages = $lockContent.packages
}
Write-Output "$lockPath -> $lockDirectory/packages-only-lock.json"
$packagesOnly | ConvertTo-Json -Depth 100 `
| Set-Content -Path "$lockDirectory/packages-only-lock.json"
}
- name: Use node_modules from cache [npm]
id: cache-node
uses: actions/cache@v3
Expand All @@ -45,8 +65,9 @@ runs:
with:
# caching node_modules
path: ${{ steps.working_directory.outputs.path }}node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**//packages-only-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
Expand All @@ -58,6 +79,12 @@ runs:
run: |
npm ci
- shell: pwsh
name: Clear package only lock files
run: |
Get-ChildItem -Path ${{ steps.working_directory.outputs.path }} -Filter 'packages-only-lock.json' -Recurse `
| Remove-Item
- shell: pwsh
name: Check path for cache
if: steps.cache-node.outputs.cache-hit != 'true'
Expand Down

0 comments on commit fa5f6ca

Please sign in to comment.