-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (84 loc) · 3.64 KB
/
Copy pathci.yml
File metadata and controls
90 lines (84 loc) · 3.64 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
name: CI
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: read
pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changes:
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
relevant: ${{ steps.paths.outputs.relevant }}
steps:
- id: paths
env:
GH_TOKEN: ${{ github.token }}
EXPECTED_BASE: ${{ github.event.pull_request.base.sha }}
EXPECTED_BASE_REF: ${{ github.event.pull_request.base.ref }}
EXPECTED_HEAD: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then
echo 'relevant=true' >> "$GITHUB_OUTPUT"
exit 0
fi
gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" > pr.json
gh api --paginate --slurp "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files?per_page=100" > files.json
gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" > pr-after.json
python3 - <<'PYTHON'
import json, os, re
pr = json.load(open('pr.json'))
after = json.load(open('pr-after.json'))
files = [f for page in json.load(open('files.json')) for f in page]
complete = 0 < len(files) == pr['changed_files'] < 3000
stable = all(p['head']['sha'] == os.environ['EXPECTED_HEAD']
and p['base']['sha'] == os.environ['EXPECTED_BASE']
and p['base']['ref'] == os.environ['EXPECTED_BASE_REF']
and p['changed_files'] == pr['changed_files'] for p in (pr, after))
docs = re.compile(r'^(docs/|README[^/]*\.md$|CHANGELOG[^/]*\.md$|LICENSE[^/]*$|\.github/AUTOMATION\.md$)')
paths = [path for f in files for path in (f['filename'], f.get('previous_filename', f['filename']))]
relevant = not (complete and stable and all(docs.search(path) for path in paths))
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
output.write(f'relevant={str(relevant).lower()}\n')
PYTHON
test:
name: typecheck, unit tests, build
if: ((github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false)) && needs.changes.outputs.relevant == 'true'
needs: changes
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun run typecheck
- run: bun test
- run: bun run build
required:
name: Required CI
if: always() && (github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false)
needs: ["changes", "test"]
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- env:
NEEDS: ${{ toJSON(needs) }}
run: |
python3 - <<'PYTHON'
import json, os
jobs = json.loads(os.environ['NEEDS'])
assert jobs['changes']['result'] == 'success', 'Path detection failed'
relevant = jobs.pop('changes')['outputs']['relevant']
assert relevant in ('true', 'false')
expected = 'success' if relevant == 'true' else 'skipped'
assert all(job['result'] == expected for job in jobs.values()), jobs
PYTHON