Skip to content

Commit

Permalink
ci: Setup e2e scripts (#12629)
Browse files Browse the repository at this point in the history
* ci: remove dependance on webhooks

* ci: try again

* ci: migrate to manual cb triggers for e2e

* ci: set region if not defined

* ci: cleanup

* ci: refactor
  • Loading branch information
awsluja authored May 16, 2023
1 parent aeb26ae commit bb10103
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
33 changes: 20 additions & 13 deletions .circleci/publish-codebuild.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/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
Expand Down Expand Up @@ -34,13 +41,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,7 +63,7 @@ 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]"

Expand All @@ -70,7 +77,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,33 +95,33 @@ 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
force_publish_local_args="--force-publish '@aws-amplify/cli-internal'"
fi
# create release commit and release tags
git checkout "${CODEBUILD_WEBHOOK_TRIGGER#branch/*}" && npx lerna version --preid=rc.$CODEBUILD_RESOLVED_SOURCE_VERSION --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
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)
lernaPublishExitOnFailure from-package --git-head $CODEBUILD_RESOLVED_SOURCE_VERSION --yes --no-push
lernaPublishExitOnFailure from-git --yes --no-push
echo "Published packages to verdaccio"
echo "Exiting without pushing release commit or release tags"
exit 0
fi

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

# push release commit
git push origin "${CODEBUILD_WEBHOOK_TRIGGER#branch/*}"
git push origin "$BRANCH_NAME"

# push release tags
git tag --points-at HEAD | xargs git push origin
else
echo "branch name" "${CODEBUILD_WEBHOOK_TRIGGER#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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"check-version-conflicts:beta": "yarn ts-node ./scripts/check-version.ts beta",
"check-version-conflicts:release": "yarn ts-node ./scripts/check-version.ts",
"clean": "nx reset && nx run-many --target=clean --all && yarn rimraf tsconfig.tsbuildinfo",
"cloud-e2e-with-rc": "CURR_BRANCH=$(git branch | awk '/\\*/{printf \"%s\", $2}') && UPSTREAM_BRANCH=run-e2e-with-rc/$USER/$CURR_BRANCH && git push $(git remote -v | grep aws-amplify/amplify-cli | head -n1 | awk '{print $1;}') $CURR_BRANCH:$UPSTREAM_BRANCH --no-verify --force-with-lease && echo \"\n\n 🏃 E2E test are running at:\nhttps://app.circleci.com/pipelines/github/aws-amplify/amplify-cli?branch=$UPSTREAM_BRANCH\"",
"cloud-e2e": "CURR_BRANCH=$(git branch | awk '/\\*/{printf \"%s\", $2}') && UPSTREAM_BRANCH=run-e2e/$USER/$CURR_BRANCH && git push $(git remote -v | grep aws-amplify/amplify-cli | head -n1 | awk '{print $1;}') $CURR_BRANCH:$UPSTREAM_BRANCH --no-verify --force-with-lease && echo \"\n\n 🏃 E2E test are running at:\nhttps://app.circleci.com/pipelines/github/aws-amplify/amplify-cli?branch=$UPSTREAM_BRANCH\"",
"cloud-e2e": "source ./scripts/cloud-e2e.sh && cloudE2E",
"cloud-e2e-beta": "source ./scripts/cloud-e2e.sh && cloudE2EBeta",
"commit": "git-cz",
"coverage:collect": "ts-node ./scripts/collect-test-coverage.ts",
"coverage": "codecov || exit 0",
Expand Down
39 changes: 39 additions & 0 deletions scripts/cloud-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# set exit on error to true
set -e
# load .env
set -o allexport
source ./scripts/.env set
export CURR_BRANCH=$(git branch --show-current)
function authenticate {
echo Authenticating terminal...
mwinit
echo Loading E2E account credentials...
ada cred update --profile="${CLOUD_E2E_PROFILE}" --account="${CLOUD_E2E_ACCOUNT}" --role=CodeBuildE2E --provider=isengard --once
aws configure set region us-east-1 --profile $CLOUD_E2E_PROFILE
}
function triggerBuild {
echo Submitting CodeBuild Request to AWS Account: $CLOUD_E2E_ACCOUNT
echo Current branch is: $CURR_BRANCH
echo E2E Target branch is: $TARGET_BRANCH
RESULT=$(aws codebuild start-build-batch --profile="${CLOUD_E2E_PROFILE}" --project-name AmplifyCLI-E2E-Testing --source-version=$TARGET_BRANCH --query 'buildBatch.id' --output text)
echo "https://us-east-1.console.aws.amazon.com/codesuite/codebuild/$CLOUD_E2E_ACCOUNT/projects/AmplifyCLI-E2E-Testing/batch/$RESULT?region=us-east-1"
}
function cloudE2EBeta {
echo Running Beta E2E Test Suite
export CLOUD_E2E_PROFILE=AmplifyCLIE2EBeta
export CLOUD_E2E_ACCOUNT=$E2E_ACCOUNT_BETA
export TARGET_BRANCH=$CURR_BRANCH
authenticate
triggerBuild
}
function cloudE2E {
echo Running Prod E2E Test Suite
export CLOUD_E2E_PROFILE=AmplifyCLIE2E
export CLOUD_E2E_ACCOUNT=$E2E_ACCOUNT_PROD
export TARGET_BRANCH=run-e2e/$USER/$CURR_BRANCH
git push $(git remote -v | grep aws-amplify/amplify-cli | head -n1 | awk '{print $1;}') $CURR_BRANCH:$TARGET_BRANCH --no-verify --force-with-lease
authenticate
triggerBuild
}
4 changes: 4 additions & 0 deletions scripts/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
E2E_ACCOUNT_BETA=
E2E_ACCOUNT_PROD=
RELEASE_ACCOUNT_BETA=
RELEASE_ACCOUNT_PROD=

0 comments on commit bb10103

Please sign in to comment.