1313 paths :
1414 - ' src/**'
1515 - ' tests/**'
16+
1617concurrency :
1718 group : ${{ github.workflow }}-${{ github.ref }}
1819 cancel-in-progress : true
20+
1921permissions :
2022 contents : read
2123 packages : read
24+ pull-requests : write
2225
2326jobs :
2427 test-ubuntu :
5659 jq \
5760 rsvg-convert \
5861 openssh-clients || true
59-
62+
6063 - name : Setup Python
6164 uses : actions/setup-python@v5
6265 with :
@@ -79,19 +82,51 @@ jobs:
7982 # CRITICAL FIX: Ensure coverage tools are installed for the CI runner
8083 pip install coverage pytest-cov
8184
82- - name : Run tests and Report Coverage # Unified step for test execution and reporting
85+ - name : Run tests and Report Coverage
8386 run : |
8487 source .venv/bin/activate
8588 # 1. Run tests and collect coverage for src/ and tests/
86- pytest --cov=src --cov=tests --cov-report=term-missing -vv
87-
88- # 2. Combine and report data (needed after parallel execution)
89+ pytest --cov=src --cov=tests --cov-report=term-missing -vv
90+
91+ # 2. Combine data
8992 python -m coverage combine --append || true
90- python -m coverage report
93+
94+ # 3. Generate report and save to file (using tee to see it in logs too)
95+ python -m coverage report | tee coverage.txt
96+
97+ # 4. Cleanup coverage data
9198 python -m coverage erase # Final cleanup
9299 env :
93100 PYTHONSTARTMETHOD : spawn
94-
101+
102+ - name : Create Coverage Comment for ${{ github.event.pull_request.head.sha || github.sha }}
103+ if : success() && github.event_name == 'pull_request' && matrix.python-version == '3.12'
104+ env :
105+ # Use the PR head if available, otherwise fallback to the workflow SHA
106+ COMMIT_SHA : ${{ github.event.pull_request.head.sha || github.sha }}
107+ run : |
108+ # Get the short SHA (e.g., a1b2c3d)
109+ SHORT_SHA=${COMMIT_SHA::7}
110+ # Create the comment content with markdown formatting:
111+ echo "## Coverage Report" > coverage_comment.txt
112+ echo "For commit $SHORT_SHA" >> coverage_comment.txt
113+ echo "" >> coverage_comment.txt
114+
115+ echo "<details><summary>Click to expand Coverage Report</summary>" >> coverage_comment.txt
116+ echo "" >> coverage_comment.txt
117+ echo "\`\`\`" >> coverage_comment.txt
118+ cat coverage.txt >> coverage_comment.txt
119+ echo "\`\`\`" >> coverage_comment.txt
120+ echo "</details>" >> coverage_comment.txt
121+ cat coverage_comment.txt
122+
123+ - name : Post Coverage Comment
124+ if : success() && github.event_name == 'pull_request' && matrix.python-version == '3.12'
125+ uses : marocchino/sticky-pull-request-comment@v2
126+ with :
127+ path : coverage_comment.txt
128+ header : coverage
129+
95130 test-macos :
96131 name : macos-python-${{ matrix.python-version }}
97132 runs-on : macos-latest
@@ -102,21 +137,21 @@ jobs:
102137 steps :
103138 - name : Checkout repository
104139 uses : actions/checkout@v4
105-
140+
106141 # Set up Python on macOS environment
107142 - name : Setup Python
108143 uses : actions/setup-python@v5
109144 with :
110145 python-version : ${{ matrix.python-version }}
111-
146+
112147 # Install uv and project dependencies inside a virtual environment
113148 - name : Install uv and dependencies
114149 run : |
115150 python3 -m venv .venv
116151 source .venv/bin/activate
117152 pip install uv
118153 uv pip install --editable . --group devel
119-
154+
120155 # Install macOS-specific external tools (such as XML parsers and Java)
121156 - name : Install external tools (macOS)
122157 run : |
@@ -128,7 +163,7 @@ jobs:
128163
129164 # Download jing.jar file for XML validation
130165 curl -sL -f $JING_URL -o jing.jar
131-
166+
132167 # Ensures the jar file is successfully downloaded, else exit with error
133168 if [ ! -f jing.jar ]; then
134169 echo "::error file=$JING_URL:: Failed to download jing.jar"
@@ -150,6 +185,6 @@ jobs:
150185 - name : Run tests
151186 run : |
152187 source .venv/bin/activate
153- pytest --cov=src -vv
188+ pytest --cov=src -vv
154189 env :
155- PYTHONSTARTMETHOD : spawn
190+ PYTHONSTARTMETHOD : spawn
0 commit comments