Skip to content

Commit 2be22d8

Browse files
Merge pull request #10152 from BitGo/WCI-2204
fix(root): pin express Docker build to release SHA (WCI-2204)
2 parents e39b1b4 + 2cea0c6 commit 2be22d8

1 file changed

Lines changed: 48 additions & 25 deletions

File tree

‎.github/workflows/npmjs-release.yml‎

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ jobs:
216216
runs-on: ${{ vars.BASE_RUNNER_TYPE || 'ubuntu-latest' }}
217217
timeout-minutes: 60
218218
environment: npmjs-release
219+
outputs:
220+
# The commit this job published from. The express jobs verify the
221+
# express git tag still resolves to it before building the image.
222+
publish-sha: ${{ steps.capture-publish-sha.outputs.sha }}
219223
steps:
220224
- name: Checkout repository
221225
uses: actions/checkout@v6
@@ -301,6 +305,14 @@ jobs:
301305
run: |
302306
yarn lerna version --sign-git-tag --sign-git-commit --include-merged-tags --conventional-commits --conventional-graduate --yes
303307
308+
# Recorded for the express tag verification in get-express-release-context.
309+
- name: Capture publish SHA
310+
id: capture-publish-sha
311+
run: |
312+
PUBLISH_SHA=$(git rev-parse HEAD)
313+
echo "Publish SHA: $PUBLISH_SHA"
314+
echo "sha=$PUBLISH_SHA" >> "$GITHUB_OUTPUT"
315+
304316
- name: Publish siblings (pass 1)
305317
if: inputs.dry-run == false
306318
run: yarn lerna publish from-package --yes
@@ -453,13 +465,14 @@ jobs:
453465
outputs:
454466
version: ${{ steps.compute-express-git-tag.outputs.version }}
455467
git-tag: ${{ steps.compute-express-git-tag.outputs.git-tag }}
456-
git-sha: ${{ steps.compute-express-git-sha.outputs.git-sha }}
468+
git-sha: ${{ steps.verify-express-git-tag.outputs.git-sha }}
457469
docker-exists: ${{ steps.check-docker-image.outputs.docker-exists }}
458470
steps:
459-
- name: Checkout rel/latest branch
471+
# Check out the exact commit the release was published from.
472+
- name: Checkout release commit
460473
uses: actions/checkout@v6
461474
with:
462-
ref: rel/latest
475+
ref: ${{ needs.release-bitgojs.outputs.publish-sha }}
463476
fetch-depth: 0
464477
fetch-tags: true
465478

@@ -473,34 +486,43 @@ jobs:
473486
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
474487
echo "git-tag=$TAG" >> "$GITHUB_OUTPUT"
475488
476-
- name: Checkout express target git tag
477-
uses: actions/checkout@v6
478-
with:
479-
ref: ${{ steps.compute-express-git-tag.outputs.git-tag }}
480-
fetch-depth: 2
481-
482-
- name: Parse express git SHA
483-
id: compute-express-git-sha
489+
# The express git tag must resolve to the express version bump commit
490+
# (its parent carries a different version) within the published release
491+
# history. The Docker build uses this verified tag commit.
492+
- name: Verify Express Git Tag
493+
id: verify-express-git-tag
484494
run: |
485-
GIT_SHA=$(git rev-parse HEAD)
486-
echo "Git SHA: $GIT_SHA"
487-
echo "git-sha=$GIT_SHA" >> "$GITHUB_OUTPUT"
495+
PUBLISH_SHA="${{ needs.release-bitgojs.outputs.publish-sha }}"
496+
TAG="${{ steps.compute-express-git-tag.outputs.git-tag }}"
497+
VERSION="${{ steps.compute-express-git-tag.outputs.version }}"
498+
# ^{} peels the annotated, GPG-signed tag object down to its commit.
499+
TAG_SHA=$(git rev-parse "${TAG}^{}")
500+
VERSION_AT_TAG=$(git show "${TAG_SHA}:modules/express/package.json" | jq -r '.version')
488501
489-
- name: Sanity Check Express Git Tag
490-
run: |
491-
CURRENT_VERSION="${{ steps.compute-express-git-tag.outputs.version }}"
492-
PREVIOUS_VERSION=$(git show HEAD~1:./modules/express/package.json | jq -r '.version')
502+
echo "Publish SHA: $PUBLISH_SHA"
503+
echo "Tag $TAG resolves to: $TAG_SHA (express version $VERSION_AT_TAG)"
493504
494-
echo "Current version: $CURRENT_VERSION"
495-
echo "Previous version: $PREVIOUS_VERSION"
505+
if [ "$VERSION_AT_TAG" != "$VERSION" ]; then
506+
echo "::error::Express git tag $TAG points at $TAG_SHA whose modules/express/package.json version is $VERSION_AT_TAG, not the released $VERSION."
507+
echo "::error::The tag may have been moved after the release. Refusing to build the Express Docker image."
508+
exit 1
509+
fi
510+
511+
VERSION_AT_PARENT=$(git show "${TAG_SHA}^:modules/express/package.json" | jq -r '.version')
512+
if [ "$VERSION_AT_PARENT" = "$VERSION_AT_TAG" ]; then
513+
echo "::error::Express git tag $TAG points at $TAG_SHA which is not the commit that bumped the express version to $VERSION."
514+
echo "::error::The tag may have been moved after the release. Refusing to build the Express Docker image."
515+
exit 1
516+
fi
496517
497-
if [ "$CURRENT_VERSION" == "$PREVIOUS_VERSION" ]; then
498-
echo "::error::Express version bump does not line up with git tag location."
499-
echo "::error::This suggests the git tag may have been moved."
518+
if ! git merge-base --is-ancestor "$TAG_SHA" "$PUBLISH_SHA"; then
519+
echo "::error::Express git tag $TAG points at $TAG_SHA which is not part of the published release history (publish SHA $PUBLISH_SHA)."
520+
echo "::error::The tag may have been moved after the release. Refusing to build the Express Docker image."
500521
exit 1
501522
fi
502523
503-
echo "✅ Express version bump lines up with git tag"
524+
echo "✅ Express git tag verified; building from the tagged commit"
525+
echo "git-sha=$TAG_SHA" >> "$GITHUB_OUTPUT"
504526
505527
- name: Check if Docker image already exists in Docker Hub
506528
id: check-docker-image
@@ -527,7 +549,8 @@ jobs:
527549
echo ""
528550
echo "Express Version: ${{ steps.compute-express-git-tag.outputs.version }}"
529551
echo "Git Tag: ${{ steps.compute-express-git-tag.outputs.git-tag }}"
530-
echo "Commit SHA: ${{ steps.compute-express-git-sha.outputs.git-sha }}"
552+
echo "Commit SHA (verified): ${{ steps.verify-express-git-tag.outputs.git-sha }}"
553+
echo "Publish SHA (verified): ${{ needs.release-bitgojs.outputs.publish-sha }}"
531554
echo ""
532555
echo "### Docker Images to be deployed:"
533556
echo "- \`bitgo/express:latest\`"

0 commit comments

Comments
 (0)