Repository: runatlantis/atlantis (language: go)

Issue:
CircleCI e2e "branch" checks are cancelled intermittently after merging a PR
<!--- Please keep this note for the community --->

### Community Note

* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
* Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
* If you are interested in working on this issue or have submitted a pull request, please leave a comment.

<!--- Thank you for keeping this note for the community --->

---

<!--- When filing a bug, please include the following headings if possible. Any example text in this template can be deleted. --->

### Overview of the Issue

<!--- Please describe the issue you are having and how you encountered the problem. --->

> - website_link_check - Cancelled
> - test - Cancelled
> - e2e - Cancelled

See failure https://github.com/runatlantis/atlantis/runs/9402182715 after merging #2522. I reran the failed checks to get them to pass.

See other merges https://github.com/runatlantis/atlantis/commits/main?after=ee7a5cadfb276f2b49926f9f814bd66787f6b4b1+174&branch=main&qualified_name=refs%2Fheads%2Fmain from when #2522 was merged. No other merges from that day...

Also, see releases, there was a release [after](https://github.com/runatlantis/atlantis/releases/tag/v0.21.0-pre.20221114) and [before](https://github.com/runatlantis/atlantis/releases/tag/v0.20.2-pre.20221106).

It's possible that we will have more control over this once we move off of circleci and on to gha.

### Reproduction Steps

<!--- 

In order to effectively and quickly resolve the issue, please provide exact steps that allow us the reproduce the problem. If no steps are provided, then it will likely take longer to get the issue resolved.
  
--->
Merge in a new pr

### Logs

<!---

Provide log files from Atlantis server

<details>
  <summary>Logs</summary>

```
log output
```

</details>

--->
None

### Environment details

<!---

If not already included, please provide the following:
- Atlantis version:
- If not running the latest Atlantis version have you tried to reproduce this issue on the latest version: 
- Atlantis flags:

Atlantis server-side config file:
```
# config file
```

Repo `atlantis.yaml` file:
```
# config file
```

Any other information you can provide about the environment/deployment.
--->
None

### Additional Context

<!---
Additional context on the problem. Docs, links to blogs, or other material that lead you to discover this issue or were helpful in troubleshooting the issue. 
--->
It's possible it's due to concurrency checks in the branch circleci action

https://github.com/runatlantis/atlantis/blob/4cacaeb0c7633c98a9a5f873faaf391b259bf355/.circleci/config.yml#L53-L68



Discussion / hints:

Fix patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index e9af0aa3c7..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.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\/.*)/


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index b8f0fdc012..a6fcb598af 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -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
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 f04b823906..c5ae0e2582 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