Skip to content

Commit 9b3d983

Browse files
authored
feat: Use upstream npm for uploading provenance. (#2257)
Fixes #1897 --------- Signed-off-by: Ian Lewis <ianlewis@google.com>
1 parent 4314fec commit 9b3d983

3 files changed

Lines changed: 24 additions & 70 deletions

File tree

actions/nodejs/publish/action.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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:
4755
runs:
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
@@ -80,7 +88,6 @@ runs:
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[@]}"

actions/nodejs/setup-npm/action.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

internal/builders/nodejs/generate-layout.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ digest=$(echo "${integrity_digest}" | cut -d'-' -f2- | base64 -d | od -A n -v -t
7070

7171
# NOTE: the name of the attestation should be configurable.
7272
filename=$(echo "${PACK_JSON}" | jq -r '.[0].filename')
73-
attestation_name="${filename%.*}.intoto"
73+
attestation_name="${filename%.*}"
7474
cat <<EOF | jq | tee "$SLSA_OUTPUTS_ARTIFACTS_FILE"
7575
{
7676
"version": 1,

0 commit comments

Comments
 (0)