Skip to content

Cleanup codestyle workflow #3634

Cleanup codestyle workflow

Cleanup codestyle workflow #3634

Workflow file for this run

name: benchmarks
on:
push:
branches:
- master
pull_request_target:
branches:
- master
types:
- opened
- reopened
- synchronize
- labeled # benchmarks label required
- ready_for_review
workflow_dispatch:
env:
DEPLOY_BRANCH: main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash -l {0}
jobs:
build:
if: github.repository_owner == 'tardis-sn' &&
(github.event_name == 'push' ||
(!github.event.pull_request.draft) ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request_target' &&
contains(github.event.pull_request.labels.*.name, 'benchmarks')))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: github.event_name != 'pull_request_target'
with:
fetch-depth: 0
- name: Checkout PR and master branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
if: github.event_name == 'pull_request_target'
- name: Fetch master branch
run: git fetch origin master:master
if: github.event_name == 'pull_request_target'
- name: Setup LFS
uses: ./.github/actions/setup_lfs
- name: Setup Mamba
uses: mamba-org/setup-micromamba@v1
with:
environment-name: benchmark
init-shell: >-
bash
create-args: >-
python
asv=0.6.4
mamba
conda-build
conda=24.9.0
- name: Accept all asv questions
run: asv machine --yes
- name: Run benchmarks for last 4 commits if not PR
if: github.event_name != 'pull_request_target'
run: |
git log -n 4 --pretty=format:"%H" >> tag_commits.txt
asv run -a rounds=1 HASHFILE:tag_commits.txt | tee asv-output.log
if grep -q failed asv-output.log; then
echo "Some benchmarks have failed!"
exit 1
fi
- name: Generate Graphs and HTML
if: github.event_name != 'pull_request_target'
run: asv publish
- name: Delete env files
if: github.event_name != 'pull_request_target'
run: rm -r .asv/env
- name: Deploy asv page
if: github.event_name != 'pull_request_target'
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.BOT_TOKEN }}
publish_branch: ${{ env.DEPLOY_BRANCH }}
publish_dir: .asv/html
keep_files: true
external_repository: tardis-sn/tardis-benchmarks
user_name: "TARDIS Bot"
user_email: "tardis.sn.bot@gmail.com"
- name: Run benchmarks for base and head commits of PR
if: github.event_name == 'pull_request_target'
run: |
echo $(git rev-parse HEAD) > commit_hashes.txt
echo $(git rev-parse master) >> commit_hashes.txt
asv run -a rounds=1 HASHFILE:commit_hashes.txt | tee asv-output-PR.log
if grep -q failed asv-output-PR.log; then
echo "Some benchmarks have failed!"
exit 1
fi
- name: Compare Master and PR head
run: asv compare origin/master HEAD --factor 1.1 --split --sort ratio | tee asv-compare-output.log
- name: Compare Master and PR head but only show changed results
run: asv compare origin/master HEAD --only-changed --factor 1.1 --split --sort ratio | tee asv-compare-changed-output.log
- name: Benchmarks compare output
id: asv_pr_vs_master
uses: juliangruber/read-file-action@v1.0.0
with:
path: asv-compare-output.log
- name: Benchmarks compare only changed output
id: asv_pr_vs_master_changed
uses: juliangruber/read-file-action@v1.0.0
with:
path: asv-compare-changed-output.log
- name: Generate Graphs and HTML of PR
if: github.event_name == 'pull_request_target'
run: |
asv publish
- name: Delete env files of PR
if: github.event_name == 'pull_request_target'
run: rm -r .asv/env
- name: Set destination directory
if: github.event_name == 'pull_request_target'
run: |
BRANCH=$(echo ${GITHUB_REF#refs/heads/})
if [[ $EVENT == push ]] || [[ $EVENT == workflow_dispatch ]]; then
if [[ $BRANCH == $DEFAULT ]]; then
echo "DEST_DIR=" >> $GITHUB_ENV
else
echo "DEST_DIR=branch/$BRANCH" >> $GITHUB_ENV
fi
elif [[ $EVENT == pull_request_target ]]; then
echo "DEST_DIR=pull/$PR" >> $GITHUB_ENV
else
echo "Unexpected event trigger $EVENT"
exit 1
fi
cat $GITHUB_ENV
env:
DEFAULT: ${{ github.event.repository.default_branch }}
EVENT: ${{ github.event_name }}
PR: ${{ github.event.number }}
- name: Set clean branch option
if: github.event_name == 'pull_request_target'
run: |
if [[ $EVENT == workflow_dispatch ]]; then
echo "CLEAN_BRANCH=true" >> $GITHUB_ENV
else
echo "CLEAN_BRANCH=false" >> $GITHUB_ENV
fi
cat $GITHUB_ENV
env:
EVENT: ${{ github.event_name }}
- name: Deploy ${{ env.DEST_DIR }}
if: github.event_name == 'pull_request_target'
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.BOT_TOKEN }}
publish_branch: ${{ env.DEPLOY_BRANCH }}
publish_dir: .asv/html
destination_dir: ${{ env.DEST_DIR }}
keep_files: true
force_orphan: ${{ env.CLEAN_BRANCH }}
external_repository: tardis-sn/tardis-benchmarks
user_name: "TARDIS Bot"
user_email: "tardis.sn.bot@gmail.com"
- name: Find Comment
if: always() && github.event_name == 'pull_request_target'
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: I ran benchmarks as you asked
- name: Post comment
if: github.event_name == 'pull_request_target'
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.BOT_TOKEN }}
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
*\*beep\* \*bop\**
Hi human,
I ran benchmarks as you asked comparing master (${{ github.event.pull_request.base.sha }}) and the latest commit (${{ github.event.pull_request.head.sha }}).
Here are the logs produced by ASV.
Results can also be downloaded as artifacts [**here**](${{ env.URL }}).
Significantly changed benchmarks:
<details>
```diff
${{ steps.asv_pr_vs_master_changed.outputs.content }}
```
</details>
All benchmarks:
<details>
```diff
${{ steps.asv_pr_vs_master.outputs.content }}
```
</details>
If you want to see the graph of the results, you can check it [**here**](${{ env.URL_PAGES }})
env:
URL: https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }}?check_suite_focus=true
URL_PAGES: https://tardis-sn.github.io/tardis-benchmarks/pull/${{ github.event.number }}
- name: Save results artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: asv-benchmark-results-${{ runner.os }}
path: |
.asv/results
asv-compare-output.log
asv-compare-changed-output.log