Skip to content

Commit

Permalink
test: remove extra hash (#13263)
Browse files Browse the repository at this point in the history
* Revert "Revert "test: remove extra hash (#13071)" (#13084)"

This reverts commit 5013f9a.

* 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 <[email protected]>

---------

Co-authored-by: Amplifiyer <[email protected]>
  • Loading branch information
sobolk and Amplifiyer authored Sep 26, 2023
1 parent ac44ef2 commit 8811bbe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 46 deletions.
8 changes: 6 additions & 2 deletions .circleci/cb-publish-step-1-set-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 25 additions & 27 deletions .circleci/local_publish_helpers_codebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
}

Expand Down
18 changes: 1 addition & 17 deletions packages/amplify-cli-npm/binary.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 8811bbe

Please sign in to comment.