Skip to content

Commit 091bcbe

Browse files
committed
update package-lock test
1 parent 99c513e commit 091bcbe

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

.github/workflows/check-package-lock.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ concurrency:
1010
on:
1111
push:
1212
branches:
13-
- main # Run on push to main branch only
13+
- main
14+
paths:
15+
- "package.json"
16+
- "package-lock.json"
1417
pull_request:
1518
branches:
16-
- "**" # Run on PR to any branch
19+
- "**"
20+
paths:
21+
- "package.json"
22+
- "package-lock.json"
1723

1824
jobs:
1925
verify-package-lock:
@@ -44,6 +50,26 @@ jobs:
4450
fi
4551
echo "SUCCESS: package-lock.json file is valid and not empty"
4652
53+
- name: Check package-lock.json is updated when package.json changes
54+
if: github.event_name == 'pull_request'
55+
run: |
56+
git fetch origin ${{ github.base_ref }} --depth=1
57+
58+
# Check if package.json was changed in this PR
59+
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "^package\.json$"; then
60+
echo "package.json was modified - checking if package-lock.json was also updated..."
61+
62+
if ! git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "^package-lock\.json$"; then
63+
echo "ERROR: package.json was changed but package-lock.json was NOT updated"
64+
echo "Please run 'npm install' to update the lock file and commit it"
65+
exit 1
66+
fi
67+
68+
echo "SUCCESS: Both package.json and package-lock.json were updated"
69+
else
70+
echo "SKIP: package.json was not modified, only package-lock.json changed"
71+
fi
72+
4773
- name: Setup Node.js
4874
uses: actions/setup-node@v4
4975
with:

0 commit comments

Comments
 (0)