forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (162 loc) · 6.4 KB
/
bench_matrix.yml
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Run all benchmarks when a comment containing "test performance please"
# comment is posted on a PR.
name: Benchmarks Matrix
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
commit:
description: "Commit to benchmark."
required: true
type: string
repo:
description: "GitHub repository containing the commit to benchmark."
required: true
type: string
default: "mbovel/scala3" # TODO(mbovel): Change to scala/scala3
runs:
description: "Number of runs to perform."
required: true
type: number
default: 1
profile:
description: "Profile to run: 'merge' to run the benchmarks that are run on every PR merge (shorter), 'nightly' to run nightly benchmarks (longer), or 'all' to run both."
required: true
type: choice
options:
- merge
- nightly
- all
jobs:
start_comment:
name: Start comment
if: github.event_name == 'issue_comment'
runs-on: ubuntu-latest
steps:
- name: Comment
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Thanks for your request. Your benchmarks will be run shortly.\nYou can follow the progress at https://github.com/mbovel/dotty/actions/runs/${context.runId}.`
})
generate_runs:
name: Generate run definitions
if: github.event_name == 'workflow_dispatch' || (github.event.issue.pull_request && contains(github.event.comment.body, 'test performance please'))
runs-on: ['self-hosted', 'benchmarks']
env:
# Path to the directory where the benchmark data is stored on the runner.
# Keep in sync with the value in .github/workflows/bench.yml.
DATA_DIR: /home/scalabenchs/bench-data-v3
steps:
- id: generate_runs
uses: actions/github-script@v7
with:
script: |
async function get_commits() {
if (context.eventName === 'issue_comment') {
const {data} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.issue.number
});
const base = {
commit: data.base.sha,
repo: data.base.repo.full_name
};
core.setOutput('base', base.commit);
const head = {
commit: data.head.sha,
repo: data.head.repo.full_name
};
core.setOutput('head', head.commit);
return [base, head];
} else if (context.eventName === 'workflow_dispatch') {
return [{
commit: context.payload.inputs.commit,
repo: context.payload.inputs.repo
}];
} else {
throw new Error(`Unsupported event: ${context.eventName}`);
}
}
function get_run_indices() {
if (context.eventName === 'issue_comment') {
return [0];
} else if (context.eventName === 'workflow_dispatch') {
return Array.from({ length: context.payload.inputs.runs }, (_, i) => i);
} else {
throw new Error(`Unsupported event: ${context.eventName}`);
}
}
function get_profile() {
if (context.eventName === 'issue_comment') {
return context.payload.comment.body.includes('all') ? 'all' : 'merge';
} else if (context.eventName === 'workflow_dispatch') {
return context.payload.inputs.profile;
} else {
throw new Error(`Unsupported event: ${context.eventName}`);
}
}
const commits = await get_commits();
const run_indices = get_run_indices();
const profile = get_profile();
const is_nightlys = profile === 'all' ? [false, true] : [profile === 'nightly'];
const fs = require('fs');
const runs = [];
for (const run_index of run_indices) {
for (const commit of commits) {
for (const is_nightly of is_nightlys) {
const dataCsv = `${process.env.DATA_DIR}/raw/${commit.commit}/${is_nightly ? 'nightly' : 'merge'}-${run_index}.csv`;
if (fs.existsSync(dataCsv)) {
console.log(`Run ${run_index} for commit ${commit.commit} with profile ${profile} has already been performed.`);
} else {
console.log(`Scheduling run ${run_index} for commit ${commit.commit} with profile ${profile}.`);
runs.push({
commit: commit.commit,
repo: commit.repo,
index: run_index,
is_nightly: is_nightly
});
}
}
}
}
core.setOutput('runs', JSON.stringify(runs));
core.setOutput('visualizer_url', `https://dotty-bench.epfl.ch/v3/compare.html#${commits.map(c => c.commit).join(',')}`);
outputs:
runs: ${{ steps.generate_runs.outputs.runs }}
visualizer_url: ${{ steps.generate_runs.outputs.visualizer_url }}
run:
name: Run
needs: ['generate_runs']
strategy:
matrix:
run: ${{fromJson(needs.generate_runs.outputs.runs)}}
max-parallel: 1
uses: ./.github/workflows/bench.yml
with:
commit: ${{ matrix.run.commit }}
repo: ${{ matrix.run.repo }}
run: ${{ matrix.run.index }}
is_nightly: ${{ matrix.run.is_nightly }}
finish_comment:
name: Finish comment
needs: ['run']
if: github.event_name == 'issue_comment'
runs-on: ubuntu-latest
steps:
- name: Comment
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: 'Your benchmarks have been run. You can see the results at ${{ needs.generate_runs.outputs.visualizer_url }}.'
})