-
Notifications
You must be signed in to change notification settings - Fork 12
133 lines (114 loc) · 3.5 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: CI
on:
push:
branches: [main]
pull_request:
branches: ['**']
types:
# On by default if types not specified:
- "opened"
- "reopened"
- "synchronize"
# For `skip changelog` handling:
- "labeled"
- "unlabeled"
permissions:
contents: read
env:
# Use the Go toolchain installed by setup-go
# https://github.com/actions/setup-go/issues/457
GOTOOLCHAIN: local
jobs:
test:
name: Test / Go ${{ matrix.go-version }} / ${{ matrix.os }}/${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: ['1.23.x', '1.22.x', '1.21.x']
arch: ['amd64', '386', 'arm64']
os: ['ubuntu-latest']
include:
- os: 'macos-latest'
arch: 'amd64'
go-version: '1.23.x'
- os: 'windows-latest'
arch: 'amd64'
go-version: '1.23.x'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
# GH runners use amd64 which also support 386.
# For other architectures, use qemu.
- name: Install QEMU
if: matrix.arch != 'amd64' && matrix.arch != '386'
uses: docker/setup-qemu-action@v3
- name: Enable race detection
shell: bash
run: |
# Only amd64 support data-race detection in CI.
# qemu doesn't give us cgo, which is needed for arm64.
if [[ "$GOARCH" == amd64 ]]; then
echo "Enabling data-race detection."
else
echo "NO_RACE=1" >> "$GITHUB_ENV"
fi
env:
GOARCH: ${{ matrix.arch }}
- name: Test ${{ matrix.arch }}
run: make cover
shell: bash
env:
GOARCH: ${{ matrix.arch }}
- name: Coverage
uses: codecov/codecov-action@v4
with:
files: ./cover.unsafe.out,./cover.safe.out
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Check out repository
- uses: actions/setup-go@v5
name: Set up Go
with:
# Use the Go language version in go.mod for linting.
go-version-file: go.mod
cache: false # managed by golangci-lint
- uses: golangci/golangci-lint-action@v6
name: Install golangci-lint
with:
version: latest
args: --help # make lint will run the linter
- name: Lint
run: make lint GOLANGCI_LINT_ARGS=--out-format=github-actions
# Write in a GitHub Actions-friendly format
# to annotate lines in the PR.
changelog:
runs-on: ubuntu-latest
steps:
- name: "Check CHANGELOG is updated or PR is marked skip changelog"
uses: brettcannon/check-for-changed-files@v1.2.1
# Run only if PR body doesn't contain '[skip changelog]'.
if: ${{ !contains(github.event.pull_request.body, '[skip changelog]') }}
with:
file-pattern: CHANGELOG.md
skip-label: "skip changelog"
token: ${{ secrets.GITHUB_TOKEN }}
failure-message: >-
Missing a changelog update ${file-pattern}; please update or
if a changelog entry is not needed, use label ${skip-label}
or add [skip changelog] to the PR description.
# ci-ok is a dummy job that runs after test and lint.
# It provides a job for us to attach a Required Status Check to.
ci-ok:
name: OK
runs-on: ubuntu-latest
needs: [test, lint, changelog]
steps:
- name: Success
run: echo "All checks passed."