blob: 3bb4742ef860f9a305c5481f719d72428ab14712 [file] [log] [blame]
Philip Zeyliger4f833b12025-07-16 16:30:41 -07001name: sketch_go_tests
Earl Lee2e463fb2025-04-17 11:22:22 -07002on:
3 workflow_call:
Josh Bleecher Snyder936ba622025-04-30 20:53:21 +00004 inputs:
5 ref:
6 description: "The git ref to checkout"
7 required: false
8 type: string
9 default: ""
Philip Zeyliger037f3162025-06-20 22:26:31 +000010 working-directory:
11 description: "Working directory for the workflow"
12 required: false
13 type: string
Philip Zeyliger4f833b12025-07-16 16:30:41 -070014 default: "${{ vars.SKETCH_WORKING_DIR || '.' }}"
15 include-slow-tests:
16 description: "Whether to include slow tests"
17 required: false
18 type: boolean
19 default: true
Earl Lee2e463fb2025-04-17 11:22:22 -070020 push:
21 branches-ignore:
Josh Bleecher Snyder93bb66a2025-04-30 16:29:05 -070022 - "queue-main-*"
23 - "queue-dev-*"
Earl Lee2e463fb2025-04-17 11:22:22 -070024 pull_request:
25jobs:
26 test:
Philip Zeyliger4ce9dca2025-06-27 09:46:42 -070027 runs-on: "linux-x64-ubuntu-latest-8-core"
Earl Lee2e463fb2025-04-17 11:22:22 -070028 steps:
Josh Bleecher Snyder936ba622025-04-30 20:53:21 +000029 - uses: actions/checkout@v4
30 with:
31 ref: ${{ inputs.ref }}
Earl Lee2e463fb2025-04-17 11:22:22 -070032
33 - uses: actions/setup-go@v5
34 with:
Philip Zeyliger4f833b12025-07-16 16:30:41 -070035 go-version-file: "${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}}/go.mod"
Earl Lee2e463fb2025-04-17 11:22:22 -070036 cache: true
37
Philip Zeyliger5a3cd2a2025-07-14 15:16:06 -070038 - name: Cache Go 1.24.5
Earl Lee2e463fb2025-04-17 11:22:22 -070039 uses: actions/cache@v4
40 with:
41 path: |
42 ~/.cache/go-build
Philip Zeyliger5a3cd2a2025-07-14 15:16:06 -070043 key: ${{ runner.os }}-go1.24.5-${{ hashFiles('**/go.sum') }}
Earl Lee2e463fb2025-04-17 11:22:22 -070044 restore-keys: |
Philip Zeyliger5a3cd2a2025-07-14 15:16:06 -070045 ${{ runner.os }}-go1.24.5-
Earl Lee2e463fb2025-04-17 11:22:22 -070046
philip.zeyliger46be0962025-06-14 17:51:15 +000047 - name: Optimize APT
Philip Zeyliger4f833b12025-07-16 16:30:41 -070048 working-directory: ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}}
Philip Zeyliger037f3162025-06-20 22:26:31 +000049 run: |
50 pwd
51 ./.github/scripts/optimize-apt.sh
philip.zeyliger46be0962025-06-14 17:51:15 +000052
Earl Lee2e463fb2025-04-17 11:22:22 -070053 - name: Install tools
54 run: |
55 go install golang.org/x/tools/gopls@latest
Philip Zeyliger6c1f34f2025-04-23 19:33:03 -070056 go install gotest.tools/gotestsum@latest
Josh Bleecher Snyder833a0f82025-04-24 18:39:36 +000057 go install mvdan.cc/gofumpt@latest
58 go install golang.org/x/tools/cmd/goimports@latest
Philip Zeyligerc0131342025-06-13 21:07:08 -070059 # Empirically (by logging into runners with tmate), there are versions of Chromium/Chrome in /opt/google/chrome
Philip Zeyligera35de5f2025-06-14 12:00:48 -070060 # and /usr/local/share/chromium/chrome-linux, and /usr/bin/chromium links to the former. Therefore, we
61 # don't need to apt-get it separately.
Philip Zeyliger037f3162025-06-20 22:26:31 +000062
Philip Zeyligera35de5f2025-06-14 12:00:48 -070063 # If you wish to do some interactive debugging, the following is handy. It will print
64 # an SSH command that you can use to connect to the runner instance.
65 - name: tmate debugging (disabled)
66 if: false
67 run: |
68 sudo apt-get update && sudo apt-get install -y tmate
69 set -x
70 tmate -S /tmp/tmate.sock.${GITHUB_RUN_ID} new-session -d
71 tmate -S /tmp/tmate.sock.${GITHUB_RUN_ID} wait tmate-ready
72 tmate -S /tmp/tmate.sock.${GITHUB_RUN_ID} display -p '#{tmate_ssh}'
73 sleep 1800
Earl Lee2e463fb2025-04-17 11:22:22 -070074
75 - name: Go generate
Philip Zeyliger4f833b12025-07-16 16:30:41 -070076 working-directory: ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}}
Earl Lee2e463fb2025-04-17 11:22:22 -070077 run: |
78 go generate ./...
Josh Bleecher Snyder88c61bd2025-04-30 13:40:34 -070079 # if go generate created a diff
80 if ! git diff --exit-code; then
81 echo "go generate created a diff"
82 git diff
83 exit 1
84 fi
Earl Lee2e463fb2025-04-17 11:22:22 -070085
86 - name: Run tests
Philip Zeyliger4f833b12025-07-16 16:30:41 -070087 working-directory: ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}}
Earl Lee2e463fb2025-04-17 11:22:22 -070088 run: |
Philip Zeyliger4f833b12025-07-16 16:30:41 -070089 if [ "${{ inputs.include-slow-tests }}" = "false" ]; then
90 echo "Running tests without slow tests (short mode, no race re-run)"
Philip Zeyligeraea6a8c2025-07-29 11:30:34 -070091 GOEXPERIMENT=synctest gotestsum --format testname --jsonfile test-results.json -- -short ./...
Philip Zeyliger4f833b12025-07-16 16:30:41 -070092 else
93 echo "Running full test suite including slow tests"
Philip Zeyligeraea6a8c2025-07-29 11:30:34 -070094 GOEXPERIMENT=synctest gotestsum --format testname --jsonfile test-results.json -- ./...
95 GOEXPERIMENT=synctest gotestsum --format testname --jsonfile test-results-race.json -- -race ./...
Philip Zeyliger4f833b12025-07-16 16:30:41 -070096 fi
Philip Zeyligeraea6a8c2025-07-29 11:30:34 -070097
98 - name: Upload test results
99 if: always()
100 uses: actions/upload-artifact@v4
101 with:
102 name: sketch-test-results-${{ github.run_id }}
103 path: |
104 ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}}/test-results.json
105 ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}}/test-results-race.json
106 retention-days: 30