Repository navigation
executable file
·105 lines (90 loc) · 3.14 KB
/
Copy pathtest-workspaces.yaml
File metadata and controls
executable file
·105 lines (90 loc) · 3.14 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
# @format
name: Test workspaces
# A draft pull request only runs the workspaces its changes impact (the ones
# owning a changed file, and what depends on them - see
# ws-impacted); marking it ready for review and any push to a non-draft pull
# request run every workspace. Nothing runs on a push to a long-lived branch:
# they are only tested through their pull requests.
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
list-packages:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
packages: ${{ steps.list.outputs.packages }}
steps:
- uses: actions/checkout@v7
with:
# The pull request merge commit and its base-side parent, to diff them.
fetch-depth: 2
- name: Install ws-impacted
if: github.event_name == 'pull_request' && github.event.pull_request.draft
uses: tomgrv/actions/setup-scripts@v5
with:
scripts: ws-impacted
- name: Scope to the impacted workspaces (draft pull requests)
id: scope
if: github.event_name == 'pull_request' && github.event.pull_request.draft
run: echo "filter=$(ws-impacted -r HEAD^1..HEAD)" >> "$GITHUB_OUTPUT"
- name: List packages
id: list
uses: tomgrv/actions/list-packages@v5
with:
require-repository: 'false'
filter: ${{ steps.scope.outputs.filter }}
test:
needs: list-packages
if: needs.list-packages.outputs.packages != '[]'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.list-packages.outputs.packages) }}
steps:
- uses: actions/checkout@v7
- name: Setup Bats
uses: bats-core/bats-action@4.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run workspace tests
uses: tomgrv/actions/run-workspace-tests@v5
with:
workspace: ${{ matrix.package.path }}
repo-tests:
# Repo-wide tests are not workspace-scoped: skipped on drafts, run on ready.
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- name: Setup Bats
uses: bats-core/bats-action@4.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run repo-wide tests
run: |
if compgen -G "tests/*.bats" > /dev/null; then
bats tests/
else
echo "No repo-wide tests under tests/, skipping."
fi
# Single check to mark as required in branch protection: red if any test
# job failed or was cancelled (skipped is fine - drafts skip repo-tests).
tests-green:
name: Tests green
needs: [list-packages, test, repo-tests]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Fail unless all tests are green
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1