-
Notifications
You must be signed in to change notification settings - Fork 36
225 lines (205 loc) · 7.72 KB
/
Copy pathtest.yml
File metadata and controls
225 lines (205 loc) · 7.72 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
name: test
# Taken from https://github.com/actions/starter-workflows/blob/main/ci/python-app.yml
on:
push:
branches: [ main ]
pull_request:
types: [opened, edited, synchronize]
permissions:
contents: read
jobs:
# Determine which tests to run based on changed files
detect-changes:
runs-on: ubuntu-latest
outputs:
single-parser: ${{ steps.detect-parser.outputs.parser }}
run-all-tests: ${{ steps.detect-parser.outputs.run-all }}
schema-generation: ${{ steps.filter.outputs.schema-generation }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
list-files: json
filters: |
parsers:
- 'src/allotropy/parsers/**'
- 'tests/parsers/**'
non-parser:
- 'src/allotropy/!(parsers)/**'
- 'tests/!(parsers)/**'
- 'pyproject.toml'
- 'scripts/**'
- '.github/**'
schema-generation:
- 'src/allotropy/allotrope/schemas/**'
- 'src/allotropy/allotrope/models/**'
- 'src/allotropy/allotrope/schemas.py'
- 'src/allotropy/schema_gen/**'
- 'src/allotropy/exceptions.py'
- 'scripts/download_schema.py'
- 'tests/schema_gen/**'
- 'pyproject.toml'
- name: Detect single parser changes
id: detect-parser
run: |
if [[ "${{ steps.filter.outputs.non-parser }}" == "true" ]]; then
echo "Changes detected outside parsers, running all tests"
echo "run-all=true" >> $GITHUB_OUTPUT
echo "parser=" >> $GITHUB_OUTPUT
elif [[ "${{ steps.filter.outputs.parsers }}" == "true" ]]; then
# Get list of changed files in parsers directory
FILES=$(echo '${{ steps.filter.outputs.parsers_files }}' | jq -r '.[]')
# Extract unique parser directories from both src and tests
SRC_PARSERS=$(echo "$FILES" | grep '^src/allotropy/parsers/' | cut -d'/' -f4 | grep -v '^utils$' | grep -v '^__pycache__$' || true)
TEST_PARSERS=$(echo "$FILES" | grep '^tests/parsers/' | cut -d'/' -f3 | grep -v '^__pycache__$' || true)
# Combine and get unique parsers
ALL_PARSERS=$(echo -e "$SRC_PARSERS\n$TEST_PARSERS" | sort -u | grep -v '^$' || true)
# Count unique parsers
PARSER_COUNT=$(echo "$ALL_PARSERS" | grep -v '^$' | wc -l || echo "0")
if [[ $PARSER_COUNT -eq 1 ]]; then
PARSER=$(echo "$ALL_PARSERS" | head -n1)
# Check if it's actually a parser directory (not utils, shared, etc)
if [[ "$PARSER" != "utils" && "$PARSER" != "__pycache__" && -d "tests/parsers/$PARSER" ]]; then
echo "Single parser detected: $PARSER"
echo "run-all=false" >> $GITHUB_OUTPUT
echo "parser=$PARSER" >> $GITHUB_OUTPUT
else
echo "Changes in shared parser utilities, running all tests"
echo "run-all=true" >> $GITHUB_OUTPUT
echo "parser=" >> $GITHUB_OUTPUT
fi
else
echo "Multiple parsers changed, running all tests"
echo "run-all=true" >> $GITHUB_OUTPUT
echo "parser=" >> $GITHUB_OUTPUT
fi
else
echo "No parser changes detected, running all tests"
echo "run-all=true" >> $GITHUB_OUTPUT
echo "parser=" >> $GITHUB_OUTPUT
fi
test_py_310:
needs: detect-changes
runs-on: ubuntu-latest
name: Tests (python 3.10)
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install hatch
run: pip install "hatch>=1.13.0"
- name: Install click
run: pip install click!=8.3.0
- name: Run Tests (excluding schema generation)
run: |
if [[ "${{ needs.detect-changes.outputs.run-all }}" == "true" ]]; then
echo "Running all tests"
hatch run test_all.py3.10:pytest -n 2 tests else
echo "Running tests for parser: ${{ needs.detect-changes.outputs.single-parser }}"
hatch run test_all.py3.10:pytest -n 2 tests/parsers/${{ needs.detect-changes.outputs.single-parser }} tests/parser_factory_test.py::test_table_contents
fi
timeout-minutes: 15
test_py_311:
needs: detect-changes
runs-on: ubuntu-latest
name: Tests (python 3.11)
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: actions/setup-python@v5
with:
python-version: "3.11.9"
- name: Install hatch
run: pip install "hatch>=1.13.0"
# NOTE: due to bug: https://github.com/pallets/click/issues/3066
- name: Install click
run: pip install click!=8.3.0
- name: Run Tests (excluding schema generation)
run: |
if [[ "${{ needs.detect-changes.outputs.run-all }}" == "true" ]]; then
echo "Running all tests"
hatch run test_all.py3.11:pytest -n 2 tests else
echo "Running tests for parser: ${{ needs.detect-changes.outputs.single-parser }}"
hatch run test_all.py3.11:pytest -n 2 tests/parsers/${{ needs.detect-changes.outputs.single-parser }} tests/parser_factory_test.py::test_table_contents
fi
timeout-minutes: 15
test_py_312:
needs: detect-changes
runs-on: ubuntu-latest
name: Tests (python 3.12)
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install hatch
run: pip install "hatch>=1.13.0"
- name: Install click
run: pip install click!=8.3.0
- name: Run Tests (excluding schema generation)
run: |
if [[ "${{ needs.detect-changes.outputs.run-all }}" == "true" ]]; then
echo "Running all tests"
hatch run test_all.py3.12:pytest -n 2 tests else
echo "Running tests for parser: ${{ needs.detect-changes.outputs.single-parser }}"
hatch run test_all.py3.12:pytest -n 2 tests/parsers/${{ needs.detect-changes.outputs.single-parser }} tests/parser_factory_test.py::test_table_contents
fi
timeout-minutes: 15
# Schema generation test - only runs when relevant files change or on main branch
schema_generation_test:
needs: detect-changes
# Always run on main branch, otherwise only when schema files change
if: ${{ github.ref == 'refs/heads/main' || needs.detect-changes.outputs.schema-generation == 'true' }}
runs-on: ubuntu-latest
name: Schema Generation Test
strategy:
matrix:
python-version: ["3.10"] # Only run on one Python version since output is the same
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install hatch
run: pip install "hatch>=1.13.0"
- name: Install click
run: pip install click!=8.3.0
- name: Run Schema Generation Test
run: hatch run test_all.py${{ matrix.python-version }}:pytest tests/schema_gen/ -v
timeout-minutes: 5
lint:
runs-on: ubuntu-latest
name: Quality Checks
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: actions/setup-python@v5
with:
python-version: "3.11.9"
- name: Install hatch
run: pip install "hatch>=1.13.0"
- name: Install click
run: pip install click!=8.3.0
- name: Lint
run: hatch run lint
pr-title-check:
runs-on: ubuntu-latest
name: Check PR Title
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Check PR title
run: ./scripts/check_title
env:
PR_TITLE: ${{ github.event.pull_request.title }}