Skip to content

Commit ffe0161

Browse files
committed
Separate benchmark run and results uploading
1 parent 6aa5b1f commit ffe0161

File tree

2 files changed

+77
-68
lines changed

2 files changed

+77
-68
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Upload and compare benchmark results
2+
3+
on:
4+
workflow_run:
5+
types: [completed]
6+
workflows: ['Running benchmark']
7+
8+
jobs:
9+
upload-benchmark-results:
10+
if: (github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'pull_request') && github.repository == 'OptimumCode/json-schema-validator'
11+
runs-on: ubuntu-latest
12+
environment: contribution
13+
env:
14+
RESULTS_DIR: bench-results
15+
permissions:
16+
# deployments permission to deploy GitHub pages website
17+
deployments: write
18+
# contents permission to update benchmark contents in gh-pages branch
19+
contents: write
20+
# pull-requests permission to create comments on PR in case of alert
21+
pull-requests: write
22+
strategy:
23+
# to make sure results are submitted one by one
24+
max-parallel: 1
25+
matrix:
26+
include:
27+
- artifact-pattern: 'bench-result-*'
28+
results-name: KMP JSON schema validator
29+
alert: true
30+
- artifact-pattern: 'bench-comparison-result-*'
31+
results-name: Compare KMP JSON schema validator
32+
alert: false
33+
name: 'Process benchmark results for ${{ matrix.results-name }}'
34+
steps:
35+
- name: 'Checkout Repository'
36+
uses: actions/checkout@v4
37+
- name: Download benchmark results
38+
uses: actions/download-artifact@v4
39+
with:
40+
pattern: ${{ matrix.artifact-pattern }}
41+
path: ${{ env.RESULTS_DIR }}
42+
merge-multiple: true
43+
run-id: ${{ github.event.workflow_run.id }}
44+
- name: Show downloaded artifacts
45+
run: tree ${{ env.RESULTS_DIR }}
46+
- name: Prepare and join benchmark reports
47+
id: prep
48+
run: |
49+
for report in $(find ./${{ env.RESULTS_DIR }} -type f -name "*.json")
50+
do
51+
file_name=$(basename "$report")
52+
platform="${file_name%.*}"
53+
jq "[ .[] | .benchmark |= \"${platform}.\" + ltrimstr(\"io.github.optimumcode.json.schema.benchmark.\") | .params |= map_values(. |= split(\"/\")[-1]) ]" $report > ${{ env.RESULTS_DIR }}/$platform.json
54+
done
55+
AGGREGATED_REPORT=aggregated.json
56+
# Joined reports looks like this: [[{},{}], [{},{}]]
57+
# We need to transform them into this: [{},{}]
58+
ls ${{ env.RESULTS_DIR }}/*.json
59+
jq -s '[ .[] | .[] ]' ${{ env.RESULTS_DIR }}/*.json > $AGGREGATED_REPORT
60+
echo "report=$AGGREGATED_REPORT" >> $GITHUB_OUTPUT
61+
- name: Store benchmark result
62+
uses: benchmark-action/github-action-benchmark@v1
63+
with:
64+
name: ${{ matrix.results-name }}
65+
tool: 'jmh'
66+
output-file-path: ${{ steps.prep.outputs.report }}
67+
alert-comment-cc-users: "@OptimumCode"
68+
comment-on-alert: ${{ matrix.alert }}
69+
summary-always: true
70+
alert-threshold: '150%'
71+
fail-threshold: '200%'
72+
max-items-in-chart: 50
73+
github-token: ${{ secrets.GITHUB_TOKEN }}
74+
# Push and deploy GitHub pages branch automatically only if run in main repo and not in PR
75+
auto-push: ${{ github.event.workflow_run.event == 'push' }}
76+
77+

.github/workflows/benchmark.yml

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -138,71 +138,3 @@ jobs:
138138
with:
139139
name: bench-comparison-result-${{ matrix.os }}
140140
path: ${{ env.BENCHMARK_RESULTS }}/comparison/**/*.json
141-
142-
upload-benchmark-results:
143-
if: (github.event_name == 'push' || github.event_name == 'pull_request') && github.repository == 'OptimumCode/json-schema-validator'
144-
needs:
145-
- benchmark-matrix
146-
runs-on: ubuntu-latest
147-
env:
148-
RESULTS_DIR: bench-results
149-
permissions:
150-
# deployments permission to deploy GitHub pages website
151-
deployments: write
152-
# contents permission to update benchmark contents in gh-pages branch
153-
contents: write
154-
# pull-requests permission to create comments on PR in case of alert
155-
pull-requests: write
156-
strategy:
157-
# to make sure results are submitted one by one
158-
max-parallel: 1
159-
matrix:
160-
include:
161-
- artifact-pattern: 'bench-result-*'
162-
results-name: KMP JSON schema validator
163-
alert: true
164-
- artifact-pattern: 'bench-comparison-result-*'
165-
results-name: Compare KMP JSON schema validator
166-
alert: false
167-
name: 'Process benchmark results for ${{ matrix.results-name }}'
168-
steps:
169-
- name: 'Checkout Repository'
170-
uses: actions/checkout@v4
171-
- name: Download benchmark results
172-
uses: actions/download-artifact@v4
173-
with:
174-
pattern: ${{ matrix.artifact-pattern }}
175-
path: ${{ env.RESULTS_DIR }}
176-
merge-multiple: true
177-
- name: Show downloaded artifacts
178-
run: tree ${{ env.RESULTS_DIR }}
179-
- name: Prepare and join benchmark reports
180-
id: prep
181-
run: |
182-
for report in $(find ./${{ env.RESULTS_DIR }} -type f -name "*.json")
183-
do
184-
file_name=$(basename "$report")
185-
platform="${file_name%.*}"
186-
jq "[ .[] | .benchmark |= \"${platform}.\" + ltrimstr(\"io.github.optimumcode.json.schema.benchmark.\") | .params |= map_values(. |= split(\"/\")[-1]) ]" $report > ${{ env.RESULTS_DIR }}/$platform.json
187-
done
188-
AGGREGATED_REPORT=aggregated.json
189-
# Joined reports looks like this: [[{},{}], [{},{}]]
190-
# We need to transform them into this: [{},{}]
191-
ls ${{ env.RESULTS_DIR }}/*.json
192-
jq -s '[ .[] | .[] ]' ${{ env.RESULTS_DIR }}/*.json > $AGGREGATED_REPORT
193-
echo "report=$AGGREGATED_REPORT" >> $GITHUB_OUTPUT
194-
- name: Store benchmark result
195-
uses: benchmark-action/github-action-benchmark@v1
196-
with:
197-
name: ${{ matrix.results-name }}
198-
tool: 'jmh'
199-
output-file-path: ${{ steps.prep.outputs.report }}
200-
alert-comment-cc-users: "@OptimumCode"
201-
comment-on-alert: ${{ matrix.alert }}
202-
summary-always: true
203-
alert-threshold: '150%'
204-
fail-threshold: '200%'
205-
max-items-in-chart: 50
206-
github-token: ${{ secrets.GITHUB_TOKEN }}
207-
# Push and deploy GitHub pages branch automatically only if run in main repo and not in PR
208-
auto-push: ${{ github.event_name != 'pull_request' }}

0 commit comments

Comments
 (0)