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
+ jobs :
13
+ benchmark-delta :
14
+
15
+ runs-on : ${{ matrix.os }}
16
+ timeout-minutes : 15
17
+ continue-on-error : true
18
+
19
+ strategy :
20
+ matrix :
21
+ os : [ubuntu-latest]
22
+
23
+ steps :
24
+ - uses : actions/checkout@v4
25
+ with :
26
+ fetch-depth : 0
27
+
28
+ - name : Homebrew Mac
29
+ if : ${{ runner.os == 'Macos' }}
30
+ run : |
31
+ echo "/opt/homebrew/bin:/usr/local/bin" >> $GITHUB_PATH
32
+ brew install jemalloc
33
+
34
+ - name : Ubuntu deps
35
+ if : ${{ runner.os == 'Linux' }}
36
+ run : |
37
+ sudo apt-get install -y libjemalloc-dev
38
+
39
+ - name : Git URL token override and misc
40
+ run : |
41
+ #git config --global url."https://ordo-ci:${{ secrets.CI_MACHINE_PAT }}@github.com".insteadOf "https://github.com"
42
+ #/usr/bin/ordo-performance
43
+ [ -d Benchmarks ] && echo "hasBenchmark=1" >> $GITHUB_ENV
44
+ echo "/opt/homebrew/bin:/usr/local/bin" >> $GITHUB_PATH
45
+ - name : Run benchmarks for PR branch
46
+ if : ${{ env.hasBenchmark == '1' }}
47
+ run : |
48
+ cd Benchmarks
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
+ cd Benchmarks
59
+ swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main
60
+ - name : Compare PR and main
61
+ if : ${{ env.hasBenchmark == '1' }}
62
+ id : benchmark
63
+ run : |
64
+ echo $(date) >> $GITHUB_STEP_SUMMARY
65
+ echo "exitStatus=1" >> $GITHUB_ENV
66
+ cd Benchmarks
67
+ swift package benchmark baseline check main pull_request --format markdown >> $GITHUB_STEP_SUMMARY
68
+ echo "exitStatus=0" >> $GITHUB_ENV
69
+ continue-on-error : true
70
+ - if : ${{ env.exitStatus == '0' }}
71
+ name : Pull request comment text success
72
+ id : prtestsuccess
73
+ run : |
74
+ echo 'PRTEST<<EOF' >> $GITHUB_ENV
75
+ echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/swift-extras/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV
76
+ echo 'EOF' >> $GITHUB_ENV
77
+ - if : ${{ env.exitStatus == '1' }}
78
+ name : Pull request comment text failure
79
+ id : prtestfailure
80
+ run : |
81
+ echo 'PRTEST<<EOF' >> $GITHUB_ENV
82
+ echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/swift-extras/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV
83
+ echo "_Pull request had performance regressions_" >> $GITHUB_ENV
84
+ echo 'EOF' >> $GITHUB_ENV
85
+ - name : Comment PR
86
+ if : ${{ env.hasBenchmark == '1' }}
87
+ uses : thollander/actions-comment-pull-request@v2
88
+ with :
89
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
90
+ message : ${{ env.PRTEST }}
91
+ comment_includes : " Pull request benchmark comparison [${{ matrix.os }}] with"
92
+ - name : Exit with correct status
93
+ run : |
94
+ exit ${{ env.exitStatus }}
0 commit comments