Skip to content

Commit

Permalink
refactor: add mismatch check to lockfile workflow (#89)
Browse files Browse the repository at this point in the history
* refactor: add mismatch check to lockfile workflow

* refactor: bring back v3 lockfile check
  • Loading branch information
Syed-Ali-Abbas-Zaidi authored Aug 24, 2023
1 parent 654f6d6 commit aa20ddc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/lockfile-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Check package-lock file version and mismatch issues

# This is a workflow to verify the use of NPM 9, lockfileVersion 3
# and also detects mismatch between pacakge.json and package-lock.json.
# This workflow intends to phase out the older workflow checking for lockfileVersion 2 & 3.

name: lockfile check

on:
- workflow_call

jobs:
version-check:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Retrieve version
id: getversion
run: |
echo "VERSION=$(cat package-lock.json | grep '\"lockfileVersion\": 3,')" >> $GITHUB_ENV
- name: Check value
if: ${{ env.VERSION == null }}
run: |
echo "ERROR: Outdated package-lock file. Use NPM9 to install dependencies "
exit 1
mismatch-check:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Install node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Check sync
run: |
problems=$(npm ls --all --package-lock-only --json | jq '.problems[]?' -r)
if [[ -n "$problems" ]]; then
echo "$problems"
echo
echo "Mismatch between package.json and package-lock.json. Please regenerate package lock file with 'npm install'."
exit 1
fi
2 changes: 2 additions & 0 deletions .github/workflows/lockfileversion-check-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# This is a workflow to verify the use of NPM 9 and lockfileVersion 3
# and intends to phase out the older workflow checking for lockfileVersion 2.

# !IMPORTANT! This workflow needs to be removed once all the consumers start using lockfile-check.yml.

name: lockfileVersion check v3

on:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lockfileversion-check.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#check package-lock file version

# !IMPORTANT! This workflow needs to be removed once all the consumers start using lockfile-check.yml.

name: lockfileVersion check

on:
Expand Down

0 comments on commit aa20ddc

Please sign in to comment.