-
Notifications
You must be signed in to change notification settings - Fork 220
141 lines (128 loc) · 5.05 KB
/
performance.yml
File metadata and controls
141 lines (128 loc) · 5.05 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
name: Performance
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
actions: read
contents: read
issues: write
pull-requests: write
concurrency:
group: check-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
check:
name: Check
runs-on: ubuntu-latest-8
timeout-minutes: 180
env:
BENCHMARK_TRACKING_CONFIG: .github/benchmark-tracking.toml
steps:
- name: Checkout
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
- name: Find latest main benchmark artifact
if: github.event_name == 'pull_request'
id: baseline
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const {owner, repo} = context.repo;
const artifacts = await github.paginate(github.rest.actions.listArtifactsForRepo, {
owner,
repo,
name: 'benchmark-tracking-results',
per_page: 100,
});
artifacts.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
const artifact = artifacts.find((candidate) =>
!candidate.expired && candidate.workflow_run?.head_branch === 'main'
);
if (artifact) {
core.setOutput('found', 'true');
core.setOutput('run_id', String(artifact.workflow_run.id));
} else {
core.warning('No benchmark-tracking artifact found for main');
core.setOutput('found', 'false');
}
- name: Download main benchmark artifact
if: github.event_name == 'pull_request' && steps.baseline.outputs.found == 'true'
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: benchmark-tracking-results
path: benchmark-tracking-baseline
run-id: ${{ steps.baseline.outputs.run_id }}
github-token: ${{ github.token }}
- name: Run setup
uses: ./.github/actions/setup
with:
toolchain: nightly
- name: Run benchmark tracking
id: run
run: |
args=()
if [ "${{ github.event_name }}" = "pull_request" ]; then
if [ -f benchmark-tracking-baseline/current.toml ]; then
args=(--baseline benchmark-tracking-baseline/current.toml)
fi
else
args=(--no-compare)
fi
python3 .github/scripts/benchmark-tracking.py \
--config "$BENCHMARK_TRACKING_CONFIG" \
--output-dir benchmark-tracking-results \
"${args[@]}"
- name: Upload benchmark results
if: always() && github.ref == 'refs/heads/main' && steps.run.outcome == 'success'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: benchmark-tracking-results
path: benchmark-tracking-results
if-no-files-found: error
- name: Add benchmark summary
if: always() && github.event_name == 'pull_request' && steps.run.outcome == 'success'
run: cat benchmark-tracking-results/comment.md >> "$GITHUB_STEP_SUMMARY"
- name: Comment on pull request
if: always() && github.event_name == 'pull_request' && steps.run.outcome == 'success'
continue-on-error: true
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const fs = require('fs');
const marker = '<!-- commonware-benchmark-tracking-results -->';
const body = fs.readFileSync('benchmark-tracking-results/comment.md', 'utf8');
const {owner, repo} = context.repo;
const issue_number = context.payload.pull_request.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
const previous = comments.find((comment) =>
comment.user.type === 'Bot' && comment.body.includes(marker)
);
if (previous) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: previous.id,
body,
});
} else {
await github.rest.issues.createComment({owner, repo, issue_number, body});
}
- name: Fail on benchmark regression
if: always() && github.event_name == 'pull_request' && steps.run.outcome == 'success'
run: |
python3 - <<'PY'
import sys
import tomllib
with open('benchmark-tracking-results/summary.toml', 'rb') as f:
summary = tomllib.load(f)
regressions = summary.get('regression_count', 0)
if regressions:
print(f'{regressions} benchmark(s) exceeded the configured threshold')
sys.exit(1)
PY