-
Notifications
You must be signed in to change notification settings - Fork 8
280 lines (234 loc) · 7.57 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
name: Main
on:
push:
pull_request:
branches:
- main
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:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Build
run: >
cargo build
--locked
--verbose
- name: Run tests (without coverage)
run: >
cargo test
--verbose
build-test-coverage:
name: Build and test with coverage
runs-on: ubuntu-latest
# Currently broken... linking with `cc`/`ld` fails, no idea...
if: false
steps:
- uses: actions/checkout@v4
- 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)
# `--all-targets` does not include `--doc`
run: >
cargo tarpaulin
--out xml
--engine llvm
--all-targets
--doc
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
release-please:
name: Execute release chores
runs-on: ubuntu-latest
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 }}
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: google-github-actions/release-please-action@v3
id: release
with:
# Token needs: `contents: write`, `pull-requests: write`
token: ${{ steps.app-token.outputs.token }}
release-type: rust
- uses: actions/checkout@v4
- name: Mark release as draft
# To prevent race conditions where release is created, but no binaries are
# attached yet.
if: steps.release.outputs.release_created
env:
# `secrets.GITHUB_TOKEN` would work here (with appropriate `permissions`),
# but just reuse what we already have.
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: >
gh release edit
${{ steps.release.outputs.tag_name }}
--draft=true
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
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 }}-${{ needs.release-please.outputs.tag_name }}.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:
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
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 }}" ]]