From 0c37e32981d4a403eff1e74ec5010872668128bd Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:36:19 +1300 Subject: [PATCH] :construction_worker: Setup benchmark workflow with pytest-codspeed (#4) * :heavy_plus_sign: Add pytest-codspeed Pytest plugin to create CodSpeed benchmarks! * :alembic: Decorate test_read_geotiff with pytest.mark.benchmark Will run benchmarks on this unit test soon! * :construction_worker: Setup benchmark workflow with pytest-codspeed Measuring the execution speed of unit tests to track performance of cog3pio Python functions over time. Using pytest-codspeed, see https://docs.codspeed.io/benchmarks/python#running-the-benchmarks-in-your-ci. * :truck: Rename test_read_geotiff to test_read_geotiff_local Might have other tests reading GeoTIFFs across the network, so renaming this unit test function. * :construction_worker: Don't re-run CI when PR is marked ready_for_review Also re-format the release-types: published trigger --- .github/workflows/benchmarks.yml | 59 ++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 4 +-- pyproject.toml | 1 + python/tests/test_io_geotiff.py | 3 +- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/benchmarks.yml diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml new file mode 100644 index 0000000..b14f930 --- /dev/null +++ b/.github/workflows/benchmarks.yml @@ -0,0 +1,59 @@ +# Run performance benchmarks +# +# Continuous benchmarking using pytest-codspeed. Measures the execution speed +# of tests marked with @pytest.mark.benchmark decorator. + +name: Benchmarks + +on: + # Run on pushes to the main branch + push: + branches: [ main ] + # Run on pull requests + pull_request: + types: [ opened, reopened, synchronize ] + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + release: + types: [ published ] + +jobs: + benchmarks: + runs-on: ubuntu-22.04 + defaults: + run: + shell: bash -l {0} + + steps: + # Checkout current git repository + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + # Setup Python interpreter + - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 + with: + python-version: '3.12' + + # Build binary distribution wheel + - name: Build wheels + uses: PyO3/maturin-action@60d11847b29f81ca5375519a8eb33cc336ba4bfa # v1.41.0 + with: + target: x86_64 + args: --release --out dist --find-interpreter + sccache: 'true' + manylinux: auto + + # Install the package that we want to test + - name: Install the package + run: | + set -e + python -m pip install cog3pio[tests] --find-links dist --force-reinstall + python -m pip list + + # Run the benchmark tests + - name: Run benchmarks + uses: CodSpeedHQ/action@2e04019f4572c19684929a755da499f19a00b25b # v2.2.1 + with: + run: | + python -m pytest --verbose --codspeed diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc3f39d..628f66e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,9 +9,9 @@ on: push: branches: [ "main" ] release: - types: [published] + types: [ published ] pull_request: - types: [opened, ready_for_review, reopened, synchronize] + types: [ opened, reopened, synchronize ] branches: [ "main" ] permissions: diff --git a/pyproject.toml b/pyproject.toml index 3b631f8..c01e625 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ dynamic = ["version"] [project.optional-dependencies] tests = [ "pytest", + "pytest-codspeed", ] [tool.maturin] diff --git a/python/tests/test_io_geotiff.py b/python/tests/test_io_geotiff.py index eec96bb..3b48a40 100644 --- a/python/tests/test_io_geotiff.py +++ b/python/tests/test_io_geotiff.py @@ -23,7 +23,8 @@ def fixture_geotiff_path(): yield geotiff_path -def test_read_geotiff(geotiff_path): +@pytest.mark.benchmark +def test_read_geotiff_local(geotiff_path): """ Read a GeoTIFF file from a local file path. """