From 8811bbe51e0ef3709ccdca2e07d8342b36e9c92f Mon Sep 17 00:00:00 2001 From: Kamil Sobol Date: Tue, 26 Sep 2023 10:25:52 -0700 Subject: [PATCH] test: remove extra hash (#13263) * Revert "Revert "test: remove extra hash (#13071)" (#13084)" This reverts commit 5013f9ac745215816c63f41d14104365e99c81cf. * test: make upload idempotent * test: make upload idempotent * test: make upload idempotent * test: use ful hash for testing stuff * Update .circleci/local_publish_helpers_codebuild.sh Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> --------- Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> --- .circleci/cb-publish-step-1-set-versions.sh | 8 ++- .circleci/local_publish_helpers_codebuild.sh | 52 ++++++++++---------- packages/amplify-cli-npm/binary.ts | 18 +------ 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/.circleci/cb-publish-step-1-set-versions.sh b/.circleci/cb-publish-step-1-set-versions.sh index 82bb5b0a417..7f1dfeeacca 100755 --- a/.circleci/cb-publish-step-1-set-versions.sh +++ b/.circleci/cb-publish-step-1-set-versions.sh @@ -27,8 +27,12 @@ elif [[ "$PROJECT_NAME" == "Release" ]]; then # create release commit and release tags npx lerna version --exact --conventional-commits --conventional-graduate --yes --no-push --include-merged-tags --message "chore(release): Publish latest" --no-commit-hooks --force-publish '@aws-amplify/cli-internal' -# release candidate or local publish for testing / building binary -else +# release candidate +elif [[ "$PROJECT_NAME" == "RC" ]]; then # create release commit and release tags npx lerna version --preid=rc.$(git rev-parse --short=15 HEAD) --exact --conventional-prerelease --conventional-commits --yes --no-push --include-merged-tags --message "chore(release): Publish rc" --no-commit-hooks --force-publish '@aws-amplify/cli-internal' +# local publish for testing / building binary, dev branch build, e2e tests +else + # create release commit and release tags + npx lerna version --preid=dev.$(git rev-parse HEAD) --exact --conventional-prerelease --conventional-commits --yes --no-push --include-merged-tags --message "chore(release): Publish dev" --no-commit-hooks --force-publish '@aws-amplify/cli-internal' fi diff --git a/.circleci/local_publish_helpers_codebuild.sh b/.circleci/local_publish_helpers_codebuild.sh index fcbc290df2e..7a3718c622e 100644 --- a/.circleci/local_publish_helpers_codebuild.sh +++ b/.circleci/local_publish_helpers_codebuild.sh @@ -24,38 +24,36 @@ function startLocalRegistry { } function uploadPkgCliCodeBuild { + # fail and exit if any command fails + set -e + cd out/ - export hash=$(git rev-parse HEAD | cut -c 1-12) export version=$(./amplify-pkg-linux-x64 --version) - if [[ "$PROJECT_NAME" == "Release" ]] || [[ "$PROJECT_NAME" == "RC" ]] || [[ "$PROJECT_NAME" == "TaggedReleaseWithoutE2E" ]]; then - aws s3 cp amplify-pkg-win-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-win-x64-$(echo $hash).tgz - aws s3 cp amplify-pkg-macos-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-macos-x64-$(echo $hash).tgz - aws s3 cp amplify-pkg-linux-arm64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-arm64-$(echo $hash).tgz - aws s3 cp amplify-pkg-linux-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-x64-$(echo $hash).tgz - - ALREADY_EXISTING_FILES="$(set -o pipefail && aws s3 ls s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-x64 | ( egrep -v "amplify-pkg-linux-x64-.*" || true ) | wc -l | xargs)" - INCORRECT_PERMISSIONS=$? - - if [ INCORRECT_PERMISSIONS -ne "0" ]; then - echo "Insufficient permissions to list s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-x64" - exit 1 - fi - - if [ ALREADY_EXISTING_FILES -ne "0" ]; then - echo "Cannot overwrite existing file at s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-x64.tgz" - exit 1 - fi - - aws s3 cp amplify-pkg-win-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-win-x64.tgz - aws s3 cp amplify-pkg-macos-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-macos-x64.tgz - aws s3 cp amplify-pkg-linux-arm64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-arm64.tgz - aws s3 cp amplify-pkg-linux-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-x64.tgz - - else - aws s3 cp amplify-pkg-linux-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-x64-$(echo $hash).tgz + # validate that version is uploaded in right build + if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + if [[ "$PROJECT_NAME" != "Release" ]]; then + echo "Invalid project name $PROJECT_NAME for $version release." + exit 1 + fi + elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\. ]]; then + if [[ "$PROJECT_NAME" != "RC" ]]; then + echo "Invalid project name $PROJECT_NAME for $version RC release." + exit 1 + fi + elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-$ ]]; then + echo "Version $version is missing a tag"; + exit 1 fi + # It's ok to re-upload binaries for the same build to make this step idempotent + # Versioning is handled by cb-publish-step-1-set-versions script + # Version conflicts are caught at cb-publish-step-2-verdaccio script + aws s3 cp amplify-pkg-win-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-win-x64.tgz + aws s3 cp amplify-pkg-macos-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-macos-x64.tgz + aws s3 cp amplify-pkg-linux-arm64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-arm64.tgz + aws s3 cp amplify-pkg-linux-x64.tgz s3://$PKG_CLI_BUCKET_NAME/$(echo $version)/amplify-pkg-linux-x64.tgz + cd .. } diff --git a/packages/amplify-cli-npm/binary.ts b/packages/amplify-cli-npm/binary.ts index 0fe93f1adde..282f2f6f65c 100644 --- a/packages/amplify-cli-npm/binary.ts +++ b/packages/amplify-cli-npm/binary.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import { spawnSync, execSync } from 'child_process'; +import { spawnSync } from 'child_process'; import util from 'util'; import tar from 'tar-stream'; import { createGunzip } from 'zlib'; @@ -75,27 +75,11 @@ const getCompressedBinaryUrl = (): string => { if (process.env.IS_AMPLIFY_CI && process.env.CODEBUILD_SRC_DIR) { // use cloudfront distribution for e2e url = `https://${process.env.PKG_CLI_CLOUDFRONT_URL}/${version}/${compressedBinaryName}`; - url = url.replace('.tgz', `-${getCommitHash()}.tgz`); - } else if (process.env.IS_AMPLIFY_CI) { - url = url.replace('.tgz', `-${getCommitHash()}.tgz`); } return url; }; -/** - * CI-only, used for testing hash-based binaries - * - * @returns string - */ -const getCommitHash = (): string => { - if (process.env.hash) { - return process.env.hash; - } - const hash = execSync('(git rev-parse HEAD | cut -c 1-12) || false').toString(); - return hash.substr(0, 12); -}; - /** * Wraps logic to download and run binary */