diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f92686..d514b35 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,22 @@ name: Build on: [push, pull_request] jobs: + pre-commit: + name: Run pre-commit hooks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: astral-sh/setup-uv@v5 + - uses: actions/setup-python@v5 + with: + python-version-file: pyproject.toml + + - name: Install the project + run: uv sync --locked --dev + + - name: Run pre-commit hooks + uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd + build-wheels: name: Build wheels for ${{ matrix.os }} runs-on: ${{ matrix.runs-on }} @@ -36,16 +52,15 @@ jobs: if: matrix.os == 'linux-intel' id: get-coverage-files run: | - FILES=$(find ./wheelhouse -type f -name 'coverage*' -printf '%p ') + FILES=$(find ./wheelhouse -type f -name '.coverage*' -printf '%p ') echo "Found coverage files: $FILES" echo "files=$FILES" >> $GITHUB_OUTPUT - - name: Coveralls + - name: Upload to Coveralls if: matrix.os == 'linux-intel' uses: coverallsapp/github-action@v2 with: files: ${{ steps.get-coverage-files.outputs.files }} - format: lcov build-sdist: name: Build source distribution @@ -65,7 +80,7 @@ jobs: upload-pypi: name: Publish to PyPI - needs: [build-wheels, build-sdist] + needs: [pre-commit, build-wheels, build-sdist] runs-on: ubuntu-latest environment: pypi permissions: diff --git a/scripts/save_coverage.py b/scripts/save_coverage.py index 467b770..53e4aa0 100755 --- a/scripts/save_coverage.py +++ b/scripts/save_coverage.py @@ -1,13 +1,18 @@ #!/usr/bin/env python import os -import shutil +import re import traceback import uuid +from pathlib import Path try: if os.getenv("RUNNER_OS") == "Linux": + coverage = Path("coverage.lcov").read_text() + coverage = re.sub( + r"^(SF:).*?/site-packages/", r"\1src/", coverage, flags=re.MULTILINE + ) os.makedirs("/output", exist_ok=True) - shutil.move("coverage.lcov", f"/output/coverage.{uuid.uuid4().hex}.lcov") + Path(f"/output/.coverage.{uuid.uuid4().hex}.lcov").write_text(coverage) except Exception: traceback.print_exc()