-
Notifications
You must be signed in to change notification settings - Fork 40
325 lines (293 loc) · 11.4 KB
/
pr.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
name: Pull Request
on: [pull_request, workflow_dispatch]
permissions:
actions: write
checks: write
contents: read
deployments: read
id-token: write
issues: write
discussions: read
packages: read
pages: read
pull-requests: write
repository-projects: read
security-events: read
statuses: write
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
detect_changes:
name: Detect changed files
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
linters: ${{ steps.filter.outputs.linters }}
repo-tests: ${{ steps.filter.outputs.repo-tests }}
# "linters" if ${{ steps.filter.outputs.all-linters }} is 'true'
all-linters: ${{ steps.post-filter.outputs.out }}
# shortened paths to linter subdirs
linters-files: ${{ steps.post-filter-paths.outputs.out }}
tools: ${{ steps.filter.outputs.tools }}
all-tools: ${{ steps.post-filter-tools.outputs.out }}
tools-files: ${{ steps.post-filter-tools-paths.outputs.out }}
actions: ${{ steps.filter.outputs.actions }}
all-actions: ${{ steps.post-filter-actions.outputs.out }}
actions-files: ${{ steps.post-filter-actions-paths.outputs.out }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Determine upstream
run: |
head_sha=$(git rev-parse HEAD)
git -c protocol.version=2 fetch -q \
--no-tags \
--no-recurse-submodules \
--depth=2 \
origin "${head_sha}"
upstream=$(git rev-parse HEAD^1)
echo "TEST_UPSTREAM=${upstream}" >>"${GITHUB_ENV}"
- name: Detect changed paths
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
base: ${{ env.TEST_UPSTREAM }}
filters: .github/filters.yaml
list-files: shell
- name: Suggest all linter tests
id: post-filter
if: steps.filter.outputs.all-linters == 'true'
run: |
echo "Run all linter tests"
echo "out=linters/" >> "$GITHUB_OUTPUT"
- name: Suggest all tool tests
id: post-filter-tools
if: steps.filter.outputs.all-tools == 'true'
run: |
echo "Run all tool tests"
echo "out=tools/" >> "$GITHUB_OUTPUT"
- name: Suggest all action tests
id: post-filter-actions
if: steps.filter.outputs.all-actions == 'true'
run: |
echo "Run all action tests"
echo "out=actions/" >> "$GITHUB_OUTPUT"
- name: Suggest normalized individual linter paths
id: post-filter-paths
if: steps.filter.outputs.linters
run: |
linter_files=$(echo ${{steps.filter.outputs.linters_files}} |
grep -oP "\Klinters/.*?(?=/)" |
uniq | tr '\n' ' ')
echo "Running tests on individual linters: ${linter_files}"
echo "out=${linter_files}" >> "$GITHUB_OUTPUT"
- name: Suggest normalized individual tool paths
id: post-filter-tools-paths
if: steps.filter.outputs.tools
run: |
tool_files=$(echo ${{steps.filter.outputs.tools_files}} |
grep -oP "\Ktools/.*?(?=/)" |
uniq | tr '\n' ' ')
echo "Running tests on individual tools: ${tool_files}"
echo "out=${tool_files}" >> "$GITHUB_OUTPUT"
- name: Suggest normalized individual action paths
id: post-filter-actions-paths
if: steps.filter.outputs.actions
run: |
action_files=$(echo ${{steps.filter.outputs.actions_files}} |
grep -oP "\Kactions/.*?(?=/)" |
uniq | tr '\n' ' ')
echo "Running tests on individual actions: ${action_files}"
echo "out=${action_files}" >> "$GITHUB_OUTPUT"
# Run tests against all linters for known_good_version and latest version
linter_tests:
name: Linter Tests ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: detect_changes
if:
needs.detect_changes.outputs.linters == 'true' || needs.detect_changes.outputs.all-linters ==
'linters/'
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS]
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
# TODO(Tyler): Remove this once the cache has stabilized
- name: Delete cache (mac only)
if: matrix.os == 'macOS'
# For now, avoid deleting cache on pull request changes to nightly. This improves PR experience.
run: |
if [ -d "${TMPDIR:-/tmp}/plugins_testing_download_cache" ]
then
tmp_dir=${TMPDIR:-/tmp}/${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT}
mv "${TMPDIR:-/tmp}/plugins_testing_download_cache" ${tmp_dir}
chmod -R u+w ${tmp_dir}
rm -rf ${tmp_dir}
fi
shell: bash
- name: Linter Tests
# Run tests using KnownGoodVersion with any modified linters and conditionally all linters
uses: ./.github/actions/linter_tests
with:
linter-version: KnownGoodVersion
ref-type: main
sourcery-token: ${{ secrets.TRUNK_SOURCERY_TOKEN }}
append-args:
${{ needs.detect_changes.outputs.all-linters }} ${{
needs.detect_changes.outputs.linters-files }}
trunk-staging-token: ${{ secrets.TRUNK_DEBUGGER_TOKEN }}
trunk-prod-token: ${{ secrets.TRUNK_ORG_PROD_TOKEN }}
- name: Linter Tests Latest
# Run tests on Latest with any modified linters (see filters.yaml). Don't run when cancelled.
if:
(failure() || success()) && needs.detect_changes.outputs.linters == 'true' &&
needs.detect_changes.outputs.linters-files != ''
uses: ./.github/actions/linter_tests
with:
linter-version: Latest
ref-type: main
sourcery-token: ${{ secrets.TRUNK_SOURCERY_TOKEN }}
append-args: ${{ needs.detect_changes.outputs.linters-files }}
trunk-staging-token: ${{ secrets.TRUNK_DEBUGGER_TOKEN }}
trunk-prod-token: ${{ secrets.TRUNK_ORG_PROD_TOKEN }}
tool_tests:
name: Tool Tests
runs-on: ${{ matrix.os }}
needs: detect_changes
if:
needs.detect_changes.outputs.tools == 'true' || needs.detect_changes.outputs.all-tools ==
'tools/'
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS]
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Tool Tests
# Run tests using KnownGoodVersion with any modified tools and conditionally all tools. Don't run when cancelled.
# TODO(Tyler): Wire up Latest tests and ReleaseVersionService
uses: ./.github/actions/tool_tests
with:
append-args:
${{ needs.detect_changes.outputs.all-tools }} ${{
needs.detect_changes.outputs.tools-files }}
trunk-staging-token: ${{ secrets.TRUNK_DEBUGGER_TOKEN }}
trunk-prod-token: ${{ secrets.TRUNK_ORG_PROD_TOKEN }}
action_tests:
name: Action Tests
runs-on: ubuntu-latest
needs: detect_changes
if:
needs.detect_changes.outputs.actions == 'true' || needs.detect_changes.outputs.all-actions ==
'actions/'
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Action Tests
uses: ./.github/actions/action_tests
with:
append-args:
${{ needs.detect_changes.outputs.all-actions }} ${{
needs.detect_changes.outputs.actions-files }} --
trunk-staging-token: ${{ secrets.TRUNK_DEBUGGER_TOKEN }}
trunk-prod-token: ${{ secrets.TRUNK_ORG_PROD_TOKEN }}
trunk_check_runner:
name: Trunk Check runner [linux]
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
checks: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
- name: Trunk Check
uses: trunk-io/trunk-action@4d5ecc89b2691705fd08c747c78652d2fc806a94
env:
TRUNK_GITHUB_CHECK_RUN_TITLE: Trunk Check
# Run Windows tests for modified linters and tools
# TODO(Tyler): When this is more stabilized and we want to gate on it, we can make it part of the matrix above.
windows_linter_tests:
name: Windows Linter Tests
runs-on: windows-latest
needs: detect_changes
if: needs.detect_changes.outputs.linters == 'true'
timeout-minutes: 90
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Cache tool downloads
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: /tmp/plugins_testing_download_cache
key: trunk-${{ runner.os }}
- name: Linter Tests
# Run tests using Latest with any modified linters
uses: ./.github/actions/linter_tests
with:
linter-version: Latest
ref-type: main
sourcery-token: ${{ secrets.TRUNK_SOURCERY_TOKEN }}
cli-path: ${{ github.workspace }}\trunk.ps1
append-args: ${{needs.detect_changes.outputs.linters-files }} -- --maxWorkers=5
trunk-staging-token: ${{ secrets.TRUNK_DEBUGGER_TOKEN }}
trunk-prod-token: ${{ secrets.TRUNK_ORG_PROD_TOKEN }}
windows_tool_tests:
name: Windows Tool Tests
runs-on: windows-latest
needs: detect_changes
if: needs.detect_changes.outputs.tools == 'true'
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Cache tool downloads
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: /tmp/plugins_testing_download_cache
key: trunk-${{ runner.os }}
- name: Tool Tests
# Run tests using KnownGoodVersion with any modified tools
uses: ./.github/actions/tool_tests
with:
append-args: ${{needs.detect_changes.outputs.tools-files }} -- --maxWorkers=5
cli-path: ${{ github.workspace }}\trunk.ps1
trunk-staging-token: ${{ secrets.TRUNK_DEBUGGER_TOKEN }}
trunk-prod-token: ${{ secrets.TRUNK_ORG_PROD_TOKEN }}
# Run repo healthcheck tests
repo_tests:
name: Repo Tests
needs: detect_changes
if: needs.detect_changes.outputs.repo-tests == 'true'
uses: ./.github/workflows/repo_tests.reusable.yaml
report_test_success:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Aggregate Test Results
needs: [linter_tests, tool_tests, repo_tests]
steps:
- run: |
linters="${{ needs.linter_tests.result }}"
repos="${{ needs.repo_tests.result }}"
tools="${{ needs.tool_tests.result }}"
if [[ $linters != "success" && $linters != "skipped" ]]; then
echo "Detected failure in linter tests"
exit 1
elif [[ $tools != "success" && $tools != "skipped" ]]; then
echo "Detected failure in tool tests"
exit 1
elif [[ $repos != "success" && $repos != "skipped" ]]; then
echo "Detected failure in repo tests"
exit 1
else
echo "All tests skipped or passed"
exit 0
fi