Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into pr/acusti/11854
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Jun 12, 2023
2 parents 5b5ab24 + c415f65 commit efc2ea6
Show file tree
Hide file tree
Showing 388 changed files with 45,186 additions and 180,757 deletions.
181 changes: 88 additions & 93 deletions .circleci/config.base.yml

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ jobs:
- restore_cache:
key: >-
amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
- run: yarn run production-build
- run: yarn --immutable
- run: yarn production-build
- save_cache:
key: >-
amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
Expand Down Expand Up @@ -167,7 +168,7 @@ jobs:
source .circleci/local_publish_helpers.sh
amplify -v
cd packages/amplify-console-integration-tests
retry yarn run console-integration --no-cache --maxWorkers=4
retry yarn console-integration --no-cache --maxWorkers=4
name: Run Amplify Console integration tests
no_output_timeout: 90m
- run:
Expand Down
62 changes: 51 additions & 11 deletions .circleci/local_publish_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ [email protected]

function startLocalRegistry {
# Start local registry
tmp_registry_log=$(mktemp)
tmp_registry_log="$(mktemp)"
echo "Registry output file: $tmp_registry_log"
(cd && nohup npx ${VERDACCIO_PACKAGE:-$default_verdaccio_package} -c $1 &>$tmp_registry_log &)
# Wait for Verdaccio to boot
grep -q 'http address' <(tail -f $tmp_registry_log)
attempts=0
until grep -q 'http address' $tmp_registry_log
do
attempts=$((attempts+1))
echo "Waiting for Verdaccio, attempt $attempts"
sleep 1

if (( attempts > 60 )); then
echo "Verdaccio didn't start";
exit 1
fi
done
}

function uploadPkgCli {
Expand Down Expand Up @@ -56,7 +67,7 @@ function generatePkgCli {

# install package depedencies
cp ../yarn.lock ./
yarn --production
yarn workspaces focus --production

# Optimize package size
find . \
Expand Down Expand Up @@ -142,17 +153,17 @@ function verifyPkgCli {
function unsetNpmRegistryUrl {
# Restore the original NPM and Yarn registry URLs
npm set registry "https://registry.npmjs.org/"
yarn config set registry "https://registry.npmjs.org/"
yarn config set npmRegistryServer "https://registry.npmjs.org/"
}

function unsetSudoNpmRegistryUrl {
# Restore the original NPM and Yarn registry URLs
sudo npm set registry "https://registry.npmjs.org/"
sudo yarn config set registry "https://registry.npmjs.org/"
sudo yarn config set npmRegistryServer "https://registry.npmjs.org/"
}

function changeNpmGlobalPath {
mkdir -p ~/.npm-global
mkdir -p ~/.npm-global/{bin,lib}
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
}
Expand All @@ -166,13 +177,13 @@ function changeSudoNpmGlobalPath {
function setNpmRegistryUrlToLocal {
# Set registry to local registry
npm set registry "$custom_registry_url"
yarn config set registry "$custom_registry_url"
yarn config set npmRegistryServer "$custom_registry_url"
}

function setSudoNpmRegistryUrlToLocal {
# Set registry to local registry
sudo npm set registry "$custom_registry_url"
sudo yarn config set registry "$custom_registry_url"
sudo yarn config set npmRegistryServer "$custom_registry_url"
}

function useChildAccountCredentials {
Expand Down Expand Up @@ -266,16 +277,45 @@ function setAwsAccountCredentials {
useChildAccountCredentials
fi
}

function runE2eTest {
FAILED_TEST_REGEX_FILE="./amplify-e2e-reports/amplify-e2e-failed-test.txt"

if [ -f $FAILED_TEST_REGEX_FILE ]; then
# read the content of failed tests
failedTests=$(<$FAILED_TEST_REGEX_FILE)
yarn run e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE -t "$failedTests"
yarn e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE -t "$failedTests"
else
yarn run e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE
yarn e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE
fi
}

function runE2eTestCb {
_setupCoverage
FAILED_TEST_REGEX_FILE="./amplify-e2e-reports/amplify-e2e-failed-test.txt"

if [ -f $FAILED_TEST_REGEX_FILE ]; then
# read the content of failed tests
failedTests=$(<$FAILED_TEST_REGEX_FILE)
NODE_V8_COVERAGE=$E2E_TEST_COVERAGE_DIR yarn e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE -t "$failedTests"
else
NODE_V8_COVERAGE=$E2E_TEST_COVERAGE_DIR yarn e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE
fi
}

function _setupCoverage {
_teardownCoverage
echo "Setup Coverage ($E2E_TEST_COVERAGE_DIR)"
if [ ! -d $E2E_TEST_COVERAGE_DIR ]
then
mkdir -p $E2E_TEST_COVERAGE_DIR
fi
}

function _teardownCoverage {
if [ -d $E2E_TEST_COVERAGE_DIR ]
then
echo "Teardown Coverage ($E2E_TEST_COVERAGE_DIR)"
rm -r $E2E_TEST_COVERAGE_DIR
fi
}

Expand Down
58 changes: 48 additions & 10 deletions .circleci/publish.sh → .circleci/publish-codebuild.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
#!/bin/bash -e
export BRANCH_NAME="$(git symbolic-ref HEAD --short 2>/dev/null)"
if [ "$BRANCH_NAME" = "" ] ; then
BRANCH_NAME="$(git rev-parse HEAD | xargs git name-rev | cut -d' ' -f2 | sed 's/remotes\/origin\///g')";
fi
git checkout $BRANCH_NAME
echo "fetching tags"
git fetch --tags https://github.com/aws-amplify/amplify-cli

# 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
if [[ "$LOCAL_PUBLISH_TO_LATEST" == "true" ]]; then
# registy URL update changes .yarnrc.yml file
git update-index --assume-unchanged .yarnrc.yml
fi

# 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
}

# 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://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-x64.tgz
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-arm64.tgz
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-macos-x64.tgz
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-win-x64.tgz
}

if [ -z "$GITHUB_EMAIL" ]; then
if [[ "$LOCAL_PUBLISH_TO_LATEST" == "true" ]]; then
git config --global user.email [email protected]
Expand All @@ -34,13 +63,13 @@ else
git config --global user.name $GITHUB_USER
fi

if [[ "$CIRCLE_BRANCH" =~ ^tagged-release ]]; then
if [[ "$CIRCLE_BRANCH" =~ ^tagged-release-without-e2e-tests\/.* ]]; then
if [[ "$BRANCH_NAME" =~ ^tagged-release ]]; then
if [[ "$BRANCH_NAME" =~ ^tagged-release-without-e2e-tests\/.* ]]; then
# Remove tagged-release-without-e2e-tests/
export NPM_TAG="${CIRCLE_BRANCH/tagged-release-without-e2e-tests\//}"
elif [[ "$CIRCLE_BRANCH" =~ ^tagged-release\/.* ]]; then
export NPM_TAG="${BRANCH_NAME/tagged-release-without-e2e-tests\//}"
elif [[ "$BRANCH_NAME" =~ ^tagged-release\/.* ]]; then
# Remove tagged-release/
export NPM_TAG="${CIRCLE_BRANCH/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>"
Expand All @@ -56,10 +85,15 @@ if [[ "$CIRCLE_BRANCH" =~ ^tagged-release ]]; then
fi

# @latest release
elif [[ "$CIRCLE_BRANCH" == "release" ]]; then
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]"

if [[ "$LOCAL_PUBLISH_TO_LATEST" != "true" ]]; then
# verify that binary has been uploaded
verifyPkgIsAvailable
fi

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

Expand All @@ -70,7 +104,7 @@ elif [[ "$CIRCLE_BRANCH" == "release" ]]; then
fi

# push release commit
git push origin "$CIRCLE_BRANCH"
git push origin "$BRANCH_NAME"

# push release tags
git tag --points-at HEAD | xargs git push origin
Expand All @@ -88,7 +122,7 @@ elif [[ "$CIRCLE_BRANCH" == "release" ]]; then
git push origin hotfix

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

# force @aws-amplify/cli-internal to be versioned in case this pipeline run does not have any commits that modify the CLI packages
if [[ "$LOCAL_PUBLISH_TO_LATEST" == "true" ]]; then
Expand All @@ -97,6 +131,7 @@ elif [[ "$CIRCLE_BRANCH" =~ ^run-e2e-with-rc\/.* ]] || [[ "$CIRCLE_BRANCH" =~ ^r
# 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]" $(echo $force_publish_local_args) --no-commit-hooks


# if publishing locally to verdaccio
if [[ "$LOCAL_PUBLISH_TO_LATEST" == "true" ]]; then
# publish to verdaccio with no dist tag (default to latest)
Expand All @@ -106,14 +141,17 @@ elif [[ "$CIRCLE_BRANCH" =~ ^run-e2e-with-rc\/.* ]] || [[ "$CIRCLE_BRANCH" =~ ^r
exit 0
fi

# verify that binary has been uploaded
verifyPkgIsAvailable

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

# push release commit
git push origin "$CIRCLE_BRANCH"
git push origin "$BRANCH_NAME"

# push release tags
git tag --points-at HEAD | xargs git push origin
else
echo "branch name" "$CIRCLE_BRANCH" "did not match any branch publish rules. Skipping publish"
echo "branch name" "$BRANCH_NAME" "did not match any branch publish rules. Skipping publish"
fi
30 changes: 30 additions & 0 deletions .circleci/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 [[ "$CIRCLE_BRANCH" =~ ^tagged-release ]]; then
if [[ "$CIRCLE_BRANCH" =~ ^tagged-release-without-e2e-tests\/.* ]]; then
# Remove tagged-release-without-e2e-tests/
export NPM_TAG="${CIRCLE_BRANCH/tagged-release-without-e2e-tests\//}"
elif [[ "$CIRCLE_BRANCH" =~ ^tagged-release\/.* ]]; then
# Remove tagged-release/
export NPM_TAG="${CIRCLE_BRANCH/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 [[ "$CIRCLE_BRANCH" == "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]" --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/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/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
}

# 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://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-x64.tgz
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-linux-arm64.tgz
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-macos-x64.tgz
curl -I --fail https://package.cli.amplify.aws/$desiredPkgVersion/amplify-pkg-win-x64.tgz
}

if [[ "$CIRCLE_BRANCH" =~ ^tagged-release ]]; then
if [[ "$CIRCLE_BRANCH" =~ ^tagged-release-without-e2e-tests\/.* ]]; then
# Remove tagged-release-without-e2e-tests/
export NPM_TAG="${CIRCLE_BRANCH/tagged-release-without-e2e-tests\//}"
elif [[ "$CIRCLE_BRANCH" =~ ^tagged-release\/.* ]]; then
# Remove tagged-release/
export NPM_TAG="${CIRCLE_BRANCH/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 [[ "$CIRCLE_BRANCH" == "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 [[ "$CIRCLE_BRANCH" =~ ^run-e2e-with-rc\/.* ]] || [[ "$CIRCLE_BRANCH" =~ ^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" "$CIRCLE_BRANCH" "did not match any branch publish rules."
exit 1
fi
Loading

0 comments on commit efc2ea6

Please sign in to comment.