-
Notifications
You must be signed in to change notification settings - Fork 8
249 lines (238 loc) · 8 KB
/
Copy pathci.yml
File metadata and controls
249 lines (238 loc) · 8 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
on:
push:
branches: [ main ]
tags:
- 'v*'
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch: {}
name: CI
jobs:
pr-allow:
name: Check PR allow
runs-on: ubuntu-latest
outputs:
allowed: ${{ steps.check.outputs.allowed }}
reason: ${{ steps.check.outputs.reason }}
steps:
- id: check
uses: actions/github-script@v7
with:
script: |
const evt = context.eventName;
if (evt !== 'pull_request') {
core.setOutput('allowed', 'true');
core.setOutput('reason', 'not-a-pr');
return;
}
const pr = context.payload.pull_request;
const sameRepo = pr.head.repo.full_name === pr.base.repo.full_name;
let approved = false;
try {
const { owner, repo } = context.repo;
const number = pr.number;
const reviews = await github.paginate(github.rest.pulls.listReviews, { owner, repo, pull_number: number });
approved = reviews.some(r => r.state === 'APPROVED');
} catch (e) {
core.info('Failed to list reviews: ' + e.message);
}
const allowed = sameRepo || approved;
core.setOutput('allowed', allowed ? 'true' : 'false');
core.setOutput('reason', allowed ? (sameRepo ? 'same-repo' : 'approved') : 'fork-unapproved');
# ================
# TEST JOB
# runs on every push and allowed PR
# runs 2x3 times (see matrix)
# ================
test:
name: Test
strategy:
matrix:
go-version: [1.23.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
needs: pr-allow
if: needs.pr-allow.outputs.allowed == 'true'
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Build (CGO)
shell: bash
run: |
export CGO_ENABLED=1
go version
go build -v -o /dev/null .
- name: Unit tests (exclude legacy e2e)
shell: bash
run: |
set -euo pipefail
export CGO_ENABLED=1
pkgs=$(go list ./... | grep -v '/test/e2e')
go test -v -count=1 $pkgs
- name: Security tests (explicit)
shell: bash
run: |
set -euo pipefail
export CGO_ENABLED=1
go test -v -count=1 ./tests
# ================
# RELEASE JOBS
# runs after a success test
# only runs on push "v*" tag
# ================
release_binaries:
permissions:
contents: write
pull-requests: write
repository-projects: write
name: Release Binaries
needs: test
if: startsWith(github.ref, 'refs/tags/v')
strategy:
max-parallel: 1
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install cross toolchains and libc headers (Linux CGO)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
gcc-arm-linux-gnueabihf gcc-arm-linux-gnueabi gcc-aarch64-linux-gnu \
libc6-dev-armhf-cross libc6-dev-arm64-cross \
linux-libc-dev-armhf-cross linux-libc-dev-arm64-cross
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x
check-latest: true
- name: Run GoReleaser [Linux+Windows]
if: runner.os == 'Linux'
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: v2.4.0
args: release --verbose --config .github/goreleaser.linuxwin.yml
env:
GORELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
CGO_ENABLED: 1
- name: Run GoReleaser [Darwin]
if: runner.os == 'macOS'
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: v2.4.0
args: release --verbose --config .github/goreleaser.darwin.yml
env:
GORELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
finalize_release:
name: Publish GitHub Release (mark latest)
needs: release_binaries
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Publish release (unset draft)
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const tag = context.ref.replace('refs/tags/', '');
core.info(`Publishing release for tag ${tag}`);
try {
// getReleaseByTag does NOT return drafts; list and filter instead
const releases = await github.paginate(github.rest.repos.listReleases, { owner, repo, per_page: 100 });
const matches = releases.filter(r => r.tag_name === tag);
if (matches.length === 0) {
core.setFailed(`No release found for ${tag} (did GoReleaser create it?)`);
return;
}
let changed = 0;
for (const r of matches) {
if (r.draft) {
await github.rest.repos.updateRelease({ owner, repo, release_id: r.id, draft: false });
changed++;
core.info(`Published release id=${r.id}`);
} else {
core.info(`Release id=${r.id} already published`);
}
}
if (changed === 0) {
core.info('All matching releases already published');
}
} catch (e) {
core.setFailed(`Failed to publish release for ${tag}: ${e.message}`);
}
build_clients:
name: Build clients (CGO off)
needs: test
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Checkout code
uses: actions/checkout@v4
- name: Build all client binaries
run: |
make client-all VERSION=dev
build_server_linux:
name: Build server (Linux only, CGO on)
needs: test
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Checkout code
uses: actions/checkout@v4
- name: Install cross toolchains and libc headers (Linux CGO)
run: |
sudo apt-get update
sudo apt-get install -y \
gcc-arm-linux-gnueabihf gcc-arm-linux-gnueabi gcc-aarch64-linux-gnu \
libc6-dev-armhf-cross libc6-dev-arm64-cross \
linux-libc-dev-armhf-cross linux-libc-dev-arm64-cross
- name: Build server linux binaries
run: |
make server-linux-all VERSION=dev
legacy_e2e:
name: Legacy e2e (non-blocking)
needs: test
continue-on-error: true
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Checkout PR head (on approved review)
if: github.event_name == 'pull_request_review'
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Checkout code (push/tags/manual)
if: github.event_name != 'pull_request_review'
uses: actions/checkout@v4
- name: Run legacy e2e tests
shell: bash
run: |
set -euo pipefail
export CGO_ENABLED=1
go test -v -count=1 ./test/e2e