Browse Source

Fix coverage action and add pre-commit hook action

tags/v0.7.1
Ben Kurtovic 1 year ago
parent
commit
8ac8a66c01
2 changed files with 26 additions and 6 deletions
  1. +19
    -4
      .github/workflows/build.yml
  2. +7
    -2
      scripts/save_coverage.py

+ 19
- 4
.github/workflows/build.yml View File

@@ -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:


+ 7
- 2
scripts/save_coverage.py View File

@@ -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()

Loading…
Cancel
Save