| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 1 | name: sketch_go_tests |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 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 |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 14 | 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 Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 20 | push: |
| 21 | branches-ignore: |
| Josh Bleecher Snyder | 93bb66a | 2025-04-30 16:29:05 -0700 | [diff] [blame] | 22 | - "queue-main-*" |
| 23 | - "queue-dev-*" |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 24 | pull_request: |
| 25 | jobs: |
| 26 | test: |
| Philip Zeyliger | 4ce9dca | 2025-06-27 09:46:42 -0700 | [diff] [blame] | 27 | runs-on: "linux-x64-ubuntu-latest-8-core" |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 28 | steps: |
| Josh Bleecher Snyder | 936ba62 | 2025-04-30 20:53:21 +0000 | [diff] [blame] | 29 | - uses: actions/checkout@v4 |
| 30 | with: |
| 31 | ref: ${{ inputs.ref }} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 32 | |
| 33 | - uses: actions/setup-go@v5 |
| 34 | with: |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 35 | go-version-file: "${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}}/go.mod" |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 36 | cache: true |
| 37 | |
| Philip Zeyliger | 5a3cd2a | 2025-07-14 15:16:06 -0700 | [diff] [blame] | 38 | - name: Cache Go 1.24.5 |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 39 | uses: actions/cache@v4 |
| 40 | with: |
| 41 | path: | |
| 42 | ~/.cache/go-build |
| Philip Zeyliger | 5a3cd2a | 2025-07-14 15:16:06 -0700 | [diff] [blame] | 43 | key: ${{ runner.os }}-go1.24.5-${{ hashFiles('**/go.sum') }} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 44 | restore-keys: | |
| Philip Zeyliger | 5a3cd2a | 2025-07-14 15:16:06 -0700 | [diff] [blame] | 45 | ${{ runner.os }}-go1.24.5- |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 46 | |
| philip.zeyliger | 46be096 | 2025-06-14 17:51:15 +0000 | [diff] [blame] | 47 | - name: Optimize APT |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 48 | working-directory: ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}} |
| Philip Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 49 | run: | |
| 50 | pwd |
| 51 | ./.github/scripts/optimize-apt.sh |
| philip.zeyliger | 46be096 | 2025-06-14 17:51:15 +0000 | [diff] [blame] | 52 | |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 53 | - name: Install tools |
| 54 | run: | |
| 55 | go install golang.org/x/tools/gopls@latest |
| Philip Zeyliger | 6c1f34f | 2025-04-23 19:33:03 -0700 | [diff] [blame] | 56 | go install gotest.tools/gotestsum@latest |
| Josh Bleecher Snyder | 833a0f8 | 2025-04-24 18:39:36 +0000 | [diff] [blame] | 57 | go install mvdan.cc/gofumpt@latest |
| 58 | go install golang.org/x/tools/cmd/goimports@latest |
| Philip Zeyliger | c013134 | 2025-06-13 21:07:08 -0700 | [diff] [blame] | 59 | # 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] | 60 | # 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 Zeyliger | 037f316 | 2025-06-20 22:26:31 +0000 | [diff] [blame] | 62 | |
| Philip Zeyliger | a35de5f | 2025-06-14 12:00:48 -0700 | [diff] [blame] | 63 | # 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 Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 74 | |
| 75 | - name: Go generate |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 76 | working-directory: ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 77 | run: | |
| 78 | go generate ./... |
| Josh Bleecher Snyder | 88c61bd | 2025-04-30 13:40:34 -0700 | [diff] [blame] | 79 | # 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 Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 85 | |
| 86 | - name: Run tests |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 87 | working-directory: ${{ inputs.working-directory || vars.SKETCH_WORKING_DIR || '.'}} |
| Earl Lee | 2e463fb | 2025-04-17 11:22:22 -0700 | [diff] [blame] | 88 | run: | |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 89 | if [ "${{ inputs.include-slow-tests }}" = "false" ]; then |
| 90 | echo "Running tests without slow tests (short mode, no race re-run)" |
| Philip Zeyliger | aea6a8c | 2025-07-29 11:30:34 -0700 | [diff] [blame] | 91 | GOEXPERIMENT=synctest gotestsum --format testname --jsonfile test-results.json -- -short ./... |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 92 | else |
| 93 | echo "Running full test suite including slow tests" |
| Philip Zeyliger | aea6a8c | 2025-07-29 11:30:34 -0700 | [diff] [blame] | 94 | GOEXPERIMENT=synctest gotestsum --format testname --jsonfile test-results.json -- ./... |
| 95 | GOEXPERIMENT=synctest gotestsum --format testname --jsonfile test-results-race.json -- -race ./... |
| Philip Zeyliger | 4f833b1 | 2025-07-16 16:30:41 -0700 | [diff] [blame] | 96 | fi |
| Philip Zeyliger | aea6a8c | 2025-07-29 11:30:34 -0700 | [diff] [blame] | 97 | |
| 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 |