-
Notifications
You must be signed in to change notification settings - Fork 41
365 lines (313 loc) · 10.1 KB
/
publish.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
name: Build and Publish
on:
workflow_dispatch:
inputs:
targets:
description: Build targets (separated by spaces)
type: string
default: x86_64 aarch64
workflow_call:
inputs:
targets:
description: Build targets (separated by spaces)
type: string
default: x86_64 aarch64
push:
branches-ignore:
- nightly
pull_request:
branches:
- main
release:
types: [released] # Prevents double builds on nightly
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
gomod:
name: Validate Go modules
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# Use ref_name instead of ref so we always get the branch to pull our
# latest commit from.
ref: ${{ github.ref_name }}
- name: Install Nix shell
uses: ./.github/actions/init-nix
with:
shell-file: shell.nix
- name: Tidy up Go modules
run: go mod tidy
- name: Update gomod2nix.toml
run: gomod2nix --outdir nix
- name: Prepare commit
id: prepare
run: |
if git diff --exit-code nix/gomod2nix.toml go.mod go.sum; then
echo "changed=0" >> $GITHUB_OUTPUT
else
echo "changed=1" >> $GITHUB_OUTPUT
fi
- name: Commit changes
if: steps.prepare.outputs.changed == 1
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Tidy up Go modules
file_pattern: nix/gomod2nix.toml go.mod go.sum
generate:
name: Run go generate
needs: gomod
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Install Nix shell
uses: ./.github/actions/init-nix
with:
shell-file: shell.nix
- name: Generate
run: go generate ./...
- name: Prepare commit
id: prepare
run: |
if git diff --exit-code; then
echo "changed=0" >> $GITHUB_OUTPUT
else
echo "changed=1" >> $GITHUB_OUTPUT
fi
- name: Commit changes
if: steps.prepare.outputs.changed == 1
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Run go generate
lint:
name: Lint
needs: [gomod, generate]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Install Nix shell
uses: ./.github/actions/init-nix
with:
shell-file: shell.nix
- name: Format
run: |
fail=
go list -f '{{ .Dir }}' | while read -r d; do
goimports -l "$d" | while read -r f; do
fail=1
printf "::error file=%s::%s\n" "$d/$f" "File is not formatted"
done
done
[[ -z "$fail" ]]
- name: Vet
run: go vet ./... |& workflowify -e -t vet
- name: Staticcheck (warnings)
run: staticcheck ./... || true |& workflowify -w -t staticcheck
- name: Test
run: go test -v ./...
# We need a whole ass job for this.
# https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object
build-init:
name: Initialize build environment
runs-on: ubuntu-latest
outputs:
target-matrix: ${{ steps.set-matrix.outputs.matrix }}
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- id: set-targets
run: |
if [[ "$TARGETS" == "" ]]; then
case "$ACTION" in
push|release)
TARGETS="x86_64 aarch64" ;;
pull_request)
TARGETS="x86_64" ;;
*)
echo "Unknown action: $ACTION"
exit 1 ;;
esac
fi
echo "targets=$TARGETS" >> $GITHUB_OUTPUT
env:
ACTION: ${{ github.event_name }}
TARGETS: ${{ inputs.targets }}
- id: set-matrix
run: |
echo "matrix=$(printf "%s\n" $TARGETS | jq -R | jq -sc)" >> $GITHUB_OUTPUT
env:
TARGETS: ${{ steps.set-targets.outputs.targets }}
- id: version
run: |
echo "version=$(.github/tools/git-version)" >> $GITHUB_OUTPUT
build-source:
name: Build source tarball
needs: [build-init, gomod, generate]
runs-on: ubuntu-latest
outputs:
name: ${{ steps.build.outputs.name }}
directory: ${{ steps.build.outputs.directory }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Install Nix environment
uses: ./.github/actions/init-nix
with:
instantiated-expression: ${{ steps.init.outputs.expr }}
- name: Build
id: build
run: |
expr=$(cat<<EOF
import ./nix {
action = "build-source";
version = "$VERSION";
}
EOF)
out=$(nix-build -E "$expr" --no-out-link)
echo "directory=$out" >> $GITHUB_OUTPUT
echo "name=source-$VERSION" >> $GITHUB_OUTPUT
env:
VERSION: ${{ needs.build-init.outputs.version }}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: gtkcord4-${{ steps.build.outputs.name }}
path: ${{ steps.build.outputs.directory }}
build:
name: Build
needs: [build-init, gomod, generate]
runs-on: ubuntu-latest
outputs:
name: ${{ steps.build.outputs.name }}
versions: ${{ steps.versions.outputs.json }}
directory: ${{ steps.build.outputs.directory }}
strategy:
fail-fast: true
matrix:
target: ${{ fromJSON(needs.build-init.outputs.target-matrix) }}
tags:
- [""]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Initialize environment
id: init
run: |
cat<<EOF > /tmp/expr.nix
import ./nix {
action = "build-cross";
version = "$VERSION";
target = $TARGET;
tags = $TAGS;
}
EOF
# GitHub doesn't allow multiline strings in outputs, so we trim the
# new lines.
echo "expr=$(cat /tmp/expr.nix | tr -d $'\n')" >> $GITHUB_OUTPUT
env:
VERSION: ${{ needs.build-init.outputs.version }}
TARGET: ${{ toJSON(matrix.target) }}
TAGS: ${{ toJSON(matrix.tags) }}
- name: Install Nix environment
uses: ./.github/actions/init-nix
with:
instantiated-expression: ${{ steps.init.outputs.expr }}
- name: Build
id: build
run: |
out=$(nix-build -E "$EXPR" --no-out-link)
echo "path=$out" >> $GITHUB_OUTPUT
names=$(nix-instantiate --eval --json -E "builtins.attrNames ($EXPR).outputs")
name=$(jq -r '.[0]' <<< "$names")
echo "name=$name" >> $GITHUB_OUTPUT
env:
EXPR: ${{ steps.init.outputs.expr }}
VERSION: ${{ needs.build-init.outputs.version }}
TARGET: ${{ toJSON(matrix.target) }}
TAGS: ${{ toJSON(matrix.tags) }}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.build.outputs.name }}
path: ${{ steps.build.outputs.path }}
upload-release:
name: Upload artifacts to release
needs: [build, build-source]
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Install Nix shell
uses: ./.github/actions/init-nix
with:
shell-file: shell.nix
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Upload artifacts to GitHub Releases
run: upload-artifacts artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
RELEASE_ID: ${{ github.event.release.id }}
nightly-release:
name: Update nightly release
needs: [build, build-source]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Install Nix shell
uses: ./.github/actions/init-nix
with:
shell-file: shell.nix
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: /tmp/artifacts
- name: Collect built artifacts
run: mkdir /tmp/bin && find /tmp/artifacts -type f -exec mv {} /tmp/bin/ \;
- name: Generate Nightly release notes
id: generate-notes
run: |
versionJSON=$(nightly-info)
version() { jq -r ".$1" <<< "$versionJSON"; }
body=$(cat<<EOF
This is a nightly release of gtkcord4. It is built from the latest
commit on the `main` branch.
**Warning:** This release is not guaranteed to be stable. It may
contain bugs and/or security vulnerabilities. Use at your own risk.
Please report any issues you encounter as separate GitHub Issues.
### Version Information
- gtkcord4: $(version gtkcord4)
- Go: $(version go)
- GTK: $(version gtk4)
- Libadwaita: $(version libadwaita1)
EOF)
echo "body=$(jq --null-input --arg body "$body" '$body')" >> $GITHUB_OUTPUT
env:
VERSIONS: ${{ needs.build.outputs.versions }}
- name: Update Nightly release
uses: andelf/nightly-release@ce2d0a30db8cf9f3920a4237d6a0b874400710c1
with:
name: Nightly Release
body: ${{ fromJSON(steps.generate-notes.outputs.body) }}
tag_name: nightly
prerelease: true
files: /tmp/bin/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}