-
Notifications
You must be signed in to change notification settings - Fork 8
434 lines (365 loc) · 12.1 KB
/
main.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
name: Main
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
env:
CARGO_TERM_COLOR: always
jobs:
build-test:
name: Build and test (${{ matrix.os }})
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Set git to not perform line ending conversions
# Tests are very sensitive to line endings, so ensure they are exactly as found
# in the repo.
run: |
git config --global core.autocrlf false
- uses: actions/checkout@v4
- name: Check actual EOL on disk
run: |
git ls-files --eol
- uses: swatinem/rust-cache@v2
- name: Build
run: >
cargo build
--locked
--verbose
- name: Run tests (without coverage)
run: >
cargo test
--verbose
check-clippy-and-format:
name: Check clippy and format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Set up nightly toolchain
# Cannot be `minimal` profile, need `rustfmt` and `clippy`:
# https://rust-lang.github.io/rustup/concepts/profiles.html#profiles
run: >
rustup toolchain install nightly
&& rustup component add --toolchain nightly rustfmt
- name: Print versions
run: >
rustc --version
&& cargo --version
&& cargo +nightly fmt --version
&& cargo clippy --version
- name: Check formatting
run: >
cargo +nightly fmt
--all
-- --check
- name: Check clippy
run: >
cargo clippy
--workspace
--all-targets
--all-features
-- --deny warnings
check-dependency-changes:
name: Check for changes in `Cargo.toml` and `Cargo.lock`
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: base
- run: cargo tree | tee tree
working-directory: base
- uses: actions/checkout@v4
with:
path: head
- run: cargo tree | tee tree
working-directory: head
- name: Check for changes in dependencies
run: diff base/tree head/tree || true
verify-msrv:
# Set in `Cargo.toml` manually by running `cargo msrv` locally. Then verified for
# its consistency here.
name: Verify MSRV (Minimum Supported Rust Version)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- uses: cargo-bins/cargo-binstall@main
- name: Install `cargo-msrv` binary
# TODO: move out of beta & back to `taiki-e/install-action` (which we cannot use
# because it doesn't support release-candidate version notation) once properly
# released. See also https://github.com/foresterre/cargo-msrv/issues/1007
run: >
cargo binstall
--no-confirm
cargo-msrv
--version 0.16.0-beta.25
--force
- run: cargo msrv verify
bench-files:
name: Run benchmarks for `--glob` option
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: hyperfine
- name: Run benchmarks
run: >
./benches/bench-files.sh
build-test-feature-powerset:
name: Build and test feature powerset
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- name: Run tests
run: >
cargo hack
--feature-powerset
test
build-test-coverage:
name: Build and test with coverage
# Fails catastrophically on `ubuntu-latest`, as linking fails if compiling while
# using `insta`. macOS works (locally as well) and is the fastest runner anyway, so
# just use that. See also https://github.com/xd009642/tarpaulin/issues/517
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Install cargo-tarpaulin (for coverage)
# As recommened by `cargo-binstall` team:
# https://github.com/cargo-bins/cargo-binstall/tree/d5549ce99ebc82b1ceee93a41375137b7dbd1a1f#faq
uses: taiki-e/install-action@v2
with:
tool: cargo-tarpaulin
- name: Install (minimal) nightly toolchain
run: rustup toolchain install --profile minimal nightly
- name: Run tests (with coverage)
# Will read from `tarpaulin.toml`. Extra flags given here complement the config.
run: >
cargo tarpaulin
--verbose
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
verbose: true
token: ${{ secrets.CODECOV_UPLOAD_TOKEN }}
release-please:
name: Execute release chores
runs-on: ubuntu-latest
# Only run this on push events: `pull_request` events will not have access to
# secrets if coming from forks, and we do not care about release chores there
# anyway.
if: github.event_name == 'push'
outputs:
created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
tag_name_without_v: ${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
html_url: ${{ steps.release.outputs.html_url }}
steps:
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: googleapis/release-please-action@v4
id: release
with:
# Token needs: `contents: write`, `pull-requests: write`
token: ${{ steps.app-token.outputs.token }}
build-upload:
name: Build and upload binaries
needs: release-please
# Assumption: if release created, tests ran in corresponding PR, so it's safe to not
# `needs` tests here.
if: needs.release-please.outputs.created
environment:
name: binaries
url: ${{ needs.release-please.outputs.html_url }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
crate: srgn
binary: srgn
extension: ""
- os: macos-latest
target: x86_64-apple-darwin
crate: srgn
binary: srgn
extension: ""
- os: macos-latest
target: aarch64-apple-darwin
crate: srgn
binary: srgn
extension: ""
- os: windows-latest
target: x86_64-pc-windows-msvc
crate: srgn
binary: srgn
extension: ".exe"
runs-on: ${{ matrix.os }}
env:
ASSET_FILE: "${{ matrix.crate }}-${{ matrix.target }}.tgz"
permissions:
contents: write # For `gh` to upload asset to release
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Add rustup target
# Idempotent, so just succeeds if already added.
run: rustup target add ${{ matrix.target }}
- name: Build
shell: bash
run: >
cargo build
--release
--locked
--verbose
--target ${{ matrix.target }}
--bin ${{ matrix.binary }}
- name: Package binary (for cargo-binstall)
shell: bash
env:
DIR: ${{ matrix.crate }}
run: >
mkdir "$DIR"
&& mv
"target/${{ matrix.target }}/release/${{ matrix.binary }}${{ matrix.extension }}"
"$DIR"
&& tar
--create
--verbose
--gzip
--file "$ASSET_FILE"
"$DIR"
- name: Attach binary to release
shell: bash
env:
# `gh` blows up without token, cf.
# https://josh-ops.com/posts/gh-auth-login-in-actions/#example-2---env-variable
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
gh release upload
${{ needs.release-please.outputs.tag_name }}
"$ASSET_FILE"
publish-dry-run:
# Perform a dry run to see whether publishing *would* work. A convenience to avoid
# the actual publish step failing, which is super annoying as it's gated behind git
# tags etc. which we cannot just re-run.
name: Publish to crates.io - dry run
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Publish
run: >
cargo publish
--verbose
--locked
--dry-run
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs:
- release-please
# Assumption: if release created, tests ran in corresponding PR, so it's safe to not
# `needs` tests here.
if: needs.release-please.outputs.created
environment:
name: crates.io
url: https://crates.io/crates/srgn/${{ needs.release-please.outputs.tag_name_without_v }}
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Publish
# https://doc.rust-lang.org/cargo/reference/config.html?highlight=CARGO_REGISTRY_TOKEN#credentials
run: >
cargo publish
--verbose
--locked
--no-verify
--token ${{ secrets.CARGO_REGISTRY_TOKEN }}
release-draft:
name: Turn release draft into full release
runs-on: ubuntu-latest
needs:
- release-please
- build-upload
if: needs.release-please.outputs.created
permissions:
contents: write # For `gh` to edit release
steps:
- uses: actions/checkout@v4
- name: Remove draft status from release
# Now that everything is done, fully release.
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
gh release edit
${{ needs.release-please.outputs.tag_name }}
--draft=false
test-binstall-installation:
name: Test installation and running via cargo-binstall
strategy:
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
needs:
- release-please
- release-draft
- publish
runs-on: ${{ matrix.os }}
steps:
- uses: cargo-bins/cargo-binstall@main
- name: Install binary
# Get the current version that was just released, and fail if no binaries are
# directly available (don't allow fallback to compilation from source).
run: >
cargo binstall
--version ${{ needs.release-please.outputs.tag_name_without_v }}
--strategies crate-meta-data
--no-confirm
srgn
- name: Print version
run: srgn --version
- name: Print help
run: srgn --help
- name: Test version matches release
shell: bash
run: >
[[ $(srgn --version) == "srgn ${{ needs.release-please.outputs.tag_name_without_v }}" ]]
- uses: actions/checkout@v4
- name: Perform dummy run (full verbosity)
# A final sanity check. Can be used to check things which are super annoying to
# test, e.g. terminal color output (which should work in GitHub Actions).
# Because it's hard to test, this isn't asserted against anything. Just a nice
# final check. Requires overriding stdin as that is unfortunately detected as
# present in GitHub Actions. Should not be necessary in normal CLI use.
run: srgn -vvvv --stdin-override-to false --rust struct
- name: Perform dummy run (minimal verbosity)
run: srgn --stdin-override-to false --rust struct