chore(deps): autoupdate pre-commit hooks #505
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 | |
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' | |
uses: actions/checkout@v4 | |
with: | |
repository: gchq/coreax-metadata | |
# GitHub Actions require check out destination to be within coreax/coreax. To | |
# save checking out the main repo into coreax/coreax/coreax, check out the | |
# metadata repo to a nested location inside coreax/coreax. Pick a folder name | |
# that is very unlikely to clash with any current or future folder name | |
# committed to the main coreax repo. | |
path: tmp_coreax-metadata | |
- name: Compare performance against historic data | |
if: github.event_name == 'pull_request' | |
env: | |
HISTORIC: tmp_coreax-metadata/performance | |
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 | |
# Create directory if it doesn't exist yet | |
mkdir -p $HISTORIC | |
uv run tests/performance/compare.py \ | |
$RUNNER_TEMP/performance.json \ | |
$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: Generate a token for saving performance data | |
id: generate-token | |
uses: actions/create-github-app-token@v1 | |
with: | |
app-id: ${{ vars.WRITE_CONTENTS_PR_APP }} | |
private-key: ${{ secrets.WRITE_CONTENTS_PR_KEY }} | |
repositories: coreax-metadata | |
- name: Save performance data | |
if: github.event_name == 'push' | |
env: | |
# this is the only step that should actually need write permissions | |
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} | |
run: | | |
export message="chore: update performance for $GITHUB_SHA" | |
export content=$( base64 -i $RUNNER_TEMP/performance.json ) | |
OUT_NAME="performance/performance-$(date --utc +%Y-%m-%d--%H-%M-%S)--$GITHUB_SHA--v1.json" | |
gh api --method PUT \ | |
/repos/:owner/coreax-metadata/contents/$OUT_NAME \ | |
-f message="$message" \ | |
-f content="$content" | |
- name: Minimize UV cache | |
run: uv cache prune --ci | |
if: always() |