Merge pull request #814 from gchq/chore/pre-commit-autoupdate #172
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Performance | |
# Monitor performance of Coreax code. | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- "**" | |
jobs: | |
performance-check: | |
name: Check performance | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
gist_id: 3707a122b3697109068a3e55487de4fc | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up base Python | |
uses: actions/setup-python@v5 | |
with: | |
# Note that this is just the version of Python that we use to run `uv` with. | |
# `uv` manages its own version of Python. | |
# For speed, we use the same version for both, but in principle these could differ. | |
python-version: 3.12 | |
- name: Set up uv cache directory location (Linux/Mac) | |
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $GITHUB_ENV | |
if: runner.os != 'Windows' | |
- name: Set up uv cache directory location (Windows) | |
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $env:GITHUB_ENV | |
if: runner.os == 'Windows' | |
- name: Restore uv cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.UV_CACHE_DIR }} | |
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}-none | |
restore-keys: | | |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }} | |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} | |
uv-${{ runner.os }} | |
- name: Install latest versions of pip and uv | |
run: python -m pip install --upgrade pip uv | |
- name: Install package dependencies | |
run: uv sync --no-dev --locked | |
- name: Debug - uv pip freeze | |
run: uv pip freeze | |
- name: Assess performance | |
run: uv run tests/performance/run.py --output-file $RUNNER_TEMP/performance.json | |
- name: Download historic performance data | |
if: github.event_name == 'pull_request' | |
run: gh gist clone ${{ env.gist_id }} $RUNNER_TEMP/historic | |
- name: Compare performance against historic data | |
if: github.event_name == 'pull_request' | |
run: | | |
# save the commit subject to a file in case it contains any shell | |
# special characters | |
git log -1 --pretty=%s > $RUNNER_TEMP/commit_subject.txt | |
uv run tests/performance/compare.py \ | |
$RUNNER_TEMP/performance.json \ | |
$RUNNER_TEMP/historic \ | |
--commit-short-hash $(git log -1 --pretty=%h) \ | |
--commit-subject-file $RUNNER_TEMP/commit_subject.txt \ | |
> $RUNNER_TEMP/comment.md | |
cat $RUNNER_TEMP/comment.md | |
- name: Comment performance update on PR | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
var fs = require('fs'); | |
const RUNNER_TEMP = process.env.RUNNER_TEMP | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: fs.readFileSync(`${RUNNER_TEMP}/comment.md`, "utf8") | |
}) | |
- name: Save performance data to Gist | |
if: github.event_name == 'push' | |
env: | |
# this is the only step that should actually need write permissions | |
GITHUB_TOKEN: ${{ secrets.COVERAGE_GIST_KEY }} | |
run: | | |
OUT_NAME="performance-$(date --utc +%Y-%m-%d--%H-%M-%S)--$GITHUB_SHA--v1.json" | |
gh gist edit ${{ env.gist_id }} -a $OUT_NAME $RUNNER_TEMP/performance.json | |
- name: Minimize UV cache | |
run: uv cache prune --ci | |
if: always() |