| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 1 | name: go_tests |
| 2 | on: |
| 3 | workflow_call: |
| Josh Bleecher Snyder | 936ba62 | 2025-04-30 20:53:21 +0000 | [diff] [blame] | 4 | inputs: |
| 5 | ref: |
| 6 | description: "The git ref to checkout" |
| 7 | required: false |
| 8 | type: string |
| 9 | default: "" |
| Philip Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 10 | working-directory: |
| 11 | description: "Working directory for the workflow" |
| 12 | required: false |
| 13 | type: string |
| 14 | default: "." |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 15 | push: |
| 16 | branches-ignore: |
| Josh Bleecher Snyder | 93bb66a | 2025-04-30 16:29:05 -0700 | [diff] [blame] | 17 | - "queue-main-*" |
| 18 | - "queue-dev-*" |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 19 | pull_request: |
| 20 | jobs: |
| 21 | test: |
| Philip Zeyliger | 8a290e5 | 2025-06-15 20:59:58 -0700 | [diff] [blame] | 22 | runs-on: "linux-x64-ubuntu-latest-64-core" |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 23 | steps: |
| Josh Bleecher Snyder | 936ba62 | 2025-04-30 20:53:21 +0000 | [diff] [blame] | 24 | - uses: actions/checkout@v4 |
| 25 | with: |
| 26 | ref: ${{ inputs.ref }} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 27 | |
| 28 | - uses: actions/setup-go@v5 |
| 29 | with: |
| Philip Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 30 | go-version-file: "${{ inputs.working-directory || '.'}}/go.mod" |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 31 | cache: true |
| 32 | |
| Josh Bleecher Snyder | 2a32f01 | 2025-06-05 19:40:07 -0700 | [diff] [blame] | 33 | - name: Cache Go 1.24.4 |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 34 | uses: actions/cache@v4 |
| 35 | with: |
| 36 | path: | |
| 37 | ~/.cache/go-build |
| Josh Bleecher Snyder | 2a32f01 | 2025-06-05 19:40:07 -0700 | [diff] [blame] | 38 | key: ${{ runner.os }}-go1.24.4-${{ hashFiles('**/go.sum') }} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 39 | restore-keys: | |
| Josh Bleecher Snyder | 2a32f01 | 2025-06-05 19:40:07 -0700 | [diff] [blame] | 40 | ${{ runner.os }}-go1.24.4- |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 41 | |
| philip.zeyliger | 46be096 | 2025-06-14 17:51:15 +0000 | [diff] [blame] | 42 | - name: Optimize APT |
| Philip Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 43 | working-directory: ${{ inputs.working-directory || '.'}} |
| 44 | run: | |
| 45 | pwd |
| 46 | ./.github/scripts/optimize-apt.sh |
| philip.zeyliger | 46be096 | 2025-06-14 17:51:15 +0000 | [diff] [blame] | 47 | |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 48 | - name: Install tools |
| 49 | run: | |
| 50 | go install golang.org/x/tools/gopls@latest |
| Philip Zeyliger | 6c1f34f | 2025-04-23 19:33:03 -0700 | [diff] [blame] | 51 | go install gotest.tools/gotestsum@latest |
| Josh Bleecher Snyder | 833a0f8 | 2025-04-24 18:39:36 +0000 | [diff] [blame] | 52 | go install mvdan.cc/gofumpt@latest |
| 53 | go install golang.org/x/tools/cmd/goimports@latest |
| Philip Zeyliger | c013134 | 2025-06-13 21:07:08 -0700 | [diff] [blame] | 54 | # Empirically (by logging into runners with tmate), there are versions of Chromium/Chrome in /opt/google/chrome |
| Philip Zeyliger | a35de5f | 2025-06-14 12:00:48 -0700 | [diff] [blame] | 55 | # and /usr/local/share/chromium/chrome-linux, and /usr/bin/chromium links to the former. Therefore, we |
| 56 | # don't need to apt-get it separately. |
| Philip Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 57 | |
| Philip Zeyliger | a35de5f | 2025-06-14 12:00:48 -0700 | [diff] [blame] | 58 | # If you wish to do some interactive debugging, the following is handy. It will print |
| 59 | # an SSH command that you can use to connect to the runner instance. |
| 60 | - name: tmate debugging (disabled) |
| 61 | if: false |
| 62 | run: | |
| 63 | sudo apt-get update && sudo apt-get install -y tmate |
| 64 | set -x |
| 65 | tmate -S /tmp/tmate.sock.${GITHUB_RUN_ID} new-session -d |
| 66 | tmate -S /tmp/tmate.sock.${GITHUB_RUN_ID} wait tmate-ready |
| 67 | tmate -S /tmp/tmate.sock.${GITHUB_RUN_ID} display -p '#{tmate_ssh}' |
| 68 | sleep 1800 |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 69 | |
| 70 | - name: Go generate |
| Philip Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 71 | working-directory: ${{ inputs.working-directory || '.'}} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 72 | run: | |
| 73 | go generate ./... |
| Josh Bleecher Snyder | 88c61bd | 2025-04-30 13:40:34 -0700 | [diff] [blame] | 74 | # if go generate created a diff |
| 75 | if ! git diff --exit-code; then |
| 76 | echo "go generate created a diff" |
| 77 | git diff |
| 78 | exit 1 |
| 79 | fi |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 80 | |
| 81 | - name: Run tests |
| Philip Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 82 | working-directory: ${{ inputs.working-directory || '.'}} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 83 | run: | |
| Josh Bleecher Snyder | 923a3ba | 2025-05-05 15:27:13 -0700 | [diff] [blame] | 84 | GOEXPERIMENT=synctest gotestsum --format testname -- ./... |
| 85 | GOEXPERIMENT=synctest gotestsum --format testname -- -race ./... |