-
Notifications
You must be signed in to change notification settings - Fork 0
322 lines (272 loc) · 7.48 KB
/
rust.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
name: Rust CI
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
jobs:
# Check and lint source code
check:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy
- name: Install cargo-deb
uses: actions-rs/[email protected]
with:
crate: cargo-deb
version: latest
- name: Install cargo-sweep
uses: actions-rs/[email protected]
with:
crate: cargo-sweep
version: latest
- name: Restore core cache
uses: actions/cache/restore@v3
with:
key: core
path: |
~/.cargo/registry
~/.cargo/git
target
- name: Track target/ cache files for cleanup
uses: actions-rs/cargo@v1
with:
command: sweep
args: --stamp
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
- name: Clean up target cache
uses: actions-rs/cargo@v1
with:
command: sweep
args: --file
- name: Update core cache for builds on main
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/cache/save@v3
with:
key: core-${{ github.run_id }}
path: |
~/.cargo/registry
~/.cargo/git
target
# Pre-build test assets
build-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Install cargo-sweep
uses: actions-rs/[email protected]
with:
crate: cargo-sweep
version: latest
- name: Restore cache
uses: actions/cache/restore@v3
with:
key: test
path: |
~/.cargo/registry
~/.cargo/git
target
- name: Track target/ cache files for cleanup
uses: actions-rs/cargo@v1
with:
command: sweep
args: --stamp
- name: Pre-build tests
uses: actions-rs/cargo@v1
with:
command: build
args: --tests
- name: Clean up target cache
uses: actions-rs/cargo@v1
with:
command: sweep
args: --file
- name: Update cache for builds on main
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/cache/save@v3
with:
key: test-${{ github.run_id }}
path: |
~/.cargo/registry
~/.cargo/git
target
# Run per-package tests
test:
runs-on: ubuntu-latest
needs: [ "build-tests" ]
continue-on-error: true
strategy:
fail-fast: false
matrix:
package: [ core, rpc, client, engine, daemon ]
steps:
- uses: actions/checkout@v3
- name: Setup toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Restore cache
uses: actions/cache/restore@v3
with:
key: test
path: |
~/.cargo/registry
~/.cargo/git
target
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: -p dsf-${{ matrix.package }}
# Build release binaries
build:
runs-on: ${{ matrix.os }}
needs: [ "check" ]
permissions:
packages: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
use_cross: true
docker: amd64
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
use_cross: true
docker: armv7
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
use_cross: true
docker: arm64
- target: x86_64-apple-darwin
os: macos-latest
steps:
- uses: actions/checkout@v3
- uses: FranzDiebold/github-env-vars-action@v2
- name: Configure toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: ${{ matrix.target }}
override: true
- name: Set up Docker Buildx
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: docker/setup-buildx-action@v3
- name: Install cargo-sweep
uses: actions-rs/[email protected]
with:
crate: cargo-sweep
version: latest
- name: Install cargo-deb
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions-rs/[email protected]
with:
crate: cargo-deb
version: latest
- name: Restore target cache
uses: actions/cache/restore@v3
with:
key: build-${{ matrix.target }}
path: |
~/.cargo/registry
~/.cargo/git
target
- name: Track target/ cache files for cleanup
uses: actions-rs/cargo@v1
with:
command: sweep
args: --stamp
- name: Set cross compilation flag if required
if: ${{ matrix.use_cross }}
run: |
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
- name: Build release
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.use_cross }}
command: build
args: --release --target ${{ matrix.target }}
- name: Clean up target cache
uses: actions-rs/cargo@v1
with:
command: sweep
args: --file
- name: Update target cache
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/cache/save@v3
with:
key: build-${{ matrix.target }}-${{ github.run_id }}
path: |
~/.cargo/registry
~/.cargo/git
target
- name: Create .tgz archive
run: |
tar -cvf target/dsf-${{ matrix.target }}.tgz -C target/${{ matrix.target }}/release/ dsfd dsfc
- name: Create .deb archive for ubuntu/debian targets
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
cd ${{ github.workspace }}/daemon && cargo deb --no-build --no-strip --target ${{ matrix.target }}
cd ${{ github.workspace }}/client && cargo deb --no-build --no-strip --target ${{ matrix.target }}
- name: Login to GHCR (for publishing)
if: ${{ matrix.docker != '' }}
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create docker image if enabled
if: ${{ matrix.docker != '' }}
run: |
docker buildx bake ${{ matrix.docker }} --push
docker push ghcr.io/dist-svc/dsf:${{ matrix.docker }}
- name: Store CI artifacts
uses: actions/upload-artifact@v2
with:
name: dsfd-${{ matrix.target }}
path: |
target/*.tgz
target/debian/*.deb
# Update package manifests
publish:
runs-on: ubuntu-latest
needs: [ "build", "test" ]
permissions:
packages: write
steps:
- uses: actions/checkout@v3
- uses: FranzDiebold/github-env-vars-action@v2
- name: Login to GHCR (for publishing)
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Update docker manifest
run: |
make docker-pull
make docker-publish
make docker-inspect