Repository navigation
381 lines (353 loc) · 14.9 KB
/
Copy pathtest.yml
File metadata and controls
381 lines (353 loc) · 14.9 KB
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
name: Test
# The single pull-request gate: lint, unit tests, the BuildStream graph and
# (pull requests only) the install E2E tests.
#
# The `changes` job maps the changed files to the jobs they can affect, and
# every other job is skipped. A skipped job reports success, so the required
# checks always report. If `changes` itself fails, every gate runs. A change
# to this workflow runs everything.
#
# Install E2E: plain and LUKS build the same ISO from this tree and differ
# only in the install path, so a change to shared inputs runs a round-robin
# slice of them (repo variable E2E_ROUND_ROBIN_SIZE, default 1, picked by
# run number). A change to a mode's own script or workflow always runs that
# mode. Both modes run in full on their weekly schedule and on dispatch.
on:
pull_request:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Detect changed files
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
pull-requests: read
outputs:
shell: ${{ steps.classify.outputs.shell }}
yaml: ${{ steps.classify.outputs.yaml }}
workflows: ${{ steps.classify.outputs.workflows }}
renovate: ${{ steps.classify.outputs.renovate }}
bst: ${{ steps.classify.outputs.bst }}
graph: ${{ steps.classify.outputs.graph }}
bats: ${{ steps.classify.outputs.bats }}
pytest: ${{ steps.classify.outputs.pytest }}
just: ${{ steps.classify.outputs.just }}
e2e-plain: ${{ steps.classify.outputs.e2e-plain }}
e2e-luks: ${{ steps.classify.outputs.e2e-luks }}
steps:
- name: List changed files
id: list
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
EVENT: ${{ github.event_name }}
PR: ${{ github.event.pull_request.number }}
PR_FILES: ${{ github.event.pull_request.changed_files }}
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.event.after }}
run: |
set -euo pipefail
all=true
: > "$RUNNER_TEMP/changed.txt"
case "$EVENT" in
pull_request)
# The files API lists at most 3000 files; above that, test all.
if [ "${PR_FILES:-0}" -le 3000 ]; then
gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" \
--jq '.[] | .filename, (.previous_filename // empty)' > "$RUNNER_TEMP/changed.txt"
all=false
fi
;;
push)
# The compare API lists at most 300 files; a new branch has no base.
if [[ ! "$BEFORE" =~ ^0+$ ]]; then
gh api "repos/$REPO/compare/$BEFORE...$AFTER" \
--jq '.files[] | .filename, (.previous_filename // empty)' > "$RUNNER_TEMP/changed.txt"
[ "$(wc -l < "$RUNNER_TEMP/changed.txt")" -ge 300 ] || all=false
fi
;;
esac
echo "all=$all" >> "$GITHUB_OUTPUT"
echo "Changed files (all=$all):"
cat "$RUNNER_TEMP/changed.txt"
- name: Map changed files to jobs
id: classify
env:
ALL: ${{ steps.list.outputs.all }}
EVENT: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
RUN_NUMBER: ${{ github.run_number }}
RR_SIZE: ${{ vars.E2E_ROUND_ROBIN_SIZE || '1' }}
CHANGED: ${{ runner.temp }}/changed.txt
run: |
set -euo pipefail
all=$ALL
shell=false yaml=false workflows=false renovate=false bst=false
graph=false bats=false pytest=false just=false
e2e_shared=false plain=false luks=false
while IFS= read -r f; do
[ -n "$f" ] || continue
case "$f" in .github/workflows/test.yml) all=true ;; esac
case "$f" in *.sh|*.bash) shell=true ;; esac
case "$f" in *.yml|*.yaml|.yamllint) yaml=true ;; esac
case "$f" in .github/workflows/*|.github/actions/*) workflows=true ;; esac
case "$f" in renovate.json|renovate.json5|.renovaterc|.renovaterc.json|.github/renovate.json|.github/renovate.json5) renovate=true ;; esac
case "$f" in *.bst) bst=true ;; esac
case "$f" in tests/bats/*|tromso/src/*) bats=true ;; esac
# pytest also checks repo-wide invariants (tracked file sizes,
# workflows, elements), so only prose skips it.
case "$f" in *.md|LICENSE*) ;; *) pytest=true ;; esac
case "$f" in Justfile|justfile|iso.justfile|*.just|just/*) just=true ;; esac
# `bst show` reads the project, elements and local sources; these
# paths are never part of the BuildStream graph.
case "$f" in
*.md|LICENSE*|docs/*|runbooks/*|tests/*|scripts/*|tromso/*|.github/*) ;;
Justfile|iso.justfile|just/*|renovate.json|ruff.toml|codecov.yml) ;;
.yamllint.yml|.editorconfig|.gitignore|.ste-budget) ;;
*) graph=true ;;
esac
case "$f" in tromso/*|Justfile|iso.justfile|scripts/lib-install-qemu.sh|scripts/fisherman-install.sh) e2e_shared=true ;; esac
case "$f" in scripts/plain-install-qemu.sh|.github/workflows/test-plain-install.yml) plain=true ;; esac
case "$f" in scripts/luks-install-qemu.sh|.github/workflows/test-luks-install.yml) luks=true ;; esac
done < "$CHANGED"
if [ "$all" = true ]; then
shell=true yaml=true workflows=true renovate=true bst=true
graph=true bats=true pytest=true just=true
plain=true luks=true
elif [ "$e2e_shared" = true ]; then
cells=(plain luks)
n=${#cells[@]}
size=$RR_SIZE
[[ "$size" =~ ^[0-9]+$ ]] && [ "$size" -ge 1 ] || size=1
[ "$size" -le "$n" ] || size=$n
for ((i = 0; i < size; i++)); do
cell=${cells[$(( (RUN_NUMBER * size + i) % n ))]}
printf -v "$cell" true
done
fi
# The E2E tests gate pull requests into main only.
if [ "$EVENT" != pull_request ] || [ "$BASE_REF" != main ]; then
plain=false luks=false
fi
{
echo "shell=$shell"
echo "yaml=$yaml"
echo "workflows=$workflows"
echo "renovate=$renovate"
echo "bst=$bst"
echo "graph=$graph"
echo "bats=$bats"
echo "pytest=$pytest"
echo "just=$just"
echo "e2e-plain=$plain"
echo "e2e-luks=$luks"
} | tee -a "$GITHUB_OUTPUT" >> "$GITHUB_STEP_SUMMARY"
shellcheck:
name: shellcheck
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.shell == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Run shellcheck
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # 2.0.0
with:
# Pinned (tromso#185): the action defaults to version: stable,
# which resolves to a moving GitHub release tag. A transient
# asset-CDN hiccup on that tag returns an HTML page instead of
# the tarball ("tar: This does not look like a tar archive"),
# not reproducible on retry -- pinning to a concrete release
# makes the download URL deterministic.
version: v0.11.0
scandir: '.'
additional_files: >
tromso/src/build-iso.sh
tromso/src/configure-live.sh
tromso/src/install-flatpaks.sh
severity: error
# files/ is kde-build-meta-derived: dracut module fragments and
# profile.d snippets meant to be sourced, not executed — they
# intentionally have no shebang (SC2148 doesn't apply to them).
ignore_paths: files
yamllint:
name: yamllint
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.yaml == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Run yamllint (.yamllint.yml)
uses: ibiqlik/action-yamllint@2576378a8e339169678f9939646ee3ee325e845c # v3
with:
config_file: .yamllint.yml
- name: Run yamllint (default rules)
uses: ibiqlik/action-yamllint@2576378a8e339169678f9939646ee3ee325e845c # v3
with:
file_or_dir: .
config_data: |
extends: default
rules:
line-length: disable
document-start: disable
truthy: disable
comments-indentation: disable
braces:
level: warning
max-spaces-inside: 1
brackets:
level: warning
max-spaces-inside: 1
actionlint:
name: actionlint
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.workflows == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Run actionlint on workflows
uses: docker://rhysd/actionlint@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667 # latest
with:
args: -color
renovate-config:
name: Renovate Config Validate
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.renovate == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Validate renovate.json
run: npx --yes --package renovate -- renovate-config-validator renovate.json
lint-bst:
name: lint .bst files
needs: changes
if: ${{ !cancelled() && github.event_name == 'pull_request' && (needs.changes.result != 'success' || needs.changes.outputs.bst == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Checkout bst-ci scripts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: tuna-os/bst-ci
ref: main
path: .bst-ci
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7
with:
python-version: '3.15'
- name: Lint changed .bst files
run: |
pip install pyyaml
git fetch origin "${{ github.event.pull_request.base.ref }}" --depth=1
mapfile -t files < <(git diff --name-only --diff-filter=AM "origin/${{ github.event.pull_request.base.ref }}"...HEAD -- '*.bst')
if [ "${#files[@]}" -eq 0 ]; then
echo "No .bst files changed in this PR."
exit 0
fi
echo "Changed .bst files:"
printf ' %s\n' "${files[@]}"
python3 .bst-ci/scripts/lint_bst.py elements --check-new "${files[@]}"
bst-validate:
name: BuildStream Validate
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.graph == 'true') }}
runs-on: ubuntu-24.04
container:
image: registry.gitlab.com/freedesktop-sdk/infrastructure/freedesktop-sdk-docker-images/bst2:64eb0b4930d57a92710822898fb73af6cc1ae35d
# BuildStream's CAS stager needs a real FUSE device; a plain container
# job has neither /dev/fuse nor CAP_SYS_ADMIN by default.
options: --privileged --device /dev/fuse
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Validate full element graph
# Hard gate: parses every element, resolves junction refs, and
# verifies the dependency graph of the shipping target. The previous
# version ended in `|| echo` and could never fail.
run: |
bst --no-interactive show --deps all --format "%{name} %{state}" oci/tromso.bst > /tmp/graph.txt
wc -l /tmp/graph.txt
bats-tests:
name: BATS Unit Tests
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.bats == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Install BATS
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq bats
- name: Run BATS tests
run: |
echo "=== BATS Tests ==="
FAILED=0
for f in tests/bats/*.bats; do
[[ -f "$f" ]] || continue
echo " Running: $f"
bats --formatter tap "$f" || FAILED=1
done
exit $FAILED
pytest:
name: Python Tests
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.pytest == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7
with:
python-version: '3.15'
- name: Install dependencies
run: |
pip install pytest
- name: Run pytest (tests/pytest)
run: pytest tests/pytest/ -v --tb=short
- name: Test summary
if: always()
run: |
echo "| Type | Files |" >> "$GITHUB_STEP_SUMMARY"
echo "|---|---|" >> "$GITHUB_STEP_SUMMARY"
echo "| BATS | $(find tests/bats -name '*.bats' -type f | wc -l) |" >> "$GITHUB_STEP_SUMMARY"
echo "| pytest | $(find tests/pytest -name '*.py' -type f 2>/dev/null | wc -l) |" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Run locally: bats tests/bats/*.bats && pytest tests/pytest/" >> "$GITHUB_STEP_SUMMARY"
just-parse:
name: Just Parse
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.just == 'true') }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4
- name: Parse justfiles
run: |
just --summary > /dev/null
just --evaluate > /dev/null
plain-e2e:
name: Plain E2E
needs: changes
if: needs.changes.outputs.e2e-plain == 'true'
permissions:
issues: write
pull-requests: write
contents: write
actions: read
uses: ./.github/workflows/test-plain-install.yml
luks-e2e:
name: LUKS E2E
needs: changes
if: needs.changes.outputs.e2e-luks == 'true'
permissions:
issues: write
pull-requests: write
contents: write
actions: read
uses: ./.github/workflows/test-luks-install.yml