Add ruff-format and support for python 3.12 #246
Workflow file for this run
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: Benchmark | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
permissions: | |
pull-requests: write | |
contents: read | |
jobs: | |
benchmark: | |
if: github.event_name == 'push' || !contains(github.event.pull_request.labels.*.name, 'no benchmark') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up conda env | |
uses: mamba-org/setup-micromamba@v1 | |
with: | |
environment-file: environment-deprecated.yml | |
cache-environment: true | |
create-args: python=3.11 | |
- name: Install repository | |
run: python -m pip install --no-build-isolation --no-deps --disable-pip-version-check -e . | |
shell: bash -el {0} | |
- name: Cache models | |
uses: actions/cache@v3 | |
env: | |
cache-name: benchmark-model-cache | |
with: | |
path: examples/benchmark_models | |
key: models-${{ hashFiles('benchmark.py', '.github/workflows/benchmark.yml') }} | |
- name: Run benchmark | |
shell: bash -el {0} | |
run: | | |
python benchmark.py | |
echo "_(benchmark **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_" >> result.md | |
cat benchmark.md >> result.md | |
- name: Comment on PR | |
# thollander/actions-comment-pull-request is not whitelisted | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
with: | |
script: | | |
fs = require('fs') | |
const createOrUpdateComment = async ( | |
content, | |
) => { | |
// Get all comments | |
const comments = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}) | |
// Check if any of the comments was posted by the bot and could be replaced | |
for (const comment of comments.data) { | |
if (comment.user?.login === 'github-actions[bot]') { | |
await github.rest.issues.updateComment({ | |
comment_id: comment.id, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: content | |
}) | |
return | |
} | |
} | |
// If not, post a new comment | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: content, | |
}) | |
} | |
createOrUpdateComment(fs.readFileSync('result.md', 'utf8')) | |
- name: Add benchmark to Job Summary | |
run: cat benchmark.md >> "$GITHUB_STEP_SUMMARY" |