-
Notifications
You must be signed in to change notification settings - Fork 40
316 lines (259 loc) · 8.8 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
name: Build and Publish
on:
push:
branches-ignore:
- nightly
pull_request:
release:
types: [released] # Prevents double builds on nightly
defaults:
run:
# Use Nix for all of our build commands.
# Doing this will automatically run everything in our devShell.
shell: nix develop -c bash -e {0}
jobs:
generate:
name: Run go generate
runs-on: ubuntu-latest
needs: gomod # avoid pushing at the same time as gomod
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Generate
run: go generate ./...
- name: Commit changes
uses: ./.github/actions/push-or-fail
with:
commit-message: Run go generate
gomod:
name: Validate Go modules
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Tidy up Go modules
run: go mod tidy
- name: Update gomod2nix.toml
run: gomod2nix --outdir nix
- name: Commit changes
uses: ./.github/actions/push-or-fail
with:
commit-message: Tidy up Go modules
file-pattern: nix/gomod2nix.toml go.mod go.sum
lint:
name: Lint
needs: [gomod, generate]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- 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: nix run .#staticcheck ./... || true |& workflowify -w -t staticcheck
- name: Test
run: go test -v ./...
build-source:
name: Build source tarball
needs: [gomod, generate]
runs-on: ubuntu-latest
outputs:
name: ${{ steps.build.outputs.name }}
directory: ${{ steps.build.outputs.directory }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build
id: build
run: |
nix build --file ./. lib.mkSource \
--argstr version "$(git-version)"
echo name=$(ls result) >> "$GITHUB_OUTPUT"
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.build.outputs.name }}
path: result
build-linux:
name: Build for Linux (via Nix)
needs: [gomod, generate]
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
target:
- x86_64-linux
- aarch64-linux
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build
id: build
run: |
nix build --file ./. lib.mkPackageCross \
--argstr version "" \
--argstr target "${{ matrix.target }}"
echo name=$(ls result) >> "$GITHUB_OUTPUT"
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.build.outputs.name }}
path: result
build-windows:
name: Build for Windows
needs: [gomod, generate]
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Build using MSYS2
uses: ./.github/actions/build-msys2-app
with:
msys-dependencies: |
mingw-w64-x86_64-gcc
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-gtk4
mingw-w64-x86_64-libadwaita
mingw-w64-x86_64-gobject-introspection
mingw-w64-x86_64-glib2
mingw-w64-x86_64-go
out-path: ${{ runner.temp }}/exe
exe-name: dissent.exe
build-tags: nogtksource
- name: Prepare
id: prepare
run: |
version=$(.github/tools/git-version)
# version is usually in the format vMAJOR.MINOR.PATCH-N-HASH, while
# Advanced Installer only allows format MAJOR.MINOR.PATCH.REVISION.
# We trim out our hash, trim the leading v, and replace the first - with a .
if [[ $version =~ ^v([0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?) ]]; then
version=${BASH_REMATCH[1]}
version=${version//-/.}
else
# Use some fallback version. Realistically, this should never
# happen, so we throw a warning.
version=0.0.0.999
echo '::warning::Could not determine version from git for Windows build. Using `$version`'
fi
cat<<EOF >> "$GITHUB_OUTPUT"
version=$version
name=dissent-windows-amd64
EOF
- name: Make MSI installer
uses: ./.github/actions/make-advinst-app
with:
aip-file: nix/dissent-windows.aip
exe-directory: ${{ runner.temp }}/exe
exe-name: dissent.exe
app-name: Dissent
app-version: ${{ steps.prepare.outputs.version }}
icon-file: internal/icons/windows/dissent.ico
out-path: result
out-name: ${{ steps.prepare.outputs.name }}.msi
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.prepare.outputs.name }}
path: result
upload-release:
name: Upload artifacts to release
needs: [build-source, build-linux, build-windows]
environment: Stable release
runs-on: ubuntu-latest
if: github.event_name == 'release'
concurrency:
group: release-${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Upload artifacts to GitHub Releases
uses: diamondburned/action-upload-release@main
with:
files: artifacts
nightly-release:
name: Update nightly release
needs: [build-source, build-linux, build-windows]
environment: Nightly release
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
concurrency:
group: nightly-${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- 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 Dissent. It is built from the latest
commit on the `main` branch.
**Warning:** This release is not guaranteed to be stable and may
contain bugs. Use at your own risk. Please report any issues you
encounter as separate GitHub Issues.
### Version Information
- Dissent: $(version dissent)
- 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 }}