Skip to content

Commit

Permalink
fix: make updated npm version more accurate in action logs (#38)
Browse files Browse the repository at this point in the history
The current log message "Update npm to latest" is not accurate
because npm can be updated to v9 or v10.

E.g. https://github.com/ybiquitous/.github/actions/runs/12461745399/job/34781727243
  • Loading branch information
ybiquitous authored Dec 23, 2024
1 parent 8fd670c commit 1b8c644
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/nodejs-test-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,31 @@ jobs:
node-version: ${{ inputs.node-version }}
cache: npm

- name: Update npm to latest
- name: Get npm version
id: npm-version
shell: bash
run: |
case $(node -v) in
v16.*|v14.*|v12.*|v10.*)
npm install --global npm@9
major_version=9
;;
v18.*)
npm install --global npm@10
major_version=10
;;
*)
npm install --global npm@latest
echo "latest=true" >> "${GITHUB_OUTPUT}"
echo "version=$(npm view npm version)" >> "${GITHUB_OUTPUT}"
exit 0
;;
esac
echo "Successfully updated npm to $(npm -v)"
version=$(npm view "npm@${major_version}" version --json | jq -r '.[-1]')
echo "version=${version}" >> "${GITHUB_OUTPUT}"
- name: Update npm to ${{ steps.npm-version.outputs.version }}${{ steps.npm-version.outputs.latest && ' (latest)' }}
shell: bash
env:
npm_version: ${{ steps.npm-version.outputs.version }}
run: npm install --global "npm@${npm_version}"

- name: Install dependencies
run: npm ci
Expand Down

0 comments on commit 1b8c644

Please sign in to comment.