-
Notifications
You must be signed in to change notification settings - Fork 0
416 lines (375 loc) · 15.8 KB
/
python-package.yml
File metadata and controls
416 lines (375 loc) · 15.8 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
name: geosPythonPackages CI
on: pull_request
# Cancels in-progress workflows for a PR when updated
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
LABEL_TEST_GEOS_INTEGRATION: 'test-geos-integration'
LABEL_FORCE_GEOS_INTEGRATION: 'force-geos-integration'
jobs:
# Checks if PR title follows conventional semantics
semantic_pull_request:
permissions:
pull-requests: write # for amannn/action-semantic-pull-request to analyze PRs and
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
contents: read
runs-on: ubuntu-latest
steps:
- name: Check if the PR name has conventional semantics
if: github.event_name == 'pull_request'
uses: amannn/action-semantic-pull-request@v5.5.3
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
wip: true
# Configure that a scope doesn't need to be provided.
requireScope: false
- name: Skip the check on main branch
if: github.ref_name == 'main'
run: |
echo "This is not a Pull-Request, skipping"
check_draft:
runs-on: ubuntu-latest
needs: [semantic_pull_request]
steps:
- name: Fail if PR is a draft
run: |
if [ "${{ github.event.pull_request.draft }}" = "true" ]; then
echo "✗ This PR is a draft. CI will not proceed."
exit 1
else
echo "✓ This PR is ready for review."
fi
# build and test the standalone CI
build:
runs-on: ubuntu-latest
needs: [check_draft]
strategy:
fail-fast: false
max-parallel: 3
matrix:
python-version: ["3.10","3.11","3.12"]
package-name:
- geos-ats
- geos-utils
- geos-geomechanics
- geos-mesh
- geos-processing
- geos-timehistory
- geos-trame
- geos-xml-tools
- geos-xml-viewer
- mesh-doctor
- hdf5-wrapper
- pygeos-tools
include:
- package-name: geos-geomechanics
dependencies: "geos-utils"
- package-name: geos-mesh
dependencies: "geos-utils geos-geomechanics"
- package-name: geos-processing
dependencies: "geos-utils geos-mesh geos-geomechanics"
- package-name: mesh-doctor
dependencies: "geos-utils geos-mesh"
- package-name: pygeos-tools
dependencies: "geos-utils geos-mesh"
- package-name: geos-timehistory
dependencies: "hdf5-wrapper"
steps:
- uses: actions/checkout@v4
- uses: mpi4py/setup-mpi@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install OSMesa and GL
run: |
sudo apt-get update
sudo apt-get install -y libosmesa6
sudo apt-get install -y \
libegl1-mesa-dev \
libgles2-mesa-dev \
libgl1-mesa-dev \
libx11-dev \
libxext-dev
- name: Install package
# working-directory: ./${{ matrix.package-name }}
run: |
python -m pip install --upgrade pip
DEPS="${{ matrix.dependencies || '' }}"
if [ -n "$DEPS" ]; then
echo "Installing additional dependencies: $DEPS"
for dep in $DEPS; do
python -m pip install ./$dep
done
fi
echo "Installing main package..."
python -m pip install ./${{ matrix.package-name }}/[test]
# LWS Install setuptools first to provide pkg_resources for older plugins
python -m pip install setuptools
python -m pip install "pytest>=8.0.0" yapf toml "pytest-html>=4.0.0"
- name: Lint with yapf
# working-directory: ./${{ matrix.package-name }}
run: |
yapf -r --diff ./${{ matrix.package-name }} --style .style.yapf
- name: Test with pytest
#working-directory: ./${{ matrix.package-name }}
run:
# python -m pytest ./${{ matrix.package-name }} --doctest-modules --junitxml=junit/test-results.xml --cov-report=xml --cov-report=html |
# wrap pytest to avoid error when no tests in the package
sh -c 'python -m pytest ./${{ matrix.package-name }}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
# check if GEOS has label for testing GEOS integration
check_integration_label:
runs-on: ubuntu-latest
needs: [build]
outputs:
has_geos_integration_label: ${{ steps.set-label.outputs.has_label }}
steps:
- name: Check if PR has '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label
id: set-label
run: |
echo "Checking for label..."
LABEL_FOUND=false
LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'
echo "PR Labels: $LABELS"
if echo "$LABELS" | grep -q "${{ env.LABEL_TEST_GEOS_INTEGRATION }}"; then
LABEL_FOUND=true
echo "Label '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' found"
fi
echo "has_label=$LABEL_FOUND" >> $GITHUB_OUTPUT
check_force_integration_label:
runs-on: ubuntu-latest
needs: [build]
outputs:
has_geos_integration_force_label: ${{ steps.set-label.outputs.has_label }}
steps:
- name: Check if PR has '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' label
id: set-label
run: |
echo "Checking for label..."
LABEL_FOUND=false
LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'
echo "PR Labels: $LABELS"
if echo "$LABELS" | grep -q "${{ env.LABEL_FORCE_GEOS_INTEGRATION }}"; then
LABEL_FOUND=true
echo "Label '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' found"
fi
echo "has_label=$LABEL_FOUND" >> $GITHUB_OUTPUT
# Step 3: Check if GEOS integration is required based on changed files
check_geos_integration_required:
name: Check GEOS Integration Required
runs-on: ubuntu-latest
needs: [build]
if: github.event_name == 'pull_request'
outputs:
geos_integration_required: ${{ steps.check_changes.outputs.required }}
skip_reason: ${{ steps.check_changes.outputs.skip_reason }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history to compare with base branch
- name: Check if GEOS integration is required
id: check_changes
run: |
echo "Analyzing changed files to determine if GEOS integration test is required..."
# Get list of changed files
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"
echo ""
# Define packages that are integrated into GEOS (from GEOS/scripts/setupPythonEnvironment.bash)
GEOS_INTEGRATED_PACKAGES=(
"geos-utils"
"geos-mesh"
"geos-xml-tools"
"hdf5-wrapper"
"mesh-doctor"
"pygeos-tools"
"geos-ats"
)
# Define patterns that DON'T require GEOS integration testing
SKIP_PATTERNS=(
"^docs/"
"^\.github/workflows/doc-test\.yml$"
"^\.github/workflows/typing-check\.yml$"
"^README\.md$"
"^\.readthedocs\.yml$"
"^\.gitignore$"
"^\.gitattributes$"
"^\.style\.yapf$"
"^\.ruff\.toml$"
"^\.mypy\.ini$"
# Packages not used in GEOS
"^geos-geomechanics/"
"^geos-posp/"
"^geos-pv/"
"^geos-timehistory/"
"^geos-trame/"
"^geos-xml-viewer/"
)
# Check if any changed file affects GEOS-integrated packages
REQUIRES_GEOS_TEST=false
AFFECTED_PACKAGES=""
for file in $CHANGED_FILES; do
# Check if file matches any skip pattern
SHOULD_SKIP=false
for pattern in "${SKIP_PATTERNS[@]}"; do
if echo "$file" | grep -qE "$pattern"; then
SHOULD_SKIP=true
break
fi
done
if [[ "$SHOULD_SKIP" == "false" ]]; then
# Check if file is in a GEOS-integrated package
for package in "${GEOS_INTEGRATED_PACKAGES[@]}"; do
if echo "$file" | grep -qE "^${package}/"; then
REQUIRES_GEOS_TEST=true
if [[ ! "$AFFECTED_PACKAGES" =~ "$package" ]]; then
AFFECTED_PACKAGES="$AFFECTED_PACKAGES $package"
fi
fi
done
# Check for CI workflow changes that affect GEOS integration
if echo "$file" | grep -qE "^\.github/workflows/(python-package\.yml|test_geos_integration\.yml)$"; then
REQUIRES_GEOS_TEST=true
AFFECTED_PACKAGES="$AFFECTED_PACKAGES [CI-workflows]"
fi
# Check for root-level scripts that might affect integration
if echo "$file" | grep -qE "^install_packages\.sh$"; then
REQUIRES_GEOS_TEST=true
AFFECTED_PACKAGES="$AFFECTED_PACKAGES [install-scripts]"
fi
fi
done
if [[ "$REQUIRES_GEOS_TEST" == "true" ]]; then
echo "✓ GEOS integration test REQUIRED"
echo " Affected packages/components:$AFFECTED_PACKAGES"
echo " These packages are integrated into GEOS and require testing"
echo "required=true" >> "$GITHUB_OUTPUT"
echo "skip_reason=none" >> "$GITHUB_OUTPUT"
else
echo "⊘ GEOS integration test NOT required"
echo " All changes are in documentation, non-integrated packages, or config files"
echo " To force GEOS integration testing, add the '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label"
echo "required=false" >> "$GITHUB_OUTPUT"
echo "skip_reason=no-geos-integrated-changes" >> "$GITHUB_OUTPUT"
fi
geos_ci_dispatch:
name: Dispatch cases of GEOS CI
runs-on: ubuntu-latest
outputs:
is_GEOS_CI_skipped: ${{ steps.dispatch.outputs.skipped }}
fwd_geos_integration_required: ${{ steps.dispatch.outputs.fwd_geos_integration_required }}
fwd_skip_reason: ${{ steps.dispatch.outputs.skip_reason }}
needs: [check_geos_integration_required, check_integration_label, check_force_integration_label]
steps:
- name: Dispatch flag and req cases
id: dispatch
run: |
GEOS_REQUIRED="${{ needs.check_geos_integration_required.outputs.geos_integration_required }}"
HAS_TEST_LABEL="${{ needs.check_integration_label.outputs.has_geos_integration_label }}"
HAS_FORCE_LABEL="${{ needs.check_force_integration_label.outputs.has_geos_integration_force_label }}"
SKIP_REASON="${{ needs.check_geos_integration_required.outputs.skip_reason }}"
echo "fwd_geos_integration_required=${GEOS_REQUIRED}" >> "$GITHUB_OUTPUT"
echo "fwd_skip_reason=${SKIP_REASON}" >> "$GITHUB_OUTPUT"
echo "=== GEOS Integration Dispatch ==="
echo "GEOS Required (by file changes): ${GEOS_REQUIRED}"
echo "Has '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label: ${HAS_TEST_LABEL}"
echo "Has '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' label: ${HAS_FORCE_LABEL}"
echo ""
# Case 1: Force label - always run tests
if [[ "$HAS_FORCE_LABEL" == "true" ]]; then
echo "✓ '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' label present - forcing GEOS integration tests"
echo "skipped=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Case 2: GEOS required AND test label present - run tests
if [[ "$GEOS_REQUIRED" == "true" && "$HAS_TEST_LABEL" == "true" ]]; then
echo "✓ GEOS integration required and '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label present"
echo " Will proceed with GEOS integration tests"
echo "skipped=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Case 3: GEOS required BUT test label missing - ERROR
if [[ "$GEOS_REQUIRED" == "true" && "$HAS_TEST_LABEL" == "false" ]]; then
echo "✗ ERROR: GEOS integration is required but '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label is missing"
echo ""
echo "Your PR modifies GEOS-integrated packages:"
echo " - geos-utils, geos-mesh, geos-xml-tools"
echo " - hdf5-wrapper, pygeos-tools, geos-ats"
echo ""
echo "Action required: Add the '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label to this PR"
exit 1
fi
# Case 4: GEOS NOT required BUT test label present - SKIP TESTS
if [[ "$GEOS_REQUIRED" == "false" && "$HAS_TEST_LABEL" == "true" ]]; then
echo "⊘ SKIPPED: '${{ env.LABEL_TEST_GEOS_INTEGRATION }}' label present but GEOS integration is not required"
echo ""
echo "Your changes only affect:"
echo " - Documentation"
echo " - Non-integrated packages"
echo " - Configuration files"
echo ""
echo "If you want to run GEOS integration tests anyway, use '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' label to explicitly force testing"
echo "skipped=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Case 5: GEOS NOT required AND no labels - SKIP TESTS
if [[ "$GEOS_REQUIRED" == "false" && "$HAS_TEST_LABEL" == "false" ]]; then
echo "⊘ GEOS integration not required and no labels present"
echo " Skipping GEOS integration tests"
echo " Reason: ${SKIP_REASON}"
echo "skipped=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Should never reach here
echo "✗ ERROR: Unexpected state in dispatch logic"
exit 1
# Step 4: Run GEOS integration tests (only if required or label present)
geos_integration_test:
name: GEOS Integration Test
needs: [geos_ci_dispatch]
if: ${{ needs.geos_ci_dispatch.outputs.is_GEOS_CI_skipped != 'true' }}
uses: ./.github/workflows/test_geos_integration.yml
# Final validation - Summarize CI results
final_validation:
name: Final CI Validation
runs-on: ubuntu-latest
needs: [geos_ci_dispatch, geos_integration_test]
if: always() && github.event_name == 'pull_request'
steps:
- name: Validate CI completion
run: |
echo "Final CI Validation"
echo "==================="
GEOS_REQUIRED="${{ needs.geos_ci_dispatch.outputs.fwd_geos_integration_required }}"
SKIP_REASON="${{ needs.geos_ci_dispatch.outputs.fwd_skip_reason }}"
GEOS_RESULT="${{ needs.geos_integration_test.result }}"
if [[ "$GEOS_REQUIRED" == "true" ]]; then
echo "GEOS integration test was required and triggered"
if [[ "$GEOS_RESULT" == "success" ]]; then
echo "✓ GEOS integration test PASSED"
echo "✓ All CI requirements satisfied - PR can be merged"
else
echo "✗ GEOS integration test FAILED or was skipped"
echo "✗ CI FAILED - PR cannot be merged until GEOS integration passes"
exit 1
fi
else
echo "GEOS integration test was NOT required"
echo "Reason: $SKIP_REASON"
echo ""
echo "Changed files do not affect GEOS-integrated packages:"
echo " - geos-utils, geos-mesh, geos-xml-tools"
echo " - hdf5-wrapper, pygeos-tools, geos-ats"
echo ""
echo "If you want to run GEOS integration tests anyway,"
echo "add the '${{ env.LABEL_FORCE_GEOS_INTEGRATION }}' label to this PR"
echo ""
echo "✓ CI requirements satisfied - PR can be merged"
fi