-
Notifications
You must be signed in to change notification settings - Fork 4
332 lines (251 loc) · 8.79 KB
/
tests.yaml
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
name: Continuous testing
on:
# Runs on a push
push:
branches:
- main
# Runs on a pull request
pull_request:
branches:
- main
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
# Hosted GitHub runners have 7 GB of memory available, let's use 6 GB
NODE_OPTIONS: --max-old-space-size=6144
jobs:
check-changed-files:
name: Check changed files
runs-on: ubuntu-latest
outputs:
deploy_website: ${{ steps.changed-files.outputs.website_any_modified }}
trigger_algolia: ${{ steps.changed-files.outputs.website_contents_any_modified }}
run_tests: ${{ steps.changed-files.outputs.core_any_modified }}
pages_environment: ${{ env.PAGES_ENVIRONMENT }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changes core and website files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files_yaml: |
website:
- '.github/workflows/tests.yaml'
- 'website/**'
website_contents:
- 'website/contents/**'
core:
- '.github/workflows/build.yaml'
- '.github/workflows/build-and-test-target.yaml'
- '.github/workflows/tests.yaml'
- 'Cargo.lock'
- 'Cargo.toml'
- 'build.rs'
- 'templates/**'
- 'src/**'
- 'tests/**'
- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.website_all_modified_files }}; do
echo "website: $file was modified"
done
for file in ${{ steps.changed-files.outputs.core_all_modified_files }}; do
echo "core: $file was modified"
done
- name: Set the pages environment
if: github.event_name != 'pull_request'
run: |
echo "PAGES_ENVIRONMENT=github-pages" | tee -a "$GITHUB_ENV"
prepare-release-version:
name: Prepare build version
runs-on: ubuntu-latest
needs:
- check-changed-files
if: needs.check-changed-files.outputs.run_tests == 'true'
outputs:
release_version: ${{ env.RELEASE_VERSION }}
steps:
- name: Checkout commit
uses: actions/checkout@v4
- name: Get release version
run: |
git fetch --append --tags --unshallow --force
RELEASE_VERSION=$(git describe --tags --broken --dirty --match v* 2>/dev/null || true)
[ -z "$RELEASE_VERSION" ] && \
RELEASE_VERSION=0.0.0-g$(git describe --tags --always --broken --dirty --match v*)
RELEASE_VERSION=${RELEASE_VERSION##v}
echo "RELEASE_VERSION=${RELEASE_VERSION}" | tee -a "$GITHUB_ENV"
build-and-test-binaries:
name: Build and test binaries
needs:
- prepare-release-version
uses: ./.github/workflows/build.yaml
with:
git_sha: ${{ github.sha }}
release_version: ${{ needs.prepare-release-version.outputs.release_version }}
sign: false
rust-clippy-analysis:
name: Run rust-clippy analysis
runs-on: ubuntu-latest
needs:
- prepare-release-version
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout commit
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
shared-key: clippy
- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt
- name: Run clippy
id: clippy
run: |
cargo clippy --all-features --message-format=json | \
clippy-sarif | \
tee rust-clippy-results.sarif | \
sarif-fmt
continue-on-error: true
- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
- name: Fail if clippy failed
run: |
# Fail if the SARIF file is empty
if [ ! -s rust-clippy-results.sarif ]; then
exit 1
fi
# Count the number of warnings and errors
results=$(jq \
'.runs[]
| select(.tool.driver.name == "clippy")
| .results
| length' \
rust-clippy-results.sarif)
# Fail if there are any warnings or errors
if [[ "$results" != "0" ]]; then
echo >&2 "Clippy found $results warnings or errors"
exit 1
fi
rust-machete:
name: Check for unused dependencies
runs-on: ubuntu-latest
needs:
- prepare-release-version
steps:
- name: Checkout commit
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
shared-key: machete
- name: Install required cargo
run: cargo install cargo-machete
- name: Run machete
run: cargo machete --with-metadata
deploy-website:
name: Deploy static content
runs-on: ubuntu-latest
environment:
name: ${{ needs.check-changed-files.outputs.pages_environment }}
url: ${{ steps.deployment.outputs.page_url }}
needs:
- check-changed-files
if: needs.check-changed-files.outputs.deploy_website == 'true'
steps:
- name: Checkout current commit
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '>=18.0 <20.6.0 || >=20.6.1'
cache: yarn
cache-dependency-path: 'website/yarn.lock'
- name: Install dependencies
working-directory: website
run: yarn install --frozen-lockfile --non-interactive
- name: Build
working-directory: website
run: yarn build
- name: Setup Pages
if: github.event_name != 'pull_request'
uses: actions/configure-pages@v5
- name: Upload artifact
if: github.event_name != 'pull_request'
uses: actions/upload-pages-artifact@v3
with:
path: website/build
- name: Deploy to GitHub Pages
if: github.event_name != 'pull_request'
id: deployment
uses: actions/deploy-pages@v4
- name: Trigger Algolia crawler
if: github.event_name != 'pull_request' && needs.check-changed-files.outputs.trigger_algolia == 'true'
uses: algolia/[email protected]
with:
crawler-name: omnicli
crawler-user-id: ${{ secrets.ALGOLIA_CRAWLER_USER_ID }}
crawler-api-key: ${{ secrets.ALGOLIA_CRAWLER_API_KEY }}
algolia-app-id: ${{ secrets.ALGOLIA_APP_ID }}
algolia-api-key: ${{ secrets.ALGOLIA_API_KEY }}
site-url: ${{ steps.deployment.outputs.page_url }}
override-config: false
check-results:
name: Check tests results
runs-on: ubuntu-latest
needs:
- build-and-test-binaries
- rust-machete
- rust-clippy-analysis
- deploy-website
if: '!cancelled()'
steps:
- name: Fail if tests failed
if: needs.build-and-test-binaries.result == 'failure' || needs.build-and-test-binaries.result == 'cancelled'
run: exit 1
- name: Fail if CodeQL failed
if: needs.rust-clippy-analysis.result == 'failure' || needs.rust-clippy-analysis.result == 'cancelled' || needs.rust-machete.conclusion == 'failure' || needs.rust-machete.conclusion == 'cancelled'
run: exit 1
- name: Fail if website building/deployment failed
if: needs.deploy-website.result == 'failure' || needs.deploy-website.result == 'cancelled'
run: exit 1
auto-merge:
name: Auto-merge Dependabot pull-requests
runs-on: ubuntu-latest
needs:
- check-results
if: always() && github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' && needs.check-results.result == 'success'
permissions:
contents: none
steps:
- name: Checkout current commit
uses: actions/checkout@v4
- name: Enable auto-merge if Dependabot
env:
GH_TOKEN: ${{ secrets.AUTOMERGE_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh pr merge --squash --auto --body "" "$PR_NUMBER"