Skip to content

Commit

Permalink
Merge pull request #28 from codecov/pr28
Browse files Browse the repository at this point in the history
initialize maturin package
  • Loading branch information
matt-codecov authored Aug 29, 2024
2 parents bd6fe6c + d7b9879 commit 1b43a89
Show file tree
Hide file tree
Showing 17 changed files with 387 additions and 12 deletions.
65 changes: 60 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,23 @@ jobs:
toolchain: nightly
components: clippy, rustfmt
- name: Run lint
run: make lint.rust

lint-python:
name: Lint Python (ruff, mypy)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Set up venv
run: make ci.setup_venv
- name: Build and run lint
run: |
cargo fmt --all --check
cargo clippy
maturin develop
make lint.python
build:
name: Build
Expand All @@ -43,6 +57,14 @@ jobs:
- name: Run build
run: |
cargo build
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install Python requirements
run: pip install -r python/requirements.dev.txt
- name: Build Python bindings
run: maturin build

test:
name: Test
runs-on: ubuntu-latest
Expand All @@ -55,9 +77,20 @@ jobs:
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
- name: Run tests
- name: Run Rust tests
run: |
cargo test
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Set up venv
run: make ci.setup_venv
- name: Run Python tests
run: |
maturin develop
pytest
# This job runs tests, generates coverage data, and generates JUnit test
# results in a single test invocation and then uploads it all to Codecov.
# However, it doesn't print test results to stdout. If Codecov's failed test
Expand All @@ -80,16 +113,38 @@ jobs:
- name: Run tests
run: |
cargo install cargo2junit
cargo llvm-cov --lcov --output-path lcov.info -- -Z unstable-options --format json --report-time | cargo2junit > results.xml
cargo llvm-cov --lcov --output-path core.lcov -- -Z unstable-options --format json --report-time | cargo2junit > core-test-results.xml
- uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Set up venv
run: make ci.setup_venv
- name: Run Python tests
run: |
# Clear prior profile data
cargo llvm-cov clean --workspace
# Set env vars so maturin will build our Rust code with coverage instrumentation
source <(cargo llvm-cov show-env --export-prefix)
maturin develop
# Run Python tests. Any Rust code exercised by these tests will emit coverage data
pytest --cov --junitxml=python-test-results.xml
# Turn the Rust coverage data into an lcov file
cargo llvm-cov --no-run --lcov --output-path bindings.lcov
- name: Upload coverage data to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v4
with:
files: ./core.lcov,./bindings.lcov,./.coverage
token: ${{ secrets.CODECOV_ORG_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
file: ./results.xml
files: ./core-test-results.xml,./python-test-results.xml
token: ${{ secrets.CODECOV_ORG_TOKEN }}
verbose: true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@ target/
# Vim swapfiles
.*.sw*

# Python junk
__pycache__/
*.py[cod]
*$py.class

# Native extensions for Python
*.so

.git
lcov.info
21 changes: 20 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: local
hooks:
- id: format
- id: rustfmt
name: cargo fmt
entry: cargo fmt
args: ["--check", "--"]
Expand All @@ -16,3 +16,22 @@ repos:
pass_filenames: false
types: [rust]
language: system
- id: ruffcheck
name: ruff check
entry: ruff check
require_serial: true
types: [python]
language: system
- id: rufffmt
name: ruff format
entry: ruff format
require_serial: true
types: [python]
language: system
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
hooks:
- id: mypy
verbose: true
entry: bash -c 'mypy "$@" || true' --
types: [python]
116 changes: 116 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]

resolver = "2"
members = ["core"]
members = ["bindings", "core"]
default-members = ["core"]

[profile.release]

Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
VENV_PATH := $(shell pwd)/.venv/bin:${PATH}

ci.setup_venv:
python3 -m venv .venv
echo "${VENV_PATH}" >> ${GITHUB_PATH}
PATH=${VENV_PATH} pip install -r python/requirements.dev.txt


lint.rust:
cargo fmt --all --check
cargo clippy

lint.python:
ruff check
ruff format
mypy
Loading

0 comments on commit 1b43a89

Please sign in to comment.