Skip to content

Commit bfb9c59

Browse files
workflows: hoist matrix values to job-level env, drop expression substitution in run: blocks
Eli's review flagged `${{ matrix.arch }}` in a run: block as an injectable pattern even though the matrix values are hardcoded and not truly exploitable. Apply the pattern consistently across the whole workflow: - Hoist PLATFORM, ARCH, BAZEL_ARCH, REPO to job-level env so each step can reference them as shell variables ($ARCH etc.) rather than GitHub Actions expressions (${{ matrix.arch }}). Job-level env evaluates matrix context since the job is instantiated per matrix combination, so this DRYs up the per-step env blocks. - Rewrite every `run:` block to reference the job-level env vars. No more `${{ ... }}` expressions inside shell scripts. - Secret references (GITHUB_TOKEN) remain step-scoped per least-privilege. - Minor cleanup: collapse three separate `echo ... >> $GITHUB_ENV` lines into a single `{ ...; } >> "$GITHUB_ENV"` block. Addresses Eli's inline comment on line 114 of the pre-hoist file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 31f3d54 commit bfb9c59

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

.github/workflows/build-node-packages.yml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ jobs:
3030

3131
env:
3232
NODE_VERSION: v22.21.1
33+
PLATFORM: ${{ matrix.platform }}
34+
ARCH: ${{ matrix.arch }}
35+
BAZEL_ARCH: ${{ matrix.bazel_arch }}
36+
REPO: ${{ github.repository }}
3337

3438
steps:
3539
- name: Checkout repository
3640
uses: actions/checkout@v3
3741

3842
- name: Debug Matrix Values
3943
run: |
40-
echo "Matrix platform: ${{ matrix.platform }}"
41-
echo "Matrix arch: ${{ matrix.arch }}"
44+
echo "Matrix platform: $PLATFORM"
45+
echo "Matrix arch: $ARCH"
4246
4347
- name: Download Node archive
44-
run: |
45-
gh release download node-${{ env.NODE_VERSION }}-release \
46-
--repo asana/node \
47-
--pattern "node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz"
48-
mv node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz node.tar.xz
4948
env:
5049
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
run: |
51+
ASSET="node-${NODE_VERSION}-${PLATFORM}-${ARCH}-LATEST.tar.xz"
52+
gh release download "node-${NODE_VERSION}-release" \
53+
--repo asana/node \
54+
--pattern "$ASSET"
55+
mv "$ASSET" node.tar.xz
5156
5257
- name: Execute the Dockerfile
5358
run: |
@@ -70,7 +75,7 @@ jobs:
7075
mv node_modules/cld ./cld@2.9.1/node_modules/
7176
mv node_modules/unix-dgram ./unix-dgram@2.0.6/node_modules/
7277
mv "node_modules/@datadog/pprof" "./@datadog+pprof@5.8.0/node_modules/@datadog/"
73-
tar --hard-dereference -cvzf packages_${{matrix.arch}}.tar.gz bcrypt@5.1.0 cld@2.9.1 unix-dgram@2.0.6 "@datadog+pprof@5.8.0"
78+
tar --hard-dereference -cvzf "packages_${ARCH}.tar.gz" bcrypt@5.1.0 cld@2.9.1 unix-dgram@2.0.6 "@datadog+pprof@5.8.0"
7479
7580
- name: Upload archive to release
7681
# Use `gh release upload` (first-party GitHub CLI, pre-installed on runners)
@@ -80,10 +85,10 @@ jobs:
8085
env:
8186
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8287
run: |
83-
gh release upload "node-${{ env.NODE_VERSION }}-release" \
84-
"packages_${{ matrix.arch }}.tar.gz" \
88+
gh release upload "node-${NODE_VERSION}-release" \
89+
"packages_${ARCH}.tar.gz" \
8590
--clobber \
86-
--repo "${{ github.repository }}"
91+
--repo "$REPO"
8792
8893
# S3 upload is restricted to the protected main branch only. The IAM role
8994
# (push_node_gyp_packages) trusts only refs/heads/main via OIDC. To upload
@@ -106,15 +111,17 @@ jobs:
106111
# (disable_confusing_acls = true), which disables ACLs entirely.
107112
# BlockPublicAcls + IgnorePublicAcls provide additional coverage.
108113
# Reads come via CloudFront OAC.
109-
NODE_MAJOR=$(echo "${{ env.NODE_VERSION }}" | sed 's/^v//' | cut -d. -f1)
110-
SHA256=$(sha256sum "packages_${{ matrix.arch }}.tar.gz" | awk '{print $1}')
114+
NODE_MAJOR=$(echo "$NODE_VERSION" | sed 's/^v//' | cut -d. -f1)
115+
SHA256=$(sha256sum "packages_${ARCH}.tar.gz" | awk '{print $1}')
111116
SHORT_HASH=${SHA256:0:8}
112-
S3_KEY="node-gyp/packages_${{ matrix.bazel_arch }}_node${NODE_MAJOR}-${SHORT_HASH}.tar.gz"
113-
echo "Uploading packages_${{ matrix.arch }}.tar.gz to s3://asana-oss-cache/${S3_KEY}"
114-
aws s3 cp "packages_${{ matrix.arch }}.tar.gz" "s3://asana-oss-cache/${S3_KEY}"
115-
echo "S3_KEY=${S3_KEY}" >> "$GITHUB_ENV"
116-
echo "SHA256=${SHA256}" >> "$GITHUB_ENV"
117-
echo "NODE_MAJOR=${NODE_MAJOR}" >> "$GITHUB_ENV"
117+
S3_KEY="node-gyp/packages_${BAZEL_ARCH}_node${NODE_MAJOR}-${SHORT_HASH}.tar.gz"
118+
echo "Uploading packages_${ARCH}.tar.gz to s3://asana-oss-cache/$S3_KEY"
119+
aws s3 cp "packages_${ARCH}.tar.gz" "s3://asana-oss-cache/$S3_KEY"
120+
{
121+
echo "S3_KEY=$S3_KEY"
122+
echo "SHA256=$SHA256"
123+
echo "NODE_MAJOR=$NODE_MAJOR"
124+
} >> "$GITHUB_ENV"
118125
119126
- name: Verify upload is reachable via CloudFront
120127
if: github.ref == 'refs/heads/main'
@@ -135,6 +142,6 @@ jobs:
135142
run: |
136143
echo ""
137144
echo "=== Update tools_repositories.bzl in codez ==="
138-
echo " name = \"node_gyp_packages_${{ matrix.bazel_arch }}_node${NODE_MAJOR}\","
139-
echo " urls = [\"https://asana-oss-cache.s3.us-east-1.amazonaws.com/${S3_KEY}\"],"
140-
echo " sha256 = \"${SHA256}\","
145+
echo " name = \"node_gyp_packages_${BAZEL_ARCH}_node${NODE_MAJOR}\","
146+
echo " urls = [\"https://asana-oss-cache.s3.us-east-1.amazonaws.com/$S3_KEY\"],"
147+
echo " sha256 = \"$SHA256\","

0 commit comments

Comments
 (0)