1- name : Comment Benchmarks
1+ name : Benchmarks
22
33on :
4+ push :
5+ branches :
6+ - main
47 pull_request :
58 branches :
69 - " *"
@@ -11,22 +14,20 @@ jobs:
1114 name : Run Benchmarks and Comment
1215
1316 steps :
14- - uses : actions/checkout@v3
15-
16- - uses : actions/setup-node@v3
17+ - uses : actions/checkout@v4
18+ - uses : actions/setup-node@v4
1719 with :
18- node-version : 18
19-
20+ node-version : " 20"
2021 - name : Cache Node modules
21- uses : actions/cache@v2
22+ uses : actions/cache@v4
2223 with :
2324 path : ~/.npm
2425 key : ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
2526 restore-keys : |
2627 ${{ runner.os }}-node-
2728
2829 - name : Cache mops packages
29- uses : actions/cache@v3
30+ uses : actions/cache@v4
3031 with :
3132 key : mops-packages-${{ hashFiles('mops.toml') }}
3233 path : |
@@ -51,25 +52,67 @@ jobs:
5152 # set moc path for dfx to use
5253 echo "DFX_MOC_PATH=$(mops toolchain bin moc)" >> $GITHUB_ENV
5354
55+ - name : Create benchmark-results branch if it doesn't exist
56+ uses : peterjgrainger/action-create-branch@v2.2.0
57+ env :
58+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
59+ with :
60+ branch : " benchmark-results"
61+ sha : " ${{ github.event.pull_request.head.sha }}"
62+ continue-on-error : true
63+
64+ - name : Checkout out the branch with benchmark results
65+ if : github.event_name == 'pull_request'
66+ uses : actions/checkout@v4
67+ with :
68+ ref : benchmark-results
69+ path : .benchmark-results-branch/
70+ - name : Move Saved Benchmarks
71+ if : github.event_name == 'pull_request'
72+ run : mv .benchmark-results-branch/.bench .bench 2>/dev/null || mkdir -p .bench
73+
5474 - name : Benchmarks
75+ if : github.event_name == 'pull_request'
5576 id : benchmarks
5677 run : |
57- mops bench --gc incremental 2>&1 | tee benchmark_results.txt
58-
59- # Process the output to remove everything up to the last occurrence of \033[2K
60- awk '/\x1b\[2K/ { buffer = "" } { buffer = buffer $0 "\n" } END { print buffer }' benchmark_results.txt > intermediate_results.txt
61- sed 's/\x1b\[[0-9;]*[a-zA-Z]//g' intermediate_results.txt > processed_results.txt
78+ mops bench --gc incremental --compare 2>&1 | tee benchmark_results.txt
79+ echo "result<<EOF" >> $GITHUB_OUTPUT
80+ cat benchmark_results.txt >> $GITHUB_OUTPUT
81+ echo "EOF" >> $GITHUB_OUTPUT
6282
63- # Set the processed output as an environment variable
64- echo "BENCHMARK_OUTPUT<<EOF" >> $GITHUB_ENV
65- cat processed_results.txt >> $GITHUB_ENV
66- echo "EOF" >> $GITHUB_ENV
83+ - name : Find Benchmark Comment
84+ if : github.event_name == 'pull_request'
85+ uses : peter-evans/find-comment@v3
86+ id : fc
87+ with :
88+ issue-number : ${{ github.event.pull_request.number }}
89+ comment-author : " github-actions[bot]"
90+ body-includes : Benchmark Results
6791
68- - name : Comment PR
92+ - name : Create or update comment
6993 if : github.event_name == 'pull_request'
70- uses : unsplash/comment-on-pr@v1.3.0
71- env :
72- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
94+ uses : peter-evans/create-or-update-comment@v4
95+ with :
96+ comment-id : ${{ steps.fc.outputs.comment-id }}
97+ issue-number : ${{ github.event.pull_request.number }}
98+ body : ${{ steps.benchmarks.outputs.result }}
99+ edit-mode : replace
100+
101+ - name : Generate Benchmark Results
102+ if : github.event_name != 'pull_request'
103+ run : |
104+ set -o pipefail
105+ mops bench --gc incremental --save 2>&1
106+ - name : Move Generated Results
107+ if : github.event_name != 'pull_request'
108+ run : |
109+ mkdir .bench-br
110+ mv .bench .bench-br/.bench
111+ mv bench-results.md .bench-br/README.md
112+ - name : Upload benchmark results
113+ if : github.event_name != 'pull_request'
114+ uses : JamesIves/github-pages-deploy-action@v4
73115 with :
74- msg : " # Benchmark Results\n\n ${{ env.BENCHMARK_OUTPUT }}\n "
75- check_for_duplicate_msg : false
116+ token : ${{ secrets.GITHUB_TOKEN }}
117+ branch : benchmark-results
118+ folder : .bench-br
0 commit comments