Repository navigation
144 lines (130 loc) · 4.84 KB
/
Copy pathpython_ci.yml
File metadata and controls
144 lines (130 loc) · 4.84 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
name: Python CI
on:
merge_group:
types: [checks_requested]
push:
branches:
- main
paths:
- 'python/**'
- 'NOTICE'
- 'NOTICE.extra.yml'
- '.github/workflows/python_ci.yml'
- '.github/workflows/lean_action_ci.yml'
- '.github/workflows/docs.yml'
pull_request:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
scope:
runs-on: ubuntu-latest
outputs:
applicable: ${{ steps.scope.outputs.applicable }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
persist-credentials: false
- id: scope
env:
EVENT: ${{ github.event_name }}
BASE: ${{ github.event.merge_group.base_sha || github.event.pull_request.base.sha }}
run: |
applicable=true
if [ "$EVENT" = merge_group ] || [ "$EVENT" = pull_request ]; then
applicable=false
if [ "$EVENT" = pull_request ]; then
files=$(git diff --name-only "$BASE"...HEAD)
else
files=$(git diff --name-only "$BASE"..HEAD)
fi
if printf '%s\n' "$files" | grep -Eq '^(python/|NOTICE$|NOTICE.extra.yml$|.github/workflows/(python_ci|lean_action_ci|docs).yml$)'; then
applicable=true
fi
fi
echo "applicable=$applicable" >> "$GITHUB_OUTPUT"
lint:
needs: scope
if: always() && (needs.scope.result != 'success' || needs.scope.outputs.applicable != 'false')
runs-on: ubuntu-latest
name: Lint (ruff)
steps:
- name: Require successful change classification
env:
SCOPE_RESULT: ${{ needs.scope.result }}
APPLICABLE: ${{ needs.scope.outputs.applicable }}
run: |
if [ "$SCOPE_RESULT" != success ] || [ "$APPLICABLE" != true ]; then
echo "::error::Change classification failed; required validation cannot be skipped."
exit 1
fi
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- uses: astral-sh/setup-uv@d0d8abe699bfb85fec6de9f7adb5ae17292296ff
with:
enable-cache: true
- name: Install dev dependencies
run: cd python && uv sync --locked --group dev
- name: Ruff check
run: cd python && uv run ruff check .
- name: Ruff format check
run: cd python && uv run ruff format --check .
test:
needs: scope
if: always() && (needs.scope.result != 'success' || needs.scope.outputs.applicable != 'false')
runs-on: ubuntu-latest
name: Test (pytest)
steps:
- name: Require successful change classification
env:
SCOPE_RESULT: ${{ needs.scope.result }}
APPLICABLE: ${{ needs.scope.outputs.applicable }}
run: |
if [ "$SCOPE_RESULT" != success ] || [ "$APPLICABLE" != true ]; then
echo "::error::Change classification failed; required validation cannot be skipped."
exit 1
fi
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
persist-credentials: false
- uses: astral-sh/setup-uv@d0d8abe699bfb85fec6de9f7adb5ae17292296ff
with:
enable-cache: true
- name: Install test dependencies
run: cd python && uv sync --locked --group test
- name: Validate authored attribution and regenerate the combined test view
if: github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
EVENT: ${{ github.event_name }}
BASE_SHA: ${{ github.event.merge_group.base_sha || github.event.pull_request.base.sha || github.event.before }}
HEAD_SHA: ${{ github.event.merge_group.head_sha || github.event.pull_request.head.sha || github.sha }}
run: |
arguments=()
if [ "$EVENT" = pull_request ]; then arguments+=(--pull-request); fi
if [ "$EVENT" = push ]; then arguments+=(--main-push); fi
PYTHONPATH=python uv run --project python --locked python -m lean_pool.queue_notice \
--base "$BASE_SHA" --head "$HEAD_SHA" "${arguments[@]}"
- name: Pytest
run: |
cd python
# Translate pytest's exit code 5 ("no tests collected") to success
# so CI passes while tests/ is still empty. Remove this once tests
# exist; any other failure still fails the job.
set +e
uv run pytest --cov
status=$?
set -e
if [ "$status" -eq 5 ]; then
echo "No tests collected; skipping pytest."
exit 0
fi
exit "$status"