1
+ name : Benchmarks
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ pull_request :
6
+ push :
7
+ branches : [main]
8
+
9
+ jobs :
10
+ bench :
11
+ name : Benchmark the code
12
+ runs-on : warp-ubuntu-latest-x64-16x
13
+ strategy :
14
+ matrix :
15
+ toolchain :
16
+ - stable
17
+ env :
18
+ PR_NUMBER : ${{ github.event.number }}
19
+ BENCH_AGAINST_BASE : 1
20
+ steps :
21
+ - name : Checkout sources
22
+ uses : actions/checkout@v4
23
+ with :
24
+ fetch-depth : 0 # Used to get hash of base branch
25
+
26
+ # https://github.com/dtolnay/rust-toolchain
27
+ - name : Setup rust toolchain
28
+ uses : dtolnay/rust-toolchain@stable
29
+ with :
30
+ toolchain : ${{ matrix.toolchain }}
31
+
32
+ # https://github.com/swatinem/rust-cache
33
+ - name : Run Swatinem/rust-cache@v2
34
+ uses : Swatinem/rust-cache@v2
35
+ with :
36
+ cache-on-failure : true
37
+
38
+ - name : Set (and display) useful variables
39
+ id : vars
40
+ run : |
41
+ source scripts/ci/env-vars.sh
42
+
43
+ echo "HEAD_SHA: ${HEAD_SHA}"
44
+ echo "HEAD_SHA_SHORT: ${HEAD_SHA_SHORT}"
45
+ echo "BASE_SHA: ${BASE_SHA}"
46
+ echo "BASE_SHA_SHORT: ${BASE_SHA_SHORT}"
47
+
48
+ echo "HEAD_SHA=${HEAD_SHA}" >> "$GITHUB_OUTPUT"
49
+ echo "HEAD_SHA_SHORT=${HEAD_SHA_SHORT}" >> "$GITHUB_OUTPUT"
50
+ echo "BASE_SHA=${BASE_SHA}" >> "$GITHUB_OUTPUT"
51
+ echo "BASE_SHA_SHORT=${BASE_SHA_SHORT}" >> "$GITHUB_OUTPUT"
52
+
53
+ # S3 upload directory, depending if it includes a comparison or not
54
+ if [ "$HEAD_SHA" == "$BASE_SHA" ]; then
55
+ # No comparison (i.e. running on a branch like main directly)
56
+ S3_UPLOAD_DIR="benchmark/${HEAD_SHA_SHORT}"
57
+ else
58
+ # Comparison (i.e. running on a PR)
59
+ S3_UPLOAD_DIR="benchmark/${HEAD_SHA_SHORT}-${BASE_SHA_SHORT}"
60
+ fi
61
+ echo "S3_UPLOAD_DIR: ${S3_UPLOAD_DIR}"
62
+ echo "S3_UPLOAD_DIR=${S3_UPLOAD_DIR}" >> "$GITHUB_OUTPUT"
63
+ echo "S3_UPLOAD_DIR=${S3_UPLOAD_DIR}" >> "$GITHUB_ENV"
64
+
65
+ #
66
+ # RUN BENCHMARKS (and upload the report)
67
+ #
68
+ - run : make bench-in-ci
69
+
70
+ # Upload as artifact first
71
+ - name : Upload report as artifact
72
+
73
+ with :
74
+ name : benchmark-report
75
+ path : target/benchmark-in-ci/benchmark-report/
76
+
77
+ - name : Zip the report and add to folder (for S3 upload)
78
+ working-directory : target/benchmark-in-ci
79
+ run : |
80
+ zip_fn="report.zip"
81
+ zip -r $zip_fn benchmark-report
82
+ mv $zip_fn benchmark-report/
83
+
84
+ # Upload S3 (using https://github.com/shallwefootball/upload-s3-action)
85
+ - name : Upload report to S3
86
+ uses : shallwefootball/s3-upload-action@master
87
+ id : S3
88
+ with :
89
+ aws_key_id : ${{secrets.AWS_KEY_ID}}
90
+ aws_secret_access_key : ${{secrets.AWS_SECRET_ACCESS_KEY}}
91
+ aws_bucket : flashbots-rbuilder-ci-stats
92
+ source_dir : target/benchmark-in-ci/benchmark-report
93
+ destination_dir : ${{ steps.vars.outputs.S3_UPLOAD_DIR }}
94
+
95
+ #
96
+ # POST SUMMARY (to PR comment and CI job summary)
97
+ #
98
+ - name : Add summary to CI job summary
99
+ run : |
100
+ BENCH_URL="https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/${{steps.S3.outputs.object_key}}/report/index.html"
101
+ sed -i "s|__BENCH_URL__|${BENCH_URL}|" target/benchmark-in-ci/benchmark-summary.md
102
+ sed -i "s|__BENCH_URL__|${BENCH_URL}|" target/benchmark-in-ci/benchmark-pr-comment.md
103
+ cat target/benchmark-in-ci/benchmark-summary.md >> $GITHUB_STEP_SUMMARY
104
+
105
+ # https://github.com/peter-evans/find-comment
106
+ - name : Find previous PR comment
107
+ uses : peter-evans/find-comment@v3
108
+ if : github.event_name == 'pull_request'
109
+ id : fc
110
+ with :
111
+ issue-number : ${{ github.event.pull_request.number }}
112
+ comment-author : ' github-actions[bot]'
113
+ body-includes : Benchmark results
114
+
115
+ # https://github.com/peter-evans/create-or-update-comment
116
+ - name : Create or update PR comment
117
+ uses : peter-evans/create-or-update-comment@v4
118
+ if : github.event_name == 'pull_request'
119
+ with :
120
+ comment-id : ${{ steps.fc.outputs.comment-id }}
121
+ issue-number : ${{ github.event.pull_request.number }}
122
+ edit-mode : replace
123
+ body-path : target/benchmark-in-ci/benchmark-pr-comment.md
0 commit comments