|
| 1 | +# Run performance benchmarks |
| 2 | +# |
| 3 | +# Continuous benchmarking using pytest-codspeed. Measures the execution speed |
| 4 | +# of tests marked with @pytest.mark.benchmark decorator. |
| 5 | + |
| 6 | +name: Benchmarks |
| 7 | + |
| 8 | +on: |
| 9 | + # Run on pushes to the main branch |
| 10 | + push: |
| 11 | + branches: [ main ] |
| 12 | + paths: |
| 13 | + - 'pygmt/**/*.py' |
| 14 | + - '!pygmt/tests/**' |
| 15 | + - '.github/workflows/benchmarks.yml' |
| 16 | + pull_request: |
| 17 | + paths: |
| 18 | + - 'pygmt/**/*.py' |
| 19 | + - '!pygmt/tests/**' |
| 20 | + - '.github/workflows/benchmarks.yml' |
| 21 | + # `workflow_dispatch` allows CodSpeed to trigger backtest |
| 22 | + # performance analysis in order to generate initial data. |
| 23 | + workflow_dispatch: |
| 24 | + release: |
| 25 | + types: |
| 26 | + - published |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 30 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 31 | + |
| 32 | +jobs: |
| 33 | + benchmarks: |
| 34 | + runs-on: ubuntu-22.04 |
| 35 | + defaults: |
| 36 | + run: |
| 37 | + shell: bash -l {0} |
| 38 | + |
| 39 | + steps: |
| 40 | + # Checkout current git repository |
| 41 | + - name: Checkout |
| 42 | + |
| 43 | + with: |
| 44 | + # fetch all history so that setuptools-scm works |
| 45 | + fetch-depth: 0 |
| 46 | + |
| 47 | + # Install Miniconda with conda-forge dependencies |
| 48 | + - name: Setup Miniconda |
| 49 | + uses: conda-incubator/[email protected] |
| 50 | + with: |
| 51 | + auto-activate-base: true |
| 52 | + activate-environment: "" # base environment |
| 53 | + channels: conda-forge,nodefaults |
| 54 | + channel-priority: strict |
| 55 | + |
| 56 | + # Install GMT and dependencies from conda-forge |
| 57 | + - name: Install dependencies |
| 58 | + run: | |
| 59 | + # $CONDA is an environment variable pointing to the root of the miniconda directory |
| 60 | + # Preprend $CONDA/bin to $PATH so that conda's python is used over system python |
| 61 | + echo $CONDA/bin >> $GITHUB_PATH |
| 62 | + conda install --solver=libmamba gmt=6.4.0 python=3.12 \ |
| 63 | + numpy pandas xarray netCDF4 packaging \ |
| 64 | + pytest pytest-benchmark pytest-mpl |
| 65 | + python -m pip install -U pytest-codspeed setuptools |
| 66 | +
|
| 67 | + # Install the package that we want to test |
| 68 | + - name: Install the package |
| 69 | + run: make install |
| 70 | + |
| 71 | + # Run the benchmark tests |
| 72 | + - name: Run benchmarks |
| 73 | + uses: CodSpeedHQ/[email protected] |
| 74 | + with: |
| 75 | + run: | |
| 76 | + python -c "import pygmt; pygmt.show_versions()" |
| 77 | + PYGMT_USE_EXTERNAL_DISPLAY="false" python -m pytest -r P --pyargs pygmt --codspeed |
| 78 | + env: |
| 79 | + GMT_LIBRARY_PATH: /usr/share/miniconda/lib/ |
0 commit comments