This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
303 lines (286 loc) · 9.25 KB
/
ci.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
name: CI
on:
pull_request:
push:
branches:
- "staging"
- "master"
env:
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dprint/check@v2.1
# job to run change detection
changes:
runs-on: ubuntu-latest
# Set job outputs to values from filter step
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
electron: ${{ steps.filter.outputs.electron }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: filter
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: |
backend:
- 'crates/**'
- 'Cargo.toml'
- 'Cargo.lock'
frontend:
- 'taker-frontend/**'
- 'maker-frontend/**'
electron:
- 'crates/taker-electron/**'
gather_workspace_members:
runs-on: ubuntu-latest
outputs:
members: ${{ steps.cargo-metadata.outputs.members }}
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
run: rustup show
- id: cargo-metadata
run: |
# replacing itchysats with taker-electron: dirty fix, as neon and electron require the package name for processing. neon requires the package name to equal the crate name -
# and electron uses the package name as name of the application.
WORKSPACE_MEMBERS=$(cargo metadata --format-version=1 --no-deps | jq -c '.packages |.[] | select(.name == "itchysats").name |= "taker-electron" | .name' | jq -s | jq -c '.')
echo "::set-output name=members::${WORKSPACE_MEMBERS}"
clippy:
needs: [gather_workspace_members, changes]
if: ${{ needs.changes.outputs.backend == 'true' }}
strategy:
matrix:
crate: ${{ fromJson(needs.gather_workspace_members.outputs.members) }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: crates/${{ matrix.crate }}
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2.0.1
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: cargo clippy --all-targets -- -D warnings
lint-commits:
runs-on: ubuntu-latest
if: github.event.ref != 'refs/heads/master'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get all commits on current master
run: git fetch origin master
- name: Log all commits we will analyze
run: git log --pretty=format:%s origin/master..HEAD
- name: Disallow fixup! commits
run: git log --pretty=format:%s origin/master..HEAD | grep -zv fixup!
- name: Disallow squash! commits
run: git log --pretty=format:%s origin/master..HEAD | grep -zv squash!
frontend:
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' }}
strategy:
matrix:
bin: [maker, taker]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ matrix.bin }}-frontend
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: "yarn"
cache-dependency-path: ${{ matrix.bin }}-frontend/yarn.lock
- run: yarn install
- run: yarn run eslint
- run: yarn run tsc
- run: yarn run test
- run: yarn run build
electron:
needs: changes
if: ${{ needs.changes.outputs.electron == 'true' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: crates/taker-electron
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: "yarn"
cache-dependency-path: crates/taker-electron/yarn.lock
- name: Install Protoc
uses: arduino/setup-protoc@v1
- run: yarn install
- run: yarn run eslint
- run: yarn run tsc
- run: yarn run build:rust
- run: yarn run build:main
- run: yarn run build:renderer
# Builds and archives the test so that they can be run later in multiple jobs
build-tests:
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' }}
strategy:
matrix:
os: [ubuntu-latest, macos-12]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2.0.1
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Build and archive tests
run: cargo nextest archive --archive-file nextest-archive.tar.zst
- name: Upload archive to workflow
uses: actions/upload-artifact@v3
with:
name: nextest-archive-${{ matrix.os }}
path: nextest-archive.tar.zst
# Run partitioned tests
# In order to change the number of jobs, amend `partition` array and `--partition count` argument
run-tests:
strategy:
matrix:
partition: [1, 2, 3, 4]
os: [ubuntu-latest, macos-12]
needs: [build-tests, changes]
if: ${{ needs.changes.outputs.backend == 'true' }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
# In this example, the Rust toolchain is not installed. cargo nextest's run phase does not
# require Cargo. You can choose to install Rust if your tests require it, of course.
# Instead, create ~/.cargo/bin as required by the install action.
- run: mkdir -p ~/.cargo/bin
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Download archive
uses: actions/download-artifact@v3
with:
name: nextest-archive-${{ matrix.os }}
- name: Run tests
run: |
~/.cargo/bin/cargo-nextest nextest run --archive-file nextest-archive.tar.zst \
--profile ci \
--partition count:${{ matrix.partition }}/4
smoke_test:
needs: changes
if: ${{ (needs.changes.outputs.backend || needs.changes.outputs.frontend) == 'true' }}
strategy:
matrix:
os: [ubuntu-latest, macos-12]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2.0.1
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: cargo build --bin maker --bin taker
- name: Smoke testing maker for ${{ matrix.os }} binary
shell: bash
run: |
cargo dev-maker-headless &
n=0
until [ "$n" -ge 3 ]
do
n=$((n+1))
sleep 10
curl --fail http://localhost:8001/api/alive && break;
done
- name: Smoke testing taker for ${{ matrix.os }} binary
shell: bash
run: |
cargo dev-taker-headless &
n=0
until [ "$n" -ge 3 ]
do
n=$((n+1))
sleep 10
curl --fail http://localhost:8000/api/alive && break;
done
daemons_arm_build:
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' }}
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2.0.1
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install compiler for aarch64 arch
run: |
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install g++-aarch64-linux-gnu
- run: cargo build --target=aarch64-unknown-linux-gnu --bins
sqlx-db-check:
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' }}
steps:
- uses: actions/checkout@v3
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2.0.1
- name: Install sqlx-cli
# Lock sqlx-cli version to the same version as sqlx in the workspace
run: |
cargo install sqlx-cli@0.6.2
- name: Run sqlx prepare
run: |
cd crates/sqlite-db
./prepare_db.sh
git diff --exit-code sqlx-data.json
- name: sqlx prepare was not run
if: failure()
run: |
echo "sqlx prepare was not run or sqlx-data.json was not checked-in"
# We need some "accummulation" job here because bors fails (timeouts) to
# listen on matrix builds. Bors will only listen on this job.
ci-success:
name: CI
needs:
- changes
- gather_workspace_members
- formatting
- lint-commits
- build-tests
- run-tests
- sqlx-db-check
- frontend
- electron
- smoke_test
- daemons_arm_build
- clippy
runs-on: ubuntu-latest
if: ${{ always() && contains(needs.*.result, 'success') && !(contains(needs.*.result, 'failure')) }}
steps:
- name: CI succeeded
run: exit 0