feat(e2e): migrate off circleci (#4576)

Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-authored-by: Christian Winther <jippignu@gmail.com>
This commit is contained in:
Rui Chen
2024-05-20 12:02:10 -04:00
committed by GitHub
parent 633ca09fce
commit 7e79f56173
6 changed files with 47 additions and 74 deletions

View File

@@ -1,30 +0,0 @@
version: 2
jobs:
e2e:
docker:
- image: cimg/go:1.22 # If you update this, update it in the Makefile too
environment:
# This version of TF will be downloaded before Atlantis is started.
# We do this instead of setting --default-tf-version because setting
# that flag starts the download asynchronously so we'd have a race
# condition.
# renovate: datasource=github-releases depName=hashicorp/terraform versioning=hashicorp
TERRAFORM_VERSION: 1.8.3
steps:
- checkout
- run: make build-service
# We don't run e2e tests on fork PRs because they don't have access to the secret env vars.
- run: if [ -z "${CIRCLE_PR_REPONAME}" ]; then ./scripts/e2e.sh; fi
workflows:
version: 2
branch:
jobs:
- e2e:
context:
- atlantis-e2e-tests
filters:
branches:
# Ignore fork PRs since they don't have access to
# the atlantis-e2e-tests context (and also doc PRs).
ignore: /(pull\/\d+)|(docs\/.*)/

View File

@@ -100,3 +100,41 @@ jobs:
runs-on: ubuntu-22.04
steps:
- run: 'echo "No build required"'
e2e-github:
runs-on: ubuntu-latest
# dont run e2e tests on forked PRs
if: github.repository == 'runatlantis/atlantis'
env:
TERRAFORM_VERSION: 1.8.3
ATLANTISBOT_GITHUB_USERNAME: ${{ secrets.ATLANTISBOT_GITHUB_USERNAME }}
ATLANTISBOT_GITHUB_TOKEN: ${{ secrets.ATLANTISBOT_GITHUB_TOKEN }}
NGROK_AUTH_TOKEN: ${{ secrets.ATLANTISBOT_NGROK_AUTH_TOKEN }}
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5
with:
go-version-file: go.mod
# This version of TF will be downloaded before Atlantis is started.
# We do this instead of setting --default-tf-version because setting
# that flag starts the download asynchronously so we'd have a race
# condition.
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Setup ngrok
run: |
wget -q -nc https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
tar -xzf ngrok-v3-stable-linux-amd64.tgz && \
chmod +x ngrok
./ngrok --help
- name: Setup gitconfig
run: |
git config --global user.email "maintainers@runatlantis.io"
git config --global user.name "atlantisbot"
- run: |
make build-service
./scripts/e2e.sh

View File

@@ -1,3 +0,0 @@
[user]
name = atlantisbot
email = lkysow+atlantis@gmail.com

View File

@@ -38,13 +38,13 @@ type Project struct {
func main() {
githubUsername := os.Getenv("GITHUB_USERNAME")
githubUsername := os.Getenv("ATLANTISBOT_GITHUB_USERNAME")
if githubUsername == "" {
log.Fatalf("GITHUB_USERNAME cannot be empty")
log.Fatalf("ATLANTISBOT_GITHUB_USERNAME cannot be empty")
}
githubToken := os.Getenv("GITHUB_PASSWORD")
githubToken := os.Getenv("ATLANTISBOT_GITHUB_TOKEN")
if githubToken == "" {
log.Fatalf("GITHUB_PASSWORD cannot be empty")
log.Fatalf("ATLANTISBOT_GITHUB_TOKEN cannot be empty")
}
atlantisURL := os.Getenv("ATLANTIS_URL")
if atlantisURL == "" {

View File

@@ -1,28 +0,0 @@
#!/usr/bin/env bash
# Exit immediately if a command returns a non-zero code
set -e
echo "Preparing to run e2e tests"
if [ ! -f atlantis ]; then
echo "atlantis binary not found. exiting...."
exit 1
fi
cp atlantis ${CIRCLE_WORKING_DIRECTORY}/e2e/
# cd into e2e folder
cd e2e/
# Download terraform
curl -LOk https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
chmod +x terraform
cp terraform /home/circleci/go/bin
# Download ngrok to create a tunnel to expose atlantis server
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v2-stable-linux-amd64.zip -O ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
chmod +x ngrok
# Download jq
wget -O jq https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64
chmod +x jq
# Copy github config file - replace with circleci user later
cp .gitconfig ~/.gitconfig

View File

@@ -3,15 +3,10 @@
set -euo pipefail
IFS=$'\n\t'
# download all the tooling needed for e2e tests
CIRCLE_WORKING_DIRECTORY="${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}" # https://discuss.circleci.com/t/circle-working-directory-doesnt-expand/17007/5
${CIRCLE_WORKING_DIRECTORY}/scripts/e2e-deps.sh
cd "${CIRCLE_WORKING_DIRECTORY}/e2e"
# start atlantis server in the background and wait for it to start
./atlantis server \
--gh-user="$GITHUB_USERNAME" \
--gh-token="$GITHUB_PASSWORD" \
--gh-user="$ATLANTISBOT_GITHUB_USERNAME" \
--gh-token="$ATLANTISBOT_GITHUB_TOKEN" \
--data-dir="/tmp" \
--log-level="debug" \
--repo-allowlist="github.com/runatlantis/atlantis-tests" \
@@ -20,14 +15,15 @@ cd "${CIRCLE_WORKING_DIRECTORY}/e2e"
sleep 2
# start ngrok in the background and wait for it to start
./ngrok config add-authtoken $NGROK_AUTH_TOKEN
./ngrok http 4141 > /tmp/ngrok.log &
./ngrok config add-authtoken $NGROK_AUTH_TOKEN > /dev/null 2>&1
./ngrok http 4141 > /tmp/ngrok.log 2>&1 &
sleep 2
# find out what URL ngrok has given us
export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[] | select(.proto=="https") | .public_url')
# Now we can start the e2e tests
cd "${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}/e2e"
echo "Running 'make build'"
make build