-
Notifications
You must be signed in to change notification settings - Fork 3
240 lines (206 loc) · 7.8 KB
/
ci.yml
File metadata and controls
240 lines (206 loc) · 7.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
name: CI/Test
on:
workflow_dispatch:
inputs:
JING_VERSION:
description: "Jing version to use"
required: false
default: "20091111" # Default value
pull_request:
push:
branches:
- main
paths:
- 'src/**'
- 'tests/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: read
pull-requests: write
# GLOBAL ENV: Applies to ALL jobs (Linux & macOS)
env:
# Strict lockfile checks for everyone, equivalent to passing --frozen to every command
UV_FROZEN: "1"
# Needed for coverage/multiprocessing reliability
PYTHONSTARTMETHOD: spawn
# The group to use for installing/testing dependencies, see pyproject.toml
PYPROJECT_GROUP: github-action
jobs:
test-ubuntu:
name: ubuntu-python-${{ matrix.python-version }}
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
python-version: &python-matrix
- '3.12'
- '3.13'
- '3.14'
container:
# image: registry.opensuse.org/documentation/containers/15.6/opensuse-daps-toolchain:latest
image: ghcr.io/opensuse/doc-container:latest
options: --user 0:0
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Get dependencies
run: |
rpm -q daps \
suse-xsl-stylesheets \
suse-xsl-stylesheets-sbp \
geekodoc \
docbook-xsl-stylesheets \
docbook-xsl-ns \
xmlgraphics-fop \
git \
ditaa \
libreoffice-draw \
novdoc \
ruby2.5-rubygem-asciidoctor \
curl \
tar \
w3m \
jq \
rsvg-convert \
openssh-clients || true
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies and Coverage Tools
run: uv sync --group ${{ env.PYPROJECT_GROUP }}
- name: Run tests and Report Coverage
env:
UV_NO_SYNC: "1" # Disable uv sync during test runs
run: |
# Using 'uv run' avoids the need to manually source .venv/bin/activate
uv run pytest --cov=src --cov=tests --cov-report=term-missing -vv
# Combine data
uv run python -m coverage combine --append || true
# Generate report
uv run python -m coverage report | tee coverage.txt
# Cleanup
uv run python -m coverage erase
- name: Create Coverage Comment for ${{ github.event.pull_request.head.sha || github.sha }}
if: success() && github.event_name == 'pull_request' && matrix.python-version == '3.12'
env:
# Use the PR head if available, otherwise fallback to the workflow SHA
COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
COVERAGE_THRESHOLD: 90
run: |
# Get the short SHA (e.g., a1b2c3d)
SHORT_SHA=${COMMIT_SHA::7}
# 1. Header
echo "## Coverage Report" > coverage_comment.txt
echo "For commit $SHORT_SHA" >> coverage_comment.txt
echo "" >> coverage_comment.txt
# 2. Open the collapsible section
echo "<details><summary>Click to expand Coverage Report</summary>" >> coverage_comment.txt
echo "" >> coverage_comment.txt
# 3. Open a diff code block
echo "\`\`\`diff" >> coverage_comment.txt
# 4. Run awk to parse percentages and add colors
awk -v threshold="$COVERAGE_THRESHOLD" '{
# Flag to track if we found a percentage in this line
is_coverage_row = 0
# 1. Scan all fields to find the one ending in "%"
# (Crucial for "term-missing" where the last column might be line numbers "1-5")
for (i=1; i<=NF; i++) {
if ($i ~ /%$/) {
# Remove "%" and force numeric type by adding 0
val = $i
gsub("%", "", val)
val = val + 0 # Force numeric conversion
is_coverage_row = 1
break; # Stop once we find the percentage
}
}
# 2. Logic: Colorize rows with %, indent everything else
if (is_coverage_row) {
if (val < threshold) {
print "- " $0; # Red
} else {
print "+ " $0; # Green
}
} else {
# Headers and Separators (------) fall here.
# We add two spaces so they appear Gray and aligned.
print " " $0;
}
}' coverage.txt >> coverage_comment.txt
# 5. Close the block
echo "\`\`\`" >> coverage_comment.txt
echo "</details>" >> coverage_comment.txt
- name: Save PR Number
if: success() && github.event_name == 'pull_request' && matrix.python-version == '3.12'
run: echo ${{ github.event.number }} > pr_number.txt
- name: Upload Coverage Artifact
if: success() && github.event_name == 'pull_request' && matrix.python-version == '3.12'
uses: actions/upload-artifact@v7
with:
name: coverage-artifact
path: |
coverage_comment.txt
pr_number.txt
test-macos:
name: macos-python-${{ matrix.python-version }}
runs-on: macos-latest
strategy:
matrix:
python-version: *python-matrix
steps:
- name: Checkout repository
uses: actions/checkout@v6
# Set up Python on macOS environment
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
# Install uv and project dependencies inside a virtual environment
- name: Install uv and dependencies
env:
UV_NO_SYNC: "1" # Disable uv sync during test runs
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install uv
uv pip install --editable . --group ${{ env.PYPROJECT_GROUP }}
# Install macOS-specific external tools (such as XML parsers and Java)
- name: Install external tools (macOS)
run: |
brew install libxml2 libxslt openjdk
# Define the version and URL for jing.jar, using the input version from workflow_dispatch
JING_VERSION="${{ github.event.inputs.JING_VERSION || '20091111' }}"
JING_URL="https://repo1.maven.org/maven2/com/thaiopensource/jing/${JING_VERSION}/jing-${JING_VERSION}.jar"
# Download jing.jar file for XML validation
curl -sL -f $JING_URL -o jing.jar
# Ensures the jar file is successfully downloaded, else exit with error
if [ ! -f jing.jar ]; then
echo "::error file=$JING_URL:: Failed to download jing.jar"
exit 1
fi
# Create a bash script to run jing.jar easily from the command line
echo '#!/bin/bash' > jing
echo 'java -jar jing.jar "$@"' >> jing
chmod +x jing
# Add paths of installed tools to GitHub Actions environment for easy access
echo "$(pwd)" >> $GITHUB_PATH
echo "/opt/homebrew/opt/openjdk/bin" >> $GITHUB_PATH
echo "/opt/homebrew/opt/libxml2/bin" >> $GITHUB_PATH
echo "/opt/homebrew/opt/libxslt/bin" >> $GITHUB_PATH
# Run the tests using pytest inside the created virtual environment
- name: Run tests
run: |
source .venv/bin/activate
pytest --cov=src -vv
env:
PYTHONSTARTMETHOD: spawn