Skip to content

Commit 495c4b8

Browse files
authored
Enhance CI workflow with lockfile detection and caching
1 parent 82af0b3 commit 495c4b8

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,37 @@ jobs:
1414
- name: Checkout repository
1515
uses: actions/checkout@v4
1616

17-
- name: Set up Node.js
17+
- name: Find lockfiles (for caching)
18+
id: find-lockfiles
19+
run: |
20+
echo "Searching for lockfiles..."
21+
files=$(find . -type f \( -name 'package-lock.json' -o -name 'pnpm-lock.yaml' -o -name 'yarn.lock' -o -name 'npm-shrinkwrap.json' \) -print | sed 's|^\./||')
22+
if [ -n "$files" ]; then
23+
echo "Found lockfiles:"
24+
printf "%s\n" "$files"
25+
# Write a multiline output for cache-dependency-path (newline-separated)
26+
echo "lockfile-paths<<EOF" >> $GITHUB_OUTPUT
27+
printf "%s\n" "$files" >> $GITHUB_OUTPUT
28+
echo "EOF" >> $GITHUB_OUTPUT
29+
else
30+
echo "No lockfiles found"
31+
# set empty output
32+
echo "lockfile-paths=" >> $GITHUB_OUTPUT
33+
fi
34+
35+
- name: Set up Node.js (with cache)
36+
if: ${{ steps.find-lockfiles.outputs.lockfile-paths != '' }}
1837
uses: actions/setup-node@v4
1938
with:
2039
node-version: '20'
2140
cache: 'npm'
22-
# If your repo is a monorepo or lockfiles live in subdirectories, list them here
23-
cache-dependency-path: |
24-
package-lock.json
25-
**/package-lock.json
26-
pnpm-lock.yaml
27-
**/pnpm-lock.yaml
28-
yarn.lock
29-
**/yarn.lock
41+
cache-dependency-path: ${{ steps.find-lockfiles.outputs.lockfile-paths }}
42+
43+
- name: Set up Node.js (no cache)
44+
if: ${{ steps.find-lockfiles.outputs.lockfile-paths == '' }}
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: '20'
3048

3149
- name: Set up Python
3250
uses: actions/setup-python@v4

0 commit comments

Comments
 (0)