Skip to content

Commit 7177889

Browse files
authored
chore: validate binary presence before npm publish in release (#12765)
* fix: remove redundant step * fix: validate that binaries has been uploaded before publishing to NPM
1 parent 76a1416 commit 7177889

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

.circleci/config.base.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -830,12 +830,6 @@ jobs:
830830
- amplify-cli-ssh-deps-{{ .Branch }}
831831
- restore_cache:
832832
key: amplify-pkg-binaries-{{ .Branch }}-{{ .Revision }}
833-
- run:
834-
name: Upload Pkg Binary
835-
command: |
836-
source .circleci/local_publish_helpers.sh
837-
uploadPkgCli
838-
./out/amplify-pkg-linux-x64 --version
839833
- run:
840834
name: Authenticate with npm
841835
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc

.circleci/publish-codebuild.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,30 @@ function lernaPublishExitOnFailure {
1717
# registy URL update changes .yarnrc.yml file
1818
git update-index --assume-unchanged .yarnrc.yml
1919
fi
20-
20+
2121
# run lerna publish with the args that were passed to this function
2222
# duplicate stdout to a temp file
2323
# grep the temp file for the lerna err token and return exit 1 if found (-v option inverts grep exit code)
2424
npx lerna publish "$@" | tee /tmp/publish-results && grep -qvz "lerna ERR!" < /tmp/publish-results
2525
}
2626

27+
# verifies that binaries are uploaded and available before publishing to NPM
28+
function verifyPkgIsAvailable {
29+
# exit on failure
30+
set -e
31+
32+
# read version of @aws-amplify/cli
33+
desiredPkgVersion=$(npx lerna list --scope @aws-amplify/cli --json | jq -r '.[0].version')
34+
35+
# check binaries
36+
# send HEAD requests to check for binary presence
37+
# curl --fail exits with non-zero code and makes this script fail
38+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-x64.tgz
39+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-arm64.tgz
40+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-macos-x64.tgz
41+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-win-x64.tgz
42+
}
43+
2744
if [ -z "$GITHUB_EMAIL" ]; then
2845
if [[ "$LOCAL_PUBLISH_TO_LATEST" == "true" ]]; then
2946
git config --global user.email [email protected]
@@ -72,6 +89,11 @@ elif [[ "$BRANCH_NAME" == "release" ]]; then
7289
# create release commit and release tags
7390
npx lerna version --exact --conventional-commits --conventional-graduate --yes --no-push --include-merged-tags --message "chore(release): Publish latest [ci skip]"
7491

92+
if [[ "$LOCAL_PUBLISH_TO_LATEST" != "true" ]]; then
93+
# verify that binary has been uploaded
94+
verifyPkgIsAvailable
95+
fi
96+
7597
# publish versions that were just computed
7698
lernaPublishExitOnFailure from-git --yes --no-push
7799

@@ -119,6 +141,9 @@ elif [[ "$BRANCH_NAME" =~ ^run-e2e-with-rc\/.* ]] || [[ "$BRANCH_NAME" =~ ^relea
119141
exit 0
120142
fi
121143

144+
# verify that binary has been uploaded
145+
verifyPkgIsAvailable
146+
122147
# publish versions that were just computed
123148
lernaPublishExitOnFailure from-git --yes --no-push --dist-tag rc
124149

.circleci/publish.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ function lernaPublishExitOnFailure {
1818
npx lerna publish "$@" | tee /tmp/publish-results && grep -qvz "lerna ERR!" < /tmp/publish-results
1919
}
2020

21+
# verifies that binaries are uploaded and available before publishing to NPM
22+
function verifyPkgIsAvailable {
23+
# exit on failure
24+
set -e
25+
26+
# read version of @aws-amplify/cli
27+
desiredPkgVersion=$(npx lerna list --scope @aws-amplify/cli --json | jq -r '.[0].version')
28+
29+
# check binaries
30+
# send HEAD requests to check for binary presence
31+
# curl --fail exits with non-zero code and makes this script fail
32+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-x64.tgz
33+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-arm64.tgz
34+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-macos-x64.tgz
35+
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-win-x64.tgz
36+
}
37+
2138
if [ -z "$GITHUB_EMAIL" ]; then
2239
if [[ "$LOCAL_PUBLISH_TO_LATEST" == "true" ]]; then
2340
git config --global user.email [email protected]
@@ -66,6 +83,11 @@ elif [[ "$CIRCLE_BRANCH" == "release" ]]; then
6683
# create release commit and release tags
6784
npx lerna version --exact --conventional-commits --conventional-graduate --yes --no-push --include-merged-tags --message "chore(release): Publish latest [ci skip]"
6885

86+
if [[ "$LOCAL_PUBLISH_TO_LATEST" != "true" ]]; then
87+
# verify that binary has been uploaded
88+
verifyPkgIsAvailable
89+
fi
90+
6991
# publish versions that were just computed
7092
lernaPublishExitOnFailure from-git --yes --no-push
7193

@@ -112,6 +134,9 @@ elif [[ "$CIRCLE_BRANCH" =~ ^run-e2e-with-rc\/.* ]] || [[ "$CIRCLE_BRANCH" =~ ^r
112134
exit 0
113135
fi
114136

137+
# verify that binary has been uploaded
138+
verifyPkgIsAvailable
139+
115140
# publish versions that were just computed
116141
lernaPublishExitOnFailure from-git --yes --no-push --dist-tag rc
117142

0 commit comments

Comments
 (0)