Debian Codegraph @

.github/workflows/test.yml

raw
1 name: Test
2
3 on:
4 workflow_dispatch:
5 push:
6 branches: [main]
7 pull_request:
8 branches: [main]
9
10 # Cancel testing of a previous commit for the same branch.
11 concurrency:
12 group: ${{ github.workflow }}-${{ github.ref }}
13 cancel-in-progress: true
14
15 permissions:
16 contents: write # To update gh-badges branch.
17
18 jobs:
19 main:
20 runs-on: ubuntu-latest
21 timeout-minutes: 10
22
23 steps:
24 - uses: actions/checkout@v7
25
26 - uses: jdx/mise-action@v4
27 - run: git reset --hard # Work around https://github.com/jdx/mise/discussions/8270.
28
29 - uses: powerman/.github/.github/actions/cache-go-and-tools@main
30
31 - run: mise run ci
32
33 - uses: powerman/.github/.github/actions/coverage-badge@main
34 if: github.ref_name == 'main'
35 with:
36 total_cmd: "mise run -q cover:go:total | tail -n 1 | sed -e 's/.*)//'"
37
38 # Testing on available native platforms.
39 native:
40 strategy:
41 matrix:
42 include:
43 - {os: ubuntu-24.04-arm} # Linux ARM64
44 - {os: macos-15-intel} # macOS AMD64
45 - {os: macos-latest} # macOS ARM64
46 - {os: windows-latest} # Windows AMD64
47 - {os: windows-11-arm} # Windows ARM64
48 runs-on: ${{ matrix.os }}
49 timeout-minutes: 10
50
51 steps:
52 - uses: actions/checkout@v7
53
54 - uses: actions/setup-go@v6
55 with:
56 go-version-file: 'go.mod'
57
58 - run: go test -timeout=60s -race ./...
59 if: matrix.os != 'windows-11-arm'
60 - run: go test -timeout=60s ./...
61 if: matrix.os == 'windows-11-arm'
62
63 # Testing on available docker QEMU platforms (Linux only).
64 qemu:
65 strategy:
66 matrix:
67 include:
68 - {arch: arm, v: v7}
69 - {arch: ppc64le}
70 - {arch: s390x}
71 - {arch: riscv64}
72 runs-on: ubuntu-latest
73 timeout-minutes: 10
74
75 steps:
76 - uses: actions/checkout@v7
77
78 - name: Set up QEMU
79 uses: docker/setup-qemu-action@v4
80 with:
81 platforms: ${{ matrix.arch }}
82
83 - name: Set up Docker Buildx
84 uses: docker/setup-buildx-action@v4
85
86 - uses: powerman/.github/.github/actions/cache-go-and-tools@main
87 with:
88 key: qemu-${{ matrix.arch }}${{ matrix.v && format('-{0}', matrix.v) || '' }}
89
90 - name: Run tests
91 env:
92 PLATFORM: linux/${{ matrix.arch }}${{ matrix.v && format('/{0}', matrix.v) || '' }}
93 run: |
94 mkdir -p ~/go ~/.cache/go-build
95 V=$(awk '$1=="toolchain"{v=$2}$1=="go"&&!v{v=$2}END{sub(/^go/,"",v);print v}' go.mod)
96 docker run -i --rm --platform "$PLATFORM" \
97 -w /workspace \
98 -v "$PWD:/workspace" \
99 -v "$HOME/.cache/go-build:/root/.cache/go-build" \
100 -v "$HOME/go:/go" \
101 "golang:${V}-alpine" go test -timeout=60s ./...
102
103 # Aggregate job for branch protection.
104 test:
105 needs: [main, native, qemu]
106 runs-on: ubuntu-latest
107 if: always()
108 steps:
109 - name: Fail if any dependency failed, cancelled or skipped
110 if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')
111 run: exit 1