-
Notifications
You must be signed in to change notification settings - Fork 0
271 lines (242 loc) · 9.79 KB
/
python-package.yml
File metadata and controls
271 lines (242 loc) · 9.79 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
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
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"
build:
runs-on: ubuntu-latest
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-posp
- geos-timehistory
- geos-trame
- geos-xml-tools
- geos-xml-viewer
- hdf5-wrapper
- pygeos-tools
include:
- package-name: geos-geomechanics
dependencies: "geos-utils"
- package-name: geos-mesh
dependencies: "geos-utils geos-geomechanics"
- package-name: geos-posp
dependencies: "geos-utils geos-mesh geos-geomechanics"
- 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 package
# working-directory: ./${{ matrix.package-name }}
run: |
python -m pip install --upgrade pip
python -m pip install pytest yapf toml
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]
- 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'
# 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: [semantic_pull_request, 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"
"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 label is present (overrides automatic detection)
HAS_LABEL=$(echo '${{ toJson(github.event.pull_request.labels.*.name) }}' | grep -q "test-geos-integration" && echo "true" || echo "false")
if [[ "$HAS_LABEL" == "true" ]]; then
echo "✓ Label 'test-geos-integration' found - GEOS integration test will run"
echo "required=true" >> "$GITHUB_OUTPUT"
echo "skip_reason=none" >> "$GITHUB_OUTPUT"
exit 0
fi
# 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 'test-geos-integration' label"
echo "required=false" >> "$GITHUB_OUTPUT"
echo "skip_reason=no-geos-integrated-changes" >> "$GITHUB_OUTPUT"
fi
# Step 4: Run GEOS integration tests (only if required or label present)
geos_integration_test:
name: GEOS Integration Test
needs: [check_geos_integration_required]
if: needs.check_geos_integration_required.outputs.geos_integration_required == 'true'
uses: ./.github/workflows/test_geos_integration.yml
# Final validation - Summarize CI results
final_validation:
name: Final CI Validation
runs-on: ubuntu-latest
needs: [check_geos_integration_required, geos_integration_test]
if: always() && github.event_name == 'pull_request'
steps:
- name: Validate CI completion
run: |
echo "Final CI Validation"
echo "==================="
GEOS_REQUIRED="${{ needs.check_geos_integration_required.outputs.geos_integration_required }}"
SKIP_REASON="${{ needs.check_geos_integration_required.outputs.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 'test-geos-integration' label to this PR"
echo ""
echo "✓ CI requirements satisfied - PR can be merged"
fi