Skip to content

Commit 65fa335

Browse files
committed
ci: add lock file sync validation to prevent confusing npm install failures
Add pre-installation validation step in E2E, Lighthouse, and Jest workflows to detect when package-lock.json is out of sync with package.json. This provides clear, actionable error messages instead of cryptic npm ETARGET errors. Affected workflows: - pr-cypress-e2e.yml (E2E Tests) - lighthouse-ci.yml (Lighthouse Performance Audit) - pr-jest-tests.yml (Jest Unit Tests) When lock files are mismatched, workflows now fail with: - Clear error message explaining the problem - Step-by-step instructions to fix it locally - Guidance to run npm install and commit the lock file This improves developer experience by eliminating confusion about npm registry vs lock file sync issues.
1 parent c270201 commit 65fa335

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.github/workflows/lighthouse-ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ jobs:
2828
node-version: '20'
2929
cache: 'npm'
3030

31+
- name: Validate lock file sync
32+
run: |
33+
echo "Validating package-lock.json is in sync with package.json..."
34+
if ! npm ci --dry-run > /dev/null 2>&1; then
35+
echo ""
36+
echo "ERROR: package-lock.json is out of sync with package.json"
37+
echo ""
38+
echo "This usually means package.json was modified but package-lock.json was not updated."
39+
echo ""
40+
echo "To fix this, run the following commands locally and commit the changes:"
41+
echo " 1. npm install"
42+
echo " 2. git add package-lock.json"
43+
echo " 3. git commit -m 'chore: update lock file'"
44+
echo " 4. git push"
45+
echo ""
46+
exit 1
47+
fi
48+
echo "Lock file is in sync. Proceeding with Lighthouse audit..."
49+
3150
- name: Install dependencies
3251
run: npm ci
3352

.github/workflows/pr-cypress-e2e.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ jobs:
2424
node-version: '20'
2525
cache: 'npm'
2626

27+
- name: Validate lock file sync
28+
run: |
29+
echo "Validating package-lock.json is in sync with package.json..."
30+
if ! npm ci --dry-run > /dev/null 2>&1; then
31+
echo ""
32+
echo "ERROR: package-lock.json is out of sync with package.json"
33+
echo ""
34+
echo "This usually means package.json was modified but package-lock.json was not updated."
35+
echo ""
36+
echo "To fix this, run the following commands locally and commit the changes:"
37+
echo " 1. npm install"
38+
echo " 2. git add package-lock.json"
39+
echo " 3. git commit -m 'chore: update lock file'"
40+
echo " 4. git push"
41+
echo ""
42+
exit 1
43+
fi
44+
echo "Lock file is in sync. Proceeding with E2E tests..."
45+
2746
- name: Run Cypress E2E Tests
2847
uses: cypress-io/github-action@v6
2948
with:

.github/workflows/pr-jest-tests.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ jobs:
2626
with:
2727
node-version: '20'
2828

29+
- name: Validate lock file sync
30+
run: |
31+
echo "Validating package-lock.json is in sync with package.json..."
32+
if ! npm ci --dry-run > /dev/null 2>&1; then
33+
echo ""
34+
echo "ERROR: package-lock.json is out of sync with package.json"
35+
echo ""
36+
echo "This usually means package.json was modified but package-lock.json was not updated."
37+
echo ""
38+
echo "To fix this, run the following commands locally and commit the changes:"
39+
echo " 1. npm install"
40+
echo " 2. git add package-lock.json"
41+
echo " 3. git commit -m 'chore: update lock file'"
42+
echo " 4. git push"
43+
echo ""
44+
exit 1
45+
fi
46+
echo "Lock file is in sync. Proceeding with Jest tests..."
47+
2948
- name: Install Dependencies
3049
run: npm install
3150

0 commit comments

Comments
 (0)