From 1b8c6443e759b9a117f510fe6c8f34423975d985 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:56:22 +0900 Subject: [PATCH] fix: make updated npm version more accurate in action logs (#38) 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 --- .github/workflows/nodejs-test-reusable.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nodejs-test-reusable.yml b/.github/workflows/nodejs-test-reusable.yml index b678dcb..ffcc0b1 100644 --- a/.github/workflows/nodejs-test-reusable.yml +++ b/.github/workflows/nodejs-test-reusable.yml @@ -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