|
21 | 21 | benchmark: |
22 | 22 | if: ${{ contains(github.event.pull_request.labels.*.name, 'run_benchmarks') || github.event_name == 'workflow_dispatch' }} |
23 | 23 | runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + pull-requests: write # allows posting the benchmark comment on the PR |
| 26 | + contents: read # allows checkout; prevents the token from pushing code or modifying workflows if exfiltrated by fork code |
| 27 | + actions: read # allows `gh cache list`; all other scopes default to none |
24 | 28 | env: |
25 | 29 | GH_TOKEN: ${{ github.token }} |
26 | 30 | strategy: |
|
38 | 42 | - uses: actions/checkout@v7 |
39 | 43 | with: |
40 | 44 | ref: ${{ github.event.pull_request.head.sha }} |
| 45 | + allow-unsafe-pr-checkout: true |
41 | 46 |
|
42 | 47 | - name: Filter changes |
43 | 48 | id: changes |
|
50 | 55 | - 'tests/benchmarks/compare_bench_results.py' |
51 | 56 | - 'setup.cfg' |
52 | 57 | - '.github/workflows/benchmark.yml' |
| 58 | + - 'requirements.txt' |
53 | 59 |
|
54 | 60 | - name: Check for relevant changes |
55 | 61 | id: check_changes |
@@ -119,6 +125,38 @@ jobs: |
119 | 125 | if: env.has_changes == 'true' |
120 | 126 | run: git checkout ${{ github.event.pull_request.head.sha }} -- tests/benchmarks |
121 | 127 |
|
| 128 | + - name: Remove PR virtual environment before master setup |
| 129 | + if: env.has_changes == 'true' |
| 130 | + run: rm -rf .venv-${{ env.version }} |
| 131 | + |
| 132 | + - name: Restore Python environment cache |
| 133 | + if: env.has_changes == 'true' |
| 134 | + id: restore-env2 |
| 135 | + uses: actions/cache/restore@v5 |
| 136 | + with: |
| 137 | + path: .venv-${{ env.version }} |
| 138 | + key: ${{ runner.os }}-venv-${{ env.version }}-${{ hashFiles('devtools/dev-requirements.txt', 'requirements.txt') }} |
| 139 | + |
| 140 | + - name: Set up virtual environment if not restored from cache |
| 141 | + if: steps.restore-env2.outputs.cache-hit != 'true' && env.has_changes == 'true' |
| 142 | + run: | |
| 143 | + gh cache list |
| 144 | + python -m venv .venv-${{ env.version }} |
| 145 | + source .venv-${{ env.version }}/bin/activate |
| 146 | + python -m pip install --upgrade pip |
| 147 | + pip install -r devtools/dev-requirements.txt |
| 148 | + pip install matplotlib==3.10.8 |
| 149 | +
|
| 150 | + - name: Action Details |
| 151 | + if: env.has_changes == 'true' |
| 152 | + run: | |
| 153 | + source .venv-${{ env.version }}/bin/activate |
| 154 | + which python |
| 155 | + python --version |
| 156 | + pwd |
| 157 | + lscpu |
| 158 | + pip list |
| 159 | +
|
122 | 160 | - name: Benchmark with pytest-benchmark (MASTER) |
123 | 161 | if: env.has_changes == 'true' |
124 | 162 | run: | |
|
0 commit comments