-
Notifications
You must be signed in to change notification settings - Fork 483
136 lines (118 loc) · 4.52 KB
/
manual-benchmark.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
# This workflows checks for comments in PRs. If the comment has this format:
# /benchmark NAME
# Then this action will run the benchmark with the given NAME, first against
# the current branch and then comparing the results against the master branch.
name: "🚀 Manual Benchmark"
on:
issue_comment:
types: [created]
jobs:
run:
name: Run
runs-on: [self-hosted, plutus-benchmark]
permissions:
pull-requests: write
if: |
startsWith(github.event.comment.body, '/benchmark') &&
github.event.issue.pull_request
steps:
- name: Checkout
uses: actions/checkout@main
with:
# We need at least one commit before master to compare against
fetch-depth: 5
- name: React With Rocket
uses: actions/github-script@main
with:
script: |
github.rest.reactions.createForIssueComment({
owner: context.issue.owner,
repo: context.issue.repo,
comment_id: context.payload.comment.id,
content: "rocket"
});
- name: Extract Benchmark Name
id: extract-benchmark
uses: actions/github-script@main
with:
script: |
const regex = /^\/benchmark\s*([^\s]*)\s*$/;
const comment = context.payload.comment.body;
const match = comment.match(regex)
if (match !== null && match.length == 2 && match[1] !== '') {
core.setOutput('benchmark', match[1]);
} else {
core.setFailed(`Unable to extract benchmark name from comment '${comment}'`);
}
- name: Extract Branch Name
id: extract-branch
uses: actions/github-script@main
with:
script: |
async function isPullRequest() {
const result = await github.rest.issues.get({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: context.issue.number
});
return !!result.data.pull_request;
}
async function getCommentHeadRef() {
const query = `
query pullRequestDetails($repo:String!, $owner:String!, $number:Int!) {
repository(name: $repo, owner: $owner) {
pullRequest(number: $number) {
headRef {
name
}
}
}
}`;
const result = await github.graphql(query, {
owner: context.issue.owner,
repo: context.issue.repo,
number: context.issue.number
});
return result.repository.pullRequest.headRef.name;
}
try {
if (!await isPullRequest()) {
core.setFailed("Comment is not on a pull request");
} else {
core.setOutput("head_ref", await getCommentHeadRef());
}
} catch (error) {
core.setFailed(`Error: ${error}`);
}
- name: Publish GH Action Link
uses: actions/github-script@main
with:
script: |
async function getJobUrl() {
return `https://github.com/${context.issue.owner}/${context.issue.repo}/actions/runs/${context.runId}`;
}
await github.rest.issues.createComment({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: context.issue.number,
body: `Click [here](${await getJobUrl()}) to check the status of your benchmark.`
});
- name: Run Benchmark
run: |
nix develop --no-warn-dirty --accept-flake-config --command bash ./scripts/ci-plutus-benchmark.sh
env:
BENCHMARK_NAME: ${{ steps.extract-benchmark.outputs.benchmark }}
PR_NUMBER: ${{ github.event.issue.number }}
PR_BRANCH: ${{ steps.extract-branch.outputs.head_ref }}
- name: Publish Results
uses: actions/github-script@main
with:
script: |
const fs = require("fs");
await github.rest.issues.createComment({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: context.issue.number,
// bench-compare-result.log is generated by ci-plutus-benchmark.sh
body: fs.readFileSync("bench-compare-result.log", "utf-8").toString()
});