-
Notifications
You must be signed in to change notification settings - Fork 6
330 lines (314 loc) · 9.72 KB
/
build-test-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
---
name: Build+Test+Publish
on:
push:
branches: [main]
tags: '*'
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings
jobs:
setup-build-matrix:
name: Setup build matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{steps.set-matrix.outputs.matrix}}
steps:
- id: set-matrix
name: Generate build matrix
shell: python
# env:
# ENABLE_PRODUCTION: ${{startsWith(github.ref, 'refs/tags/')}}
run: |
import json
import os
matrix = {
'os': [
{
'name': 'linux',
'edition': 'ubuntu-22.04',
'execext': '',
'pkgext': '.tar.bz2',
'pkgcmd': ('tar -c -f '
'$PKG.tar.bz2 '
'$PKG'),
},
{
'name': 'windows',
'edition': 'windows-2022',
'execext': '.exe',
'pkgext': '.zip',
'pkgcmd': ('7z a '
'$PKG.zip '
'$PKG'),
},
{
'name': 'macos',
'edition': 'macos-14',
'execext': '',
'pkgext': '.dmg',
'pkgcmd': ('hdiutil create -format UDZO -srcfolder '
'$PKG '
'$PKG.dmg'),
},
],
'build-config': [
{
'id': 'debug',
'args': '',
},
{
'id': 'release',
'args': '--release',
},
]
}
matrix_json = json.dumps(matrix)
env_file = os.getenv('GITHUB_OUTPUT')
if env_file is not None:
with open(env_file, 'a', encoding='utf8') as out:
print(f'matrix={matrix_json}', file=out)
code-formatting:
name: Code formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: Code formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: >-
--all -- --check -l
lint:
name: >-
Lint:
${{matrix.os.edition}},
${{matrix.build-config.id}}
needs: setup-build-matrix
strategy:
matrix: ${{fromJSON(needs.setup-build-matrix.outputs.matrix)}}
runs-on: ${{matrix.os.edition}}
steps:
- uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
target
~/.cargo
~/.rustup
key: >-
lint-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-${{hashFiles('Cargo.lock')}}
restore-keys: |
lint-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-
lint-deps-${{matrix.os.name}}-
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- name: Lint
uses: actions-rs/cargo@v1
with:
command: clippy
args: >-
--all-targets --all-features
${{matrix.build-config.args}}
documentation:
name: >-
Doc:
${{matrix.os.edition}},
${{matrix.build-config.id}}
needs: setup-build-matrix
strategy:
matrix: ${{fromJSON(needs.setup-build-matrix.outputs.matrix)}}
runs-on: ${{matrix.os.edition}}
steps:
- uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
target
~/.cargo
~/.rustup
key: >-
doc-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-${{hashFiles('Cargo.lock')}}
restore-keys: |
doc-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-
doc-deps-${{matrix.os.name}}-
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Doc
uses: actions-rs/cargo@v1
env:
RUSTDOCFLAGS: -Dwarnings
with:
command: doc
args: >-
--all-features --no-deps --document-private-items
${{matrix.build-config.args}}
build-and-test:
name: >-
Build+Test:
${{matrix.os.edition}},
${{matrix.build-config.id}}
needs: setup-build-matrix
strategy:
matrix: ${{fromJSON(needs.setup-build-matrix.outputs.matrix)}}
runs-on: ${{matrix.os.edition}}
steps:
- uses: actions/checkout@v3
- uses: dawidd6/action-get-tag@v1
if: ${{startsWith(github.ref, 'refs/tags/')}}
id: tag
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
target
~/.cargo
~/.rustup
key: >-
build-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-${{hashFiles('Cargo.lock')}}
restore-keys: |
build-deps-${{matrix.os.name}}-${{matrix.build-config.id}}-
build-deps-${{matrix.os.name}}-
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: >-
--all-features --all-targets
${{matrix.build-config.args}}
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: >-
--all-features --all-targets
${{matrix.build-config.args}}
- name: Create tarball
if: >-
${{matrix.build-config.id == 'release' &&
startsWith(github.ref, 'refs/tags/')}}
shell: bash
run: |
export PKG=tvrank-${{steps.tag.outputs.tag}}-${{matrix.os.name}}
mkdir $PKG
cp target/release/tvrank $PKG/tvrank${{matrix.os.execext}}
cp LICENSE $PKG/LICENSE
cp README.md $PKG/README.md
cp -r changelogs $PKG/changelogs
${{matrix.os.pkgcmd}}
- name: Upload tarball
if: >-
${{matrix.build-config.id == 'release' &&
startsWith(github.ref, 'refs/tags/')}}
uses: actions/upload-artifact@v4
with:
name: >-
tvrank-${{steps.tag.outputs.tag}}-${{matrix.os.name}}${{matrix.os.pkgext}}
path: >-
tvrank-${{steps.tag.outputs.tag}}-${{matrix.os.name}}${{matrix.os.pkgext}}
publish-github:
name: Publish to Github
needs:
- code-formatting
- lint
- documentation
- build-and-test
if: ${{startsWith(github.ref, 'refs/tags/')}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dawidd6/action-get-tag@v1
id: tag
- name: Download Linux tarball
uses: actions/download-artifact@v4
with:
name: tvrank-${{steps.tag.outputs.tag}}-linux.tar.bz2
- name: Download MacOS tarball
uses: actions/download-artifact@v4
with:
name: tvrank-${{steps.tag.outputs.tag}}-macos.dmg
- name: Download Windows tarball
uses: actions/download-artifact@v4
with:
name: tvrank-${{steps.tag.outputs.tag}}-windows.zip
- name: Create Release on Github
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
tag_name: ${{steps.tag.outputs.tag}}
release_name: tvrank-${{steps.tag.outputs.tag}}
body_path: changelogs/${{steps.tag.outputs.tag}}.md
- name: Upload Linux tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{steps.create-release.outputs.upload_url}}
asset_path: tvrank-${{steps.tag.outputs.tag}}-linux.tar.bz2
asset_name: tvrank-${{steps.tag.outputs.tag}}-linux.tar.bz2
asset_content_type: application/x-bzip2
- name: Upload MacOS tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{steps.create-release.outputs.upload_url}}
asset_path: tvrank-${{steps.tag.outputs.tag}}-macos.dmg
asset_name: tvrank-${{steps.tag.outputs.tag}}-macos.dmg
asset_content_type: application/x-apple-diskimage
- name: Upload Windows tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{steps.create-release.outputs.upload_url}}
asset_path: tvrank-${{steps.tag.outputs.tag}}-windows.zip
asset_name: tvrank-${{steps.tag.outputs.tag}}-windows.zip
asset_content_type: application/zip
publish-crates-io:
name: Publish to Crates.io
needs:
- code-formatting
- lint
- documentation
- build-and-test
if: ${{startsWith(github.ref, 'refs/tags/')}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Publish to Crates.io
env:
CRATES_IO_TOKEN: ${{secrets.CRATES_IO_TOKEN}}
run: |
cargo publish -p tvrank --token ${CRATES_IO_TOKEN}
sleep 5 # Gives crates.io time to update itself or whatever
cargo publish -p tvrank-cli --token ${CRATES_IO_TOKEN}
...