forked from actions-rs/clippy-check
-
Notifications
You must be signed in to change notification settings - Fork 3
301 lines (259 loc) · 8.85 KB
/
build.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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: write
checks: write
pull-requests: write
issues: write
packages: write
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref_name }}"
cancel-in-progress: true
jobs:
changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
code: ${{ steps.filter.outputs.code }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
show-progress: false
submodules: true
- name: Check if we actually made changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: .github/file-filters.yml
warm-up-cache:
name: Warm up the cache
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
- name: Set up node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
registry-url: https://npm.pkg.github.com
- name: Ensure latest version of npm, older versions like v8 have broken caching
shell: bash
run: |
npm install --location=global npm@latest
- name: Download dependencies
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm ci
npm-build:
name: Build the code
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
token: ${{ secrets.TOKEN_TO_TRIGGER_SUBSEQUENT_WORKFLOWS }}
show-progress: false
submodules: true
- name: Set up node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Run build
shell: bash
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
npm run build
- name: Compare the expected and actual dist/ directories
id: diff
env:
# for gh-cli
GH_TOKEN: ${{ secrets.TOKEN_TO_TRIGGER_SUBSEQUENT_WORKFLOWS }}
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
BRANCH="dist-updated-${PR_NUMBER}"
echo "Detected uncommitted changes after build. Checking in changes on branch: ${BRANCH}"
git checkout -b ${BRANCH}
echo "Please see the artifacts of this build for the changes"
git diff > diff.txt
echo "Creating commit with changes"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "Committing changes in dist/"
git add dist/
git commit --message "chore: commiting changes in dist/. See #${PR_NUMBER}"
# Remove GitHub's merging the tip of dist-updated branch into main's commit
# it's not needed as we require a branch to up-to-date with main
git rebase origin/main --autosquash
echo "Pushing branch"
git push --force --set-upstream origin HEAD
echo "Creating PR"
gh pr create --base main --head ${BRANCH} --title "chore(deps): rebuilding because files in dist have updated" --fill
exit 1
fi
# If dist/ was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: |
dist/
diff.txt
npm-lint:
name: Lint the code
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
show-progress: false
submodules: true
- name: Set up node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Run lint
shell: bash
run: |
npm run lint -- --format=json --output-file reports/lint-report.json || true
# hack to print results in the console
node --print "require('./node_modules/eslint/lib/cli-engine/formatters/stylish.js')(require('./reports/lint-report.json'))"
- name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@d57a1193d4c59cbfbf3f86c271f42612f9dbd9e9 # 3.0.0
with:
fail-on-error: true
fail-on-warning: true
markdown-report-on-step-summary: true
only-pr-files: false
report-json: reports/lint-report.json
npm-test:
name: Test the code
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
show-progress: false
submodules: true
fetch-depth: 0
- name: Set up node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Run tests
shell: bash
id: tests
run: |
npm run test -- --reporter=basic --reporter=github-actions --reporter=junit --coverage.reporter=text --coverage.reporter=lcovonly
continue-on-error: true
- name: Upload coverage results (to Codecov.io)
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
with:
disable_search: true
fail_ci_if_error: true
files: coverage/lcov.info
plugins: ""
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
uses: codecov/test-results-action@9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820 # v1.0.1
with:
disable_search: true
fail_ci_if_error: true
files: reports/test-report.xml
token: ${{ secrets.CODECOV_TOKEN }}
- name: Fail if tests failed
shell: bash
if: steps.tests.outcome != 'success'
run: |
echo "Tests failed"
exit 1
npm-dependencies:
name: Validate dependencies
runs-on: ubuntu-latest
needs:
- warm-up-cache
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
show-progress: false
- name: Set up node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Download dependencies from cache
shell: bash
run: |
npm ci --offline
- name: Check dependencies
shell: bash
run: |
npm run deps:ci
all-done:
name: All done
# this is the job that should be marked as required on GitHub. It's the only one that'll reliably trigger
# when any upstream fails: success
# when all upstream skips: pass
# when all upstream success: success
# combination of upstream skip and success: success
runs-on: ubuntu-latest
needs:
- npm-build
- npm-dependencies
- npm-lint
- npm-test
if: ${{ always() }}
steps:
- name: Fail!
shell: bash
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: |
echo "One / more upstream failed or was cancelled. Failing job..."
exit 1
- name: Success!
shell: bash
run: |
echo "Great success!"