Repository navigation
181 lines (156 loc) · 5.57 KB
/
Copy pathbenchmark-pr.yml
File metadata and controls
181 lines (156 loc) · 5.57 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Benchmarks -> PR Comment
on:
pull_request:
branches: [master, develop]
types: [opened, synchronize, reopened, ready_for_review, labeled]
concurrency:
group: benchmark-pr-${{ github.event.pull_request.number }}${{ github.event.action == 'labeled' && github.event.label.name != 'run-benchmarks' && format('-{0}', github.run_id) || '' }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
changes:
name: Detect changed paths
if: >-
github.event.pull_request.draft != true &&
(github.event.action != 'labeled' || github.event.label.name == 'run-benchmarks')
runs-on: ubuntu-latest
outputs:
benchmarks: ${{ steps.filter.outputs.benchmarks }}
run: ${{ steps.filter.outputs.benchmarks == 'true' && (github.base_ref == 'master' || contains(github.event.pull_request.labels.*.name, 'run-benchmarks')) }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Filter
id: filter
uses: dorny/paths-filter@v4
with:
filters: |
benchmarks:
- 'src/**'
- 'benchmarks/QueryCache.Benchmarks/**'
- 'Directory.Build.props'
- 'global.json'
- '.github/workflows/benchmark-pr.yml'
groups:
name: Load benchmark groups
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.load.outputs.matrix }}
steps:
- uses: actions/checkout@v7
- id: load
run: echo "matrix=$(jq -c . benchmarks/QueryCache.Benchmarks/benchmark-groups.json)" >> "$GITHUB_OUTPUT"
guard:
name: Every benchmark belongs to a group
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.benchmarks == 'true'
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
cache: true
cache-dependency-path: '**/*.csproj'
- name: Build (Release)
run: dotnet build benchmarks/QueryCache.Benchmarks/QueryCache.Benchmarks.csproj --configuration Release
- name: Check group coverage
run: bash benchmarks/QueryCache.Benchmarks/check-benchmark-groups.sh
benchmark:
name: Run (${{ matrix.group.name }})
runs-on: ubuntu-latest
needs: [changes, groups]
if: needs.changes.outputs.run == 'true'
strategy:
fail-fast: false
matrix:
group: ${{ fromJSON(needs.groups.outputs.matrix) }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
cache: true
cache-dependency-path: '**/*.csproj'
- name: Restore
run: dotnet restore benchmarks/QueryCache.Benchmarks/QueryCache.Benchmarks.csproj
- name: Build (Release)
run: dotnet build benchmarks/QueryCache.Benchmarks/QueryCache.Benchmarks.csproj --configuration Release --no-restore
- name: Run benchmarks
run: |
IFS=' ' read -ra patterns <<< '${{ matrix.group.filter }}'
dotnet run --project benchmarks/QueryCache.Benchmarks/QueryCache.Benchmarks.csproj \
--configuration Release --no-build \
-- --filter "${patterns[@]}" ${{ matrix.group.prArgs }}
- name: Upload markdown results
uses: actions/upload-artifact@v7
with:
name: bench-md-${{ matrix.group.name }}
path: BenchmarkDotNet.Artifacts/results/*-report-github.md
retention-days: 1
- name: Upload JSON results
uses: actions/upload-artifact@v7
with:
name: bench-json-${{ matrix.group.name }}
path: BenchmarkDotNet.Artifacts/results/*-report-full.json
retention-days: 1
comment:
name: Post PR Comment
needs: [changes, benchmark]
if: always() && needs.changes.outputs.run == 'true' && needs.benchmark.result != 'cancelled'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Checkout the published benchmark series
continue-on-error: true
uses: actions/checkout@v7
with:
ref: gh-pages
path: gh-pages
fetch-depth: 1
- name: Download all markdown results
uses: actions/download-artifact@v8
with:
pattern: bench-md-*
merge-multiple: true
path: results/
- name: Download all JSON results
uses: actions/download-artifact@v8
with:
pattern: bench-json-*
merge-multiple: true
path: results-json/
- name: Build comment body
id: build
run: |
delta=(--results results-json)
if [ -f gh-pages/dev/bench/data.js ]; then
delta+=(--baseline gh-pages/dev/bench/data.js)
fi
{
echo 'body<<BENCHMARK_EOF'
python3 benchmarks/QueryCache.Benchmarks/bench_delta.py "${delta[@]}"
echo ''
echo '<details><summary>Full results per group</summary>'
echo ''
for f in results/*-report-github.md; do
[ -f "$f" ] || continue
name=$(basename "$f" -report-github.md)
echo "### $name"
echo ''
cat "$f"
echo ''
done
echo '</details>'
echo 'BENCHMARK_EOF'
} >> "$GITHUB_OUTPUT"
- name: Post (or update) PR comment
uses: marocchino/sticky-pull-request-comment@v3
with:
header: benchmarks
message: ${{ steps.build.outputs.body }}