Skip to content

Commit 8ac8a66

Browse files
committed
Fix coverage action and add pre-commit hook action
1 parent 2a04a68 commit 8ac8a66

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ name: Build
22
on: [push, pull_request]
33

44
jobs:
5+
pre-commit:
6+
name: Run pre-commit hooks
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: astral-sh/setup-uv@v5
11+
- uses: actions/setup-python@v5
12+
with:
13+
python-version-file: pyproject.toml
14+
15+
- name: Install the project
16+
run: uv sync --locked --dev
17+
18+
- name: Run pre-commit hooks
19+
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd
20+
521
build-wheels:
622
name: Build wheels for ${{ matrix.os }}
723
runs-on: ${{ matrix.runs-on }}
@@ -36,16 +52,15 @@ jobs:
3652
if: matrix.os == 'linux-intel'
3753
id: get-coverage-files
3854
run: |
39-
FILES=$(find ./wheelhouse -type f -name 'coverage*' -printf '%p ')
55+
FILES=$(find ./wheelhouse -type f -name '.coverage*' -printf '%p ')
4056
echo "Found coverage files: $FILES"
4157
echo "files=$FILES" >> $GITHUB_OUTPUT
4258
43-
- name: Coveralls
59+
- name: Upload to Coveralls
4460
if: matrix.os == 'linux-intel'
4561
uses: coverallsapp/github-action@v2
4662
with:
4763
files: ${{ steps.get-coverage-files.outputs.files }}
48-
format: lcov
4964

5065
build-sdist:
5166
name: Build source distribution
@@ -65,7 +80,7 @@ jobs:
6580

6681
upload-pypi:
6782
name: Publish to PyPI
68-
needs: [build-wheels, build-sdist]
83+
needs: [pre-commit, build-wheels, build-sdist]
6984
runs-on: ubuntu-latest
7085
environment: pypi
7186
permissions:

scripts/save_coverage.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#!/usr/bin/env python
22

33
import os
4-
import shutil
4+
import re
55
import traceback
66
import uuid
7+
from pathlib import Path
78

89
try:
910
if os.getenv("RUNNER_OS") == "Linux":
11+
coverage = Path("coverage.lcov").read_text()
12+
coverage = re.sub(
13+
r"^(SF:).*?/site-packages/", r"\1src/", coverage, flags=re.MULTILINE
14+
)
1015
os.makedirs("/output", exist_ok=True)
11-
shutil.move("coverage.lcov", f"/output/coverage.{uuid.uuid4().hex}.lcov")
16+
Path(f"/output/.coverage.{uuid.uuid4().hex}.lcov").write_text(coverage)
1217
except Exception:
1318
traceback.print_exc()

0 commit comments

Comments
 (0)