@@ -26,6 +26,14 @@ inputs:
2626 node-auth-token :
2727 description : " The npm registry auth token used to publish the package."
2828 required : true
29+ node-version :
30+ description : " Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0."
31+ required : false
32+ type : string
33+ node-version-file :
34+ description : " File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions."
35+ required : false
36+ type : string
2937 package-name :
3038 description : " The file name for the package tarball in the artifact."
3139 required : true
@@ -47,17 +55,17 @@ inputs:
4755runs :
4856 using : " composite"
4957 steps :
50- # TODO(#1897): Use upstream version of npm
51- - name : Setup npm
52- id : setup-npm
53- uses : slsa-framework/slsa-github-generator/actions/nodejs/setup-npm@main
58+ - name : Setup Node
59+ uses : actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
60+ with :
61+ node-version : ${{ inputs.node-version }}
62+ node-version-file : ${{ inputs.node-version-file }}
5463
5564 - name : Create temp dir
5665 id : temp-dir
5766 shell : bash
5867 run : |
5968 set -euo pipefail
60-
6169 temp_dir=$(mktemp -d)
6270 echo "path=${temp_dir}" >>"${GITHUB_OUTPUT}"
6371
8088 id : publish
8189 shell : bash
8290 env :
83- NPM_PATH : ${{ steps.setup-npm.outputs.npm-path }}
8491 ACCESS : ${{ inputs.access }}
8592 PACKAGE_PATH : " ${{ steps.temp-dir.outputs.path }}/${{ inputs.package-name }}"
8693 ATTESTATION_PATH : " ${{ steps.temp-dir.outputs.path }}/${{ inputs.provenance-download-name }}/${{ inputs.provenance-name }}"
@@ -89,20 +96,23 @@ runs:
8996 run : |
9097 set -euo pipefail
9198
92- publish_flags="--provenance ${ATTESTATION_PATH}"
99+ # Install npm 9.7.1 which includes support for --provenance-file.
100+ npm install -g npm@9.7.1
101+
102+ # Print the npm version.
103+ npm version
104+
105+ publish_flags=("--provenance-file=${ATTESTATION_PATH}")
93106 if [[ "${ACCESS}" != "" ]]; then
94- publish_flags="${publish_flags} --access=${ACCESS}"
107+ publish_flags+=(" --access=${ACCESS}")
95108 fi
96109 if [[ "${DIST_TAG}" != "" ]]; then
97- publish_flags="${publish_flags} --tag=${DIST_TAG}"
110+ publish_flags+=(" --tag=${DIST_TAG}")
98111 fi
99112
100113 # NOTE: Use the absolute path to the tarball because npm tries to check
101114 # a remote github.com repository if the "package spec" looks like it
102115 # could be a "<owner>/<repo-name>" resulting in git errors.
103116 package_abs_path=$(readlink -m "${PACKAGE_PATH}")
104117
105- # Run npm publish using npm fork. We are temporarily using a fork so
106- # that we can specify the provenance bundle.
107- # NOTE: We don't quote $publish_flags because we are using word splitting to add the flags.
108- "${NPM_PATH}/npm" publish --loglevel verbose "${package_abs_path}" ${publish_flags}
118+ npm publish --loglevel verbose "${package_abs_path}" "${publish_flags[@]}"
0 commit comments