forked from nilearn/nilearn
-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (149 loc) · 7.11 KB
/
Copy pathbenchmark.yml
File metadata and controls
159 lines (149 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
# TL;DR: this workflow runs the benchmarks on the latest commit.
# It runs on PR
# On main, it will also run on a schedule at regular interval
# or can be triggered manually via the GitHub UI.
# When run on main it will deploy the updated benchmarks to
# `nilearn.github.io/benchmarks <https://nilearn.github.io/benchmarks/>`_.
#
# Step-wise details:
#
# - First it installs `asv <https://asv.readthedocs.io/en/latest/index.html>`_.
# - Then it sets up the SSH key to access the
# `benchmarks <https://github.com/nilearn/benchmarks>`_ repo,
# pulls it, and copies the results dir into the current dir. We will append
# the new results to these results.
# - ``asv machine --yes`` then fetches the machine info like CPU, RAM, OS,
# etc. and saves it in ``~/.asv-machine.json``, but it gives a unique name
# to the machine on every run even if the specs are the same. So we will set
# a fixed name for the machine so the legend isn't too overcrowded.
# - To do this, we edit the ``~/.asv-machine.json`` file to change the machine
# name to a fixed name ``fv-az1113-357``. The name is arbitrary and has been
# chosen to match the first run. The script
# ``build_tools/github/set_machine_name.py`` does all this.
# - Then we run the benchmarks (``asv run``) such that the results are
# appended to the old results (via ``--append-samples`` parameter).
# ``-ev`` makes sure any errors are printed in detail and all the output can
# be seen in the logs.
# - Then we create the HTML with all the results via ``asv publish``.
# - We upload the results as artifacts so that we can download them later.
# - Then we push the new results back to the
# `benchmarks <https://github.com/nilearn/benchmarks>`_ repo. This will
# automatically deploy the new results to
# `nilearn.github.io/benchmarks <https://nilearn.github.io/benchmarks/>`_.
###
name: Run and deploy Nilearn benchmarks
on:
pull_request:
branches:
- '*'
schedule:
# Uses the cron schedule for github actions
# https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
# Runs at 00:00, on day 1 of every 3rd month
- cron: 0 0 1 */3 *
# This enables manual triggering from GitHub UI
# https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflow_dispatch
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
FORCE_COLOR: true
MIN_PYTHON: 3.10.18
jobs:
benchmark:
if: github.repository == 'nilearn/nilearn'
runs-on: ubuntu-24.04
defaults:
run:
working-directory: ./asv_benchmarks
steps:
- uses: actions/checkout@v6
with:
# fetch all branches and tags
fetch-depth: 0
- uses: actions/setup-python@v6
with:
python-version: ${{ env.MIN_PYTHON }}
- name: Install asv and switch to asv_benchmarks directory
run: |
pip install --upgrade pip
pip install asv
pip install nilearn
- name: Add SSH key for benchmarks repo
if: github.event_name != 'pull_request'
env:
SSH_AUTH_SOCK: /tmp/ssh_agent_benchmarks.sock
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
echo "${{ secrets.UPLOAD_BENCHMARK_RESULTS }}" > ~/.ssh/github_actions
chmod 600 ~/.ssh/github_actions
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add ~/.ssh/github_actions
- name: Pull previous results from benchmarks repo
if: github.event_name != 'pull_request'
env:
SSH_AUTH_SOCK: /tmp/ssh_agent_benchmarks.sock
run: |
git clone git@github.com:nilearn/benchmarks.git benchmarks_repo
cp -r benchmarks_repo/results .
- name: Pull previous results from benchmarks repo (PR fallback)
if: github.event_name == 'pull_request'
run: |
# Use HTTPS for PRs (read-only)
git clone https://github.com/nilearn/benchmarks.git benchmarks_repo
cp -r benchmarks_repo/results .
- name: Get all the machine info
run: |
asv machine --yes 2>&1 | tee log_${{ github.event.repository.updated_at }}_${{ github.run_number }}
- name: Edit asv-machine.json to a custom machine name
run: python ../build_tools/github/set_machine_name.py fv-az1113-357
- name: Run all benchmarks on the latest commit
run: |
asv run --show-stderr --verbose --append-samples --parallel 2 --machine fv-az1113-357 2>&1 | tee log_${{ github.event.repository.updated_at }}_${{ github.run_number }}
- name: Create html with all results
run: |
asv publish
- uses: actions/upload-artifact@v7
with:
name: Upload asv benchmark results as artifacts
path: |
./asv_benchmarks/env
./asv_benchmarks/html
./asv_benchmarks/results
compression-level: 9
- name: Push new results and logs back to benchmarks repo
if: github.event_name != 'pull_request'
env:
SSH_AUTH_SOCK: /tmp/ssh_agent_benchmarks.sock
run: |
cd benchmarks_repo
cp -r ../results .
cp -r ../log_${{ github.event.repository.updated_at }}_${{ github.run_number }} ./logs/log_${{ github.event.repository.updated_at }}_${{ github.run_number }}
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add .
git commit --message "Update benchmark results and logs (${{ github.event.repository.updated_at }}_${{ github.run_number }})"
git push origin main
- name: Push html to gh-pages branch
if: github.event_name != 'pull_request'
env:
SSH_AUTH_SOCK: /tmp/ssh_agent_benchmarks.sock
run: |
cd benchmarks_repo
git checkout gh-pages
cp -r ../html/* .
git add .
git commit --message "Update benchmark HTML (${{ github.event.repository.updated_at }}_${{ github.run_number }})"
git push origin gh-pages