1+ name : Benchmark PR vs main
2+
3+ on :
4+ workflow_dispatch :
5+ pull_request :
6+ branches :
7+ - main
8+ paths :
9+ - ' **.swift'
10+ - ' **.yml'
11+
12+ concurrency :
13+ group : ${{ github.workflow }}-${{ github.ref }}-benchmark
14+ cancel-in-progress : true
15+
16+ jobs :
17+ benchmark-delta :
18+
19+ runs-on : ${{ matrix.os }}
20+ timeout-minutes : 15
21+ continue-on-error : true
22+ permissions :
23+ issues : write
24+ pull-requests : write
25+
26+ strategy :
27+ matrix :
28+ os : [ubuntu-latest]
29+
30+ steps :
31+ - uses : actions/checkout@v4
32+ with :
33+ fetch-depth : 0
34+
35+ - name : Ubuntu deps
36+ if : ${{ runner.os == 'Linux' }}
37+ run : |
38+ sudo apt-get install -y libjemalloc-dev
39+
40+ - name : Git URL token override and misc
41+ run : |
42+ #git config --global url."https://ordo-ci:${{ secrets.CI_MACHINE_PAT }}@github.com".insteadOf "https://github.com"
43+ #/usr/bin/ordo-performance
44+ [ -d Benchmarks ] && echo "hasBenchmark=1" >> $GITHUB_ENV
45+ echo "/opt/homebrew/bin:/usr/local/bin" >> $GITHUB_PATH
46+ - name : Run benchmarks for PR branch
47+ if : ${{ env.hasBenchmark == '1' }}
48+ run : |
49+ swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request
50+ - name : Switch to branch 'main'
51+ if : ${{ env.hasBenchmark == '1' }}
52+ run : |
53+ git stash
54+ git checkout main
55+ - name : Run benchmarks for branch 'main'
56+ if : ${{ env.hasBenchmark == '1' }}
57+ run : |
58+ swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main
59+ - name : Compare PR and main
60+ if : ${{ env.hasBenchmark == '1' }}
61+ id : benchmark
62+ run : |
63+ echo '## Summary' >> $GITHUB_STEP_SUMMARY
64+ echo $(date) >> $GITHUB_STEP_SUMMARY
65+ echo "exitStatus=1" >> $GITHUB_ENV
66+ swift package benchmark baseline check main pull_request --format markdown >> $GITHUB_STEP_SUMMARY
67+ echo '---' >> $GITHUB_STEP_SUMMARY
68+ swift package benchmark baseline compare main pull_request --no-progress --quiet --format markdown >> $GITHUB_STEP_SUMMARY
69+ echo "exitStatus=0" >> $GITHUB_ENV
70+ continue-on-error : true
71+ - if : ${{ env.exitStatus == '0' }}
72+ name : Pull request comment text success
73+ id : prtestsuccess
74+ run : |
75+ echo 'PRTEST<<EOF' >> $GITHUB_ENV
76+ echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/hummingbird-project/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV
77+ echo 'EOF' >> $GITHUB_ENV
78+ - if : ${{ env.exitStatus == '1' }}
79+ name : Pull request comment text failure
80+ id : prtestfailure
81+ run : |
82+ echo 'PRTEST<<EOF' >> $GITHUB_ENV
83+ echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/hummingbird-project/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV
84+ echo "_Pull request had performance regressions_" >> $GITHUB_ENV
85+ echo 'EOF' >> $GITHUB_ENV
86+ - name : Comment PR
87+ if : ${{ env.hasBenchmark == '1' }}
88+ uses : thollander/actions-comment-pull-request@v3
89+ with :
90+ github-token : ${{ secrets.GITHUB_TOKEN }}
91+ message : ${{ env.PRTEST }}
92+ comment-tag : benchmark
93+ - name : Exit with correct status
94+ run : |
95+ exit ${{ env.exitStatus }}
0 commit comments