File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,10 +10,16 @@ concurrency:
1010on :
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
1824jobs :
1925 verify-package-lock :
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 :
You can’t perform that action at this time.
0 commit comments