Skip to content

Commit

Permalink
fix(nx): update cache logic
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Apr 24, 2024
1 parent a34ffad commit c13f43c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
31 changes: 24 additions & 7 deletions nx-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,33 @@ outputs:
runs:
using: composite
steps:
- name: 'Restore nx cache'
- name: 'Check if cache already exists'
id: prepare
env:
CACHE_DIR: ${{ inputs.cache-dir }}
shell: bash
#language=bash
run: |
if [ -d "$CACHE_DIR" ]; then
echo "cache-exists=true" >> $GITHUB_OUTPUT
else
echo "cache-exists=false" >> $GITHUB_OUTPUT
fi
- name: 'Handle nx cache'
id: cache
uses: actions/cache/restore@v4
uses: actions/cache@v4
if: steps.prepare.outputs.cache-exists == 'false'
with:
path: ${{ inputs.cache-dir }}
key: '${{ runner.os }}-nx-cache-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.action }}'
save-always: true
key: '${{ runner.os }}-nx-cache-${{ github.action }}-${{ github.run_id }}-${{ github.run_attempt }}'
restore-keys: |
${{ runner.os }}-nx-cache-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt}}-
${{ runner.os }}-nx-cache-${{ github.sha }}-${{ github.run_id }}-
${{ runner.os }}-nx-cache-${{ github.sha }}-
${{ runner.os }}-nx-cache-${{ github.action }}-${{ github.run_id }}-
${{ runner.os }}-nx-cache-${{ github.action }}-
${{ runner.os }}-nx-cache-
- name: 'Prune cache'
if: steps.cache.outputs.cache-hit == 'true'
env:
MAX_CACHE_SIZE: ${{ inputs.max-cache-size }}
NX_CACHE_DIRECTORY: ${{ inputs.cache-dir }}
Expand All @@ -51,6 +64,10 @@ runs:
maxSizeKB=$(($MAX_CACHE_SIZE))
cacheDir="$NX_CACHE_DIRECTORY"
if [ ! -d "$cacheDir" ]; then
exit 0
fi
function size() {
(du -sk "$1" 2>/dev/null || echo 0) | cut -f 1
}
Expand Down
7 changes: 0 additions & 7 deletions nx-run-many/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ runs:
using: composite
steps:
- uses: myparcelnl/actions/nx-cache@v4
id: cache
with:
cache-dir: ${{ inputs.cache-dir }}
max-cache-size: ${{ inputs.max-cache-size }}
Expand All @@ -46,9 +45,3 @@ runs:
--output-style=static \
--target="${{ inputs.target }}" \
${{ inputs.args }}
- name: 'Save nx cache'
uses: actions/cache/save@v4
with:
path: ${{ inputs.cache-dir }}
key: ${{ steps.cache.outputs.cache-primary-key }}

0 comments on commit c13f43c

Please sign in to comment.