Skip to content

Improve performance comment #54

Improve performance comment

Improve performance comment #54

Workflow file for this run

# 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 ASV
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
PYTHON_VERSION: "3.10"
WORKING_DIR: ${{ github.workspace }}/benchmarks
jobs:
setup-dependencies:
runs-on: ubuntu-latest
steps:
- name: Cache Python ${{ env.PYTHON_VERSION }}
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: python-${{ env.PYTHON_VERSION }}
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install dependencies
run: |
sudo apt-get update
python -m pip install --upgrade pip
pip install asv virtualenv tabulate
asv-main:
runs-on: ubuntu-latest
needs: setup-dependencies
permissions:
contents: write
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- name: Checkout main branch of the repository
uses: actions/checkout@v3
- name: Cache Python ${{ env.PYTHON_VERSION }}
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: python-${{ env.PYTHON_VERSION }}
- name: Create ASV machine config file
run: asv machine --yes
- name: Run ASV for the main branch
run: asv run
- name: Generate dashboard HTML
run: asv publish
- name: Deploy to Github pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: html
asv-pr:
runs-on: ubuntu-latest
needs: setup-dependencies
permissions:
actions: read
pull-requests: write
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- name: Checkout PR branch of the repository
uses: actions/checkout@v3
- name: Cache Python ${{ env.PYTHON_VERSION }}
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: python-${{ env.PYTHON_VERSION }}
- name: Get current job logs URL
uses: Tiryoh/gha-jobid-action@v0
id: jobs
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
job_name: ${{ github.job }}
- name: Run comparison of PR against main branch
run: |
git remote add upstream ${{ github.repositoryUrl }}
git fetch upstream
asv continuous upstream/main HEAD
asv compare upstream/main HEAD --sort ratio | tee output
python format.py
printf "\n\nClick [here]($STEP_URL) to view all benchmarks." >> output
env:
STEP_URL: "${{ steps.jobs.outputs.html_url }}#step:6:1"
- name: Publish comment to PR
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
const workingDir = process.env.WORKING_DIR;
try {
process.chdir(workingDir);
const comment = fs.readFileSync('output', 'utf-8');
const { data } = await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: comment,
});
console.log('Comment published:', data.html_url);
} catch (err) {
console.error(err);
}