Publish comment on PR #17
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
# This workflow will install Python dependencies, run benchmarks with airspeed velocity (asv) | |
# and publish the results to a dashboard on GH Pages. | |
name: Run benchmarks with airspeed velocity | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
permissions: | |
contents: write | |
env: | |
ASV_CONFIG_FILE: benchmarks/asv.conf.json | |
GENERATED_HTML_DIR: benchmarks/html | |
jobs: | |
run-asv: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Cache dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip | |
- name: Install asv and virtualenv | |
run: | | |
sudo apt-get update | |
python -m pip install --upgrade pip | |
pip install asv | |
pip install virtualenv | |
- name: Checkout project repository | |
uses: actions/checkout@v3 | |
- name: Create ASV machine config file | |
run: asv machine --config $ASV_CONFIG_FILE --yes -v | |
- name: Run ASV for current branch | |
run: asv run --config $ASV_CONFIG_FILE -v | |
publish-gh-pages: | |
if: ${{ github.event_name == 'push' }} | |
runs-on: ubuntu-latest | |
needs: run-asv | |
steps: | |
- name: Restore dependencies cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip | |
- name: Generate dashboard HTML | |
run: asv publish --config $ASV_CONFIG_FILE -v | |
- name: Deploy to Github pages | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
folder: $GENERATED_HTML_DIR | |
comment-pr: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
needs: run-asv | |
steps: | |
- name: Restore dependencies cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip | |
- name: Run comparison against main branch | |
run: asv compare --config $ASV_CONFIG_FILE main HEAD > results.txt | |
- name: Publish comment to PR | |
uses: actions/github-script@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const comment = fs.readFileSync('results.txt', 'utf-8'); | |
const { data } = await github.issues.createComment({ | |
...context.repo, | |
issue_number: context.issue.number, | |
body: comment, | |
}); | |
console.log("Comment published:", data.html_url); | |