Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: rc, release, tagged rc, hotfix workflows #12918

Merged
merged 22 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .circleci/cb-publish-step-1-set-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -e

git config --global user.name aws-amplify-bot
git config --global user.email [email protected]

if [[ "$BRANCH_NAME" =~ ^tagged-release ]]; then
if [[ "$BRANCH_NAME" =~ ^tagged-release-without-e2e-tests\/.* ]]; then
# Remove tagged-release-without-e2e-tests/
export NPM_TAG="${BRANCH_NAME/tagged-release-without-e2e-tests\//}"
elif [[ "$BRANCH_NAME" =~ ^tagged-release\/.* ]]; then
# Remove tagged-release/
export NPM_TAG="${BRANCH_NAME/tagged-release\//}"
fi
if [ -z "$NPM_TAG" ]; then
echo "Tag name is missing. Name your branch with either tagged-release/<tag-name> or tagged-release-without-e2e-tests/<tag-name>"
exit 1
fi

npx lerna version --exact --preid=$NPM_TAG --conventional-commits --conventional-prerelease --yes --no-push --include-merged-tags --message "chore(release): Publish tagged release $NPM_TAG [ci skip]" --no-commit-hooks --force-publish '@aws-amplify/cli-internal'

# @latest release
elif [[ "$BRANCH_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 [ci skip]" --no-commit-hooks --force-publish '@aws-amplify/cli-internal'

# release candidate or local publish for testing / building binary
else
# create release commit and release tags
npx lerna version --preid=rc.$(git rev-parse --short HEAD) --exact --conventional-prerelease --conventional-commits --yes --no-push --include-merged-tags --message "chore(release): Publish rc [ci skip]" --no-commit-hooks --force-publish '@aws-amplify/cli-internal'
fi
25 changes: 25 additions & 0 deletions .circleci/cb-publish-step-2-verdaccio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -e

# lerna has a bug (https://github.com/lerna/lerna/issues/1066) where failed publishes do not set the exit code properly
# this causes the script to keep running even after failed publishes
# this function forces failed publishes to exit on failure
function lernaPublishExitOnFailure {
# exit on failure
set -e
# run lerna publish with the args that were passed to this function
# duplicate stdout to a temp file
# grep the temp file for the lerna err token and return exit 1 if found (-v option inverts grep exit code)
npx lerna publish "$@" | tee /tmp/publish-results && grep -qvz "lerna ERR!" < /tmp/publish-results
}

npmRegistryUrl=$(npm get registry)
if [[ "$npmRegistryUrl" =~ ^http://localhost ]]; then
# registy URL update changes .yarnrc.yml file
git update-index --assume-unchanged .yarnrc.yml

echo "Publishing to local registry under latest tag"
lernaPublishExitOnFailure from-git --yes --no-push
else
echo "NPM registry url is not pointing to localhost, $npmRegistryUrl"
exit 1
fi
70 changes: 70 additions & 0 deletions .circleci/cb-publish-step-3-npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash -e

# lerna has a bug (https://github.com/lerna/lerna/issues/1066) where failed publishes do not set the exit code properly
# this causes the script to keep running even after failed publishes
# this function forces failed publishes to exit on failure
function lernaPublishExitOnFailure {
# exit on failure
set -e
# run lerna publish with the args that were passed to this function
# duplicate stdout to a temp file
# grep the temp file for the lerna err token and return exit 1 if found (-v option inverts grep exit code)
npx lerna publish "$@" | tee /tmp/publish-results && grep -qvz "lerna ERR!" < /tmp/publish-results
}
jhockett marked this conversation as resolved.
Show resolved Hide resolved

# verifies that binaries are uploaded and available before publishing to NPM
function verifyPkgIsAvailable {
# exit on failure
set -e

# read version of @aws-amplify/cli
desiredPkgVersion=$(npx lerna list --scope @aws-amplify/cli --json | jq -r '.[0].version')

# check binaries
# send HEAD requests to check for binary presence
# curl --fail exits with non-zero code and makes this script fail
curl -I --fail https://$PKG_CLI_CLOUDFRONT_URL/$desiredPkgVersion/amplify-pkg-linux-x64.tgz
curl -I --fail https://$PKG_CLI_CLOUDFRONT_URL/$desiredPkgVersion/amplify-pkg-linux-arm64.tgz
curl -I --fail https://$PKG_CLI_CLOUDFRONT_URL/$desiredPkgVersion/amplify-pkg-macos-x64.tgz
curl -I --fail https://$PKG_CLI_CLOUDFRONT_URL/$desiredPkgVersion/amplify-pkg-win-x64.tgz
}

if [[ "$BRANCH_NAME" =~ ^tagged-release ]]; then
if [[ "$BRANCH_NAME" =~ ^tagged-release-without-e2e-tests\/.* ]]; then
# Remove tagged-release-without-e2e-tests/
export NPM_TAG="${BRANCH_NAME/tagged-release-without-e2e-tests\//}"
elif [[ "$BRANCH_NAME" =~ ^tagged-release\/.* ]]; then
# Remove tagged-release/
export NPM_TAG="${BRANCH_NAME/tagged-release\//}"
fi
if [ -z "$NPM_TAG" ]; then
echo "Tag name is missing. Name your branch with either tagged-release/<tag-name> or tagged-release-without-e2e-tests/<tag-name>"
exit 1
fi

# verify that binary has been uploaded
verifyPkgIsAvailable

echo "Publishing to NPM under $NPM_TAG tag"
lernaPublishExitOnFailure from-git --yes --no-push --dist-tag=$NPM_TAG

# @latest release
elif [[ "$BRANCH_NAME" == "release" ]]; then
# verify that binary has been uploaded
verifyPkgIsAvailable

# publish versions that were just computed
lernaPublishExitOnFailure from-git --yes --no-push

# release candidate or local publish for testing / building binary
elif [[ "$BRANCH_NAME" =~ ^run-e2e-with-rc\/.* ]] || [[ "$BRANCH_NAME" =~ ^release_rc\/.* ]]; then

# verify that binary has been uploaded
verifyPkgIsAvailable

# publish versions that were just computed
lernaPublishExitOnFailure from-git --yes --no-push --dist-tag rc
else
echo "branch name" "$BRANCH_NAME" "did not match any branch publish rules."
exit 1
fi
35 changes: 35 additions & 0 deletions .circleci/cb-publish-step-4-push-to-git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash -e

git config --global user.name aws-amplify-bot
git config --global user.email [email protected]

if [[ "$BRANCH_NAME" =~ ^tagged-release ]] || [[ "$BRANCH_NAME" =~ ^run-e2e-with-rc\/.* ]] || [[ "$BRANCH_NAME" =~ ^release_rc\/.* ]]; then
# push release commit
git push origin "$BRANCH_NAME"

# push release tags
git tag --points-at HEAD | xargs git push origin

# @latest release
elif [[ "$BRANCH_NAME" == "release" ]]; then
# push release commit
git push origin "$BRANCH_NAME"

# push release tags
git tag --points-at HEAD | xargs git push origin

# fast forward main to release
git fetch origin main
git checkout main
git merge release --ff-only
git push origin main

# fast forward hotfix to release
git fetch origin hotfix
git checkout hotfix
git merge release --ff-only
git push origin hotfix
else
echo "branch name" "$BRANCH_NAME" "did not match any branch publish rules."
exit 1
fi
Loading