diff --git a/npm-publish-prerelease/README.md b/npm-publish-prerelease/README.md index b177807b..eb1e5614 100644 --- a/npm-publish-prerelease/README.md +++ b/npm-publish-prerelease/README.md @@ -7,6 +7,7 @@ This action will publish a prerelease version of the package to npm with the spe * `NPM_TOKEN`: (required) the npm token used to publish the package. * `GH_TOKEN`: (optional) the GitHub access token to use (default: `${{ github.token }}`). * `node-version`: (optional) the Node.js version to use for the Action. +* `npm-version`: (optional) the npm version to use for the Action (default: `latest`). * `NPM_TAG`: (optional) NPM [distribution tag](https://docs.npmjs.com/adding-dist-tags-to-packages) (default: `next`). * `PROVENANCE`: (optional) set to `true` to generate provenance statement for the published package. Requires the `id-token: write` permission. diff --git a/npm-publish-prerelease/action.yml b/npm-publish-prerelease/action.yml index 0c65869f..1398b3f4 100644 --- a/npm-publish-prerelease/action.yml +++ b/npm-publish-prerelease/action.yml @@ -16,6 +16,10 @@ inputs: description: 'The Node.js version to use in the Action' required: false default: 'lts/*' + npm-version: + description: 'The npm version to use in the Action' + required: false + default: 'latest' PROVENANCE: description: 'Generate provenance statement for the published package.' default: 'false' @@ -36,6 +40,12 @@ runs: registry-url: https://registry.npmjs.org/ cache: npm + - name: Setup npm + shell: bash + run: npm install --global "npm@${NPM_VERSION}" + env: + NPM_VERSION: ${{ inputs.npm-version }} + - name: git config shell: bash run: | diff --git a/npm-publish-prerelease/bin/publish.sh b/npm-publish-prerelease/bin/publish.sh index d138efa5..514274de 100755 --- a/npm-publish-prerelease/bin/publish.sh +++ b/npm-publish-prerelease/bin/publish.sh @@ -18,10 +18,6 @@ LOCAL_VERSION=$(node -p "require('./package.json').version") LOCAL_BRANCH=$(git branch --show-current) echo "✅ Found ${LOCAL_NAME} ${LOCAL_VERSION} on branch ${LOCAL_BRANCH}" -# Update npm -echo_title "Updating npm to latest version" -npm install -g npm - # If not using Trusted Publishing, validate npm is logged in and ready if [ "${USE_TRUSTED_PUBLISHING:-}" != "true" ]; then echo_title "Checking npm auth" diff --git a/npm-publish/README.md b/npm-publish/README.md index af0cb06a..0dfded66 100644 --- a/npm-publish/README.md +++ b/npm-publish/README.md @@ -8,6 +8,7 @@ The `npm-prepare-release` action is meant to be called first and will create a p * `GH_TOKEN`: (required) the GitHub access token to use. It is recommended to use the standard GitHub Actions access token (used in example). * `node-version`: (optional) the Node.js version to use for the Action. +* `npm-version`: (optional) the npm version to use for the Action (default: `latest`). * `PROVENANCE`: (optional) set to `true` to generate provenance statement for the published package. Requires the `id-token: write` permission. * `CONVENTIONAL_COMMITS`: (optional) set to `true` to generate commit messages that follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#specification) specification. * `SKIP_BUMP_TO_DEV`: (optional) set to `true` to skip bumping to dev version after publishing the release. Might be useful for projects using `nlm`. diff --git a/npm-publish/action.yml b/npm-publish/action.yml index 9c8c798d..9166d064 100644 --- a/npm-publish/action.yml +++ b/npm-publish/action.yml @@ -17,6 +17,10 @@ inputs: description: 'The Node.js version to use in the Action' required: false default: 'lts/*' + npm-version: + description: 'The npm version to use in the Action' + required: false + default: 'latest' PROVENANCE: description: 'Generate provenance statement for the published package.' default: 'false' @@ -42,6 +46,12 @@ runs: node-version: ${{ inputs.node-version }} registry-url: https://registry.npmjs.org/ + - name: Setup npm + shell: bash + run: npm install --global "npm@${NPM_VERSION}" + env: + NPM_VERSION: ${{ inputs.npm-version }} + - name: git config shell: bash run: | diff --git a/npm-publish/bin/publish.sh b/npm-publish/bin/publish.sh index 1ea83b4c..e84b0ffa 100755 --- a/npm-publish/bin/publish.sh +++ b/npm-publish/bin/publish.sh @@ -26,10 +26,6 @@ else echo "✅ Determined only .json files are changed in PR" fi -# Update npm -echo_title "Updating npm to latest version" -npm install -g npm - # Determine and validate release type echo_title "Determining and validating NPM release type" NPM_VERSION_TYPE=$(echo "$PR_HEAD_REF" | awk -F '/' '{print $2}' | awk -F '-' '{print $1}')