From a2b1451b4498f5b7dc4eeb87bd7e8e823516469c Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Mon, 27 May 2024 09:06:02 -0400 Subject: [PATCH] chore: cherry-pick #4576 (e2e update) into release-0.27 (release-0.27) (#4607) Signed-off-by: Rui Chen --- .circleci/config.yml | 30 ------------------------ .github/workflows/test.yml | 48 ++++++++++++++++++++++++++++++++++---- e2e/.gitconfig | 3 --- e2e/main.go | 8 +++---- scripts/e2e-deps.sh | 28 ---------------------- scripts/e2e.sh | 14 ++++------- 6 files changed, 52 insertions(+), 79 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100644 e2e/.gitconfig delete mode 100755 scripts/e2e-deps.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 8f552060aa..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -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.7.5 - 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\/.*)/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c36a8b8ce0..03f6bfa410 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,8 +26,8 @@ jobs: if: github.event.pull_request.draft == false runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 - - uses: dorny/paths-filter@v2 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3 id: changes with: filters: | @@ -41,12 +41,12 @@ jobs: if: needs.changes.outputs.should-run-tests == 'true' name: Tests runs-on: ubuntu-22.04 - container: ghcr.io/runatlantis/testing-env:latest + container: ghcr.io/runatlantis/testing-env:latest@sha256:346fd2028603d7c9369f709023ef993faf60a70ef4c91963f5baa7454196df32 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 # need to setup go toolchain explicitly - - uses: actions/setup-go@v5 + - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5 with: go-version-file: go.mod @@ -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.event.pull_request.head.repo.fork == false + 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 diff --git a/e2e/.gitconfig b/e2e/.gitconfig deleted file mode 100644 index 3424a0e076..0000000000 --- a/e2e/.gitconfig +++ /dev/null @@ -1,3 +0,0 @@ -[user] - name = atlantisbot - email = lkysow+atlantis@gmail.com \ No newline at end of file diff --git a/e2e/main.go b/e2e/main.go index f9038df53a..840815d7bc 100644 --- a/e2e/main.go +++ b/e2e/main.go @@ -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 == "" { diff --git a/scripts/e2e-deps.sh b/scripts/e2e-deps.sh deleted file mode 100755 index 4ac9b9272b..0000000000 --- a/scripts/e2e-deps.sh +++ /dev/null @@ -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 diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 115c964454..2f8b649497 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -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