|
9 | 9 | branches:
|
10 | 10 | - master
|
11 | 11 |
|
| 12 | +# Both the "measure" and "report" jobs need to know this. |
| 13 | +env: |
| 14 | + SIZE_DATA_DIR: sizes |
| 15 | + |
12 | 16 | # Responsibility is divided between two jobs "measure" and "report", so that the
|
13 | 17 | # job that builds (and potentnially runs) untrusted code does not have PR write
|
14 | 18 | # permission, and vice-versa.
|
15 | 19 | jobs:
|
16 | 20 | measure:
|
17 | 21 | name: Check binary size
|
18 |
| - runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + platform: [ubuntu-latest, windows-latest] |
| 25 | + runs-on: ${{ matrix.platform }} |
19 | 26 | permissions:
|
20 | 27 | contents: read
|
21 | 28 | env:
|
|
26 | 33 | TEST_MAIN_RS: foo.rs
|
27 | 34 | BASE_COMMIT: ${{ github.event.pull_request.base.sha }}
|
28 | 35 | HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}
|
29 |
| - outputs: |
30 |
| - binary-size-reference: ${{ steps.size-reference.outputs.test-binary-size }} |
31 |
| - binary-size-updated: ${{ steps.size-updated.outputs.test-binary-size }} |
| 36 | + SIZE_DATA_FILE: size-${{ strategy.job-index }}.json |
32 | 37 | steps:
|
33 | 38 | - name: Print info
|
34 | 39 | shell: bash
|
|
37 | 42 | echo "Base SHA: $BASE_COMMIT"
|
38 | 43 | # Note: the backtrace source that's cloned here is NOT the version to be
|
39 | 44 | # patched in to std. It's cloned here to access the Github action for
|
40 |
| - # building the test binary and measuring its size. |
| 45 | + # building and measuring the test binary. |
41 | 46 | - name: Clone backtrace to access Github action
|
42 | 47 | uses: actions/checkout@v3
|
43 | 48 | with:
|
@@ -87,66 +92,59 @@ jobs:
|
87 | 92 | main-rs: ${{ env.TEST_MAIN_RS }}
|
88 | 93 | rustc-dir: ${{ env.RUSTC_DIR }}
|
89 | 94 | id: size-updated
|
| 95 | + # There is no built-in way to "collect" all the outputs of a set of jobs |
| 96 | + # run with a matrix strategy. Subsequent jobs that have a "needs" |
| 97 | + # dependency on this one will be run once, when the last matrix job is |
| 98 | + # run. Appending data to a single file within a matrix is subject to race |
| 99 | + # conditions. So we write the size data to files with distinct names |
| 100 | + # generated from the job index. |
| 101 | + - name: Write sizes to file |
| 102 | + uses: actions/github-script@v6 |
| 103 | + env: |
| 104 | + SIZE_REFERENCE: ${{ steps.size-reference.outputs.test-binary-size }} |
| 105 | + SIZE_UPDATED: ${{ steps.size-updated.outputs.test-binary-size }} |
| 106 | + PLATFORM: ${{ matrix.platform }} |
| 107 | + with: |
| 108 | + script: | |
| 109 | + const fs = require("fs"); |
| 110 | + const path = require("path"); |
| 111 | +
|
| 112 | + fs.mkdirSync(process.env.SIZE_DATA_DIR, {recursive: true}); |
| 113 | +
|
| 114 | + const output_data = JSON.stringify({ |
| 115 | + platform: process.env.PLATFORM, |
| 116 | + reference: process.env.SIZE_REFERENCE, |
| 117 | + updated: process.env.SIZE_UPDATED, |
| 118 | + }); |
| 119 | +
|
| 120 | + // The "wx" flag makes this fail if the file exists, which we want, |
| 121 | + // because there should be no collisions. |
| 122 | + fs.writeFileSync( |
| 123 | + path.join(process.env.SIZE_DATA_DIR, process.env.SIZE_DATA_FILE), |
| 124 | + output_data, |
| 125 | + { flag: "wx" }, |
| 126 | + ); |
| 127 | + - name: Upload size data |
| 128 | + uses: actions/upload-artifact@v3 |
| 129 | + with: |
| 130 | + name: size-files |
| 131 | + path: ${{ env.SIZE_DATA_DIR }}/${{ env.SIZE_DATA_FILE }} |
| 132 | + retention-days: 1 |
| 133 | + if-no-files-found: error |
90 | 134 | report:
|
91 | 135 | name: Report binary size changes
|
92 | 136 | runs-on: ubuntu-latest
|
93 | 137 | needs: measure
|
94 | 138 | permissions:
|
95 | 139 | pull-requests: write
|
96 | 140 | steps:
|
97 |
| - - name: Post a PR comment if the size has changed |
98 |
| - uses: actions/github-script@v6 |
99 |
| - env: |
100 |
| - SIZE_REFERENCE: ${{ needs.measure.outputs.binary-size-reference }} |
101 |
| - SIZE_UPDATED: ${{ needs.measure.outputs.binary-size-updated }} |
| 141 | + # Clone backtrace to access Github composite actions to report size. |
| 142 | + - uses: actions/checkout@v3 |
| 143 | + - name: Download size data |
| 144 | + uses: actions/download-artifact@v3 |
102 | 145 | with:
|
103 |
| - script: | |
104 |
| - const reference = process.env.SIZE_REFERENCE; |
105 |
| - const updated = process.env.SIZE_UPDATED; |
106 |
| -
|
107 |
| - if (!(reference > 0)) { |
108 |
| - core.setFailed(`Reference size invalid: ${reference}`); |
109 |
| - return; |
110 |
| - } |
111 |
| -
|
112 |
| - if (!(updated > 0)) { |
113 |
| - core.setFailed(`Updated size invalid: ${updated}`); |
114 |
| - return; |
115 |
| - } |
116 |
| -
|
117 |
| - const formatter = Intl.NumberFormat("en", {useGrouping: "always"}); |
118 |
| -
|
119 |
| - const updated_str = formatter.format(updated); |
120 |
| - const reference_str = formatter.format(reference); |
121 |
| -
|
122 |
| - const diff = updated - reference; |
123 |
| - const diff_pct = (updated / reference) - 1; |
124 |
| -
|
125 |
| - const diff_str = Intl.NumberFormat("en", { |
126 |
| - useGrouping: "always", |
127 |
| - sign: "exceptZero" |
128 |
| - }).format(diff); |
129 |
| -
|
130 |
| - const diff_pct_str = Intl.NumberFormat("en", { |
131 |
| - style: "percent", |
132 |
| - useGrouping: "always", |
133 |
| - sign: "exceptZero", |
134 |
| - maximumFractionDigits: 2 |
135 |
| - }).format(diff_pct); |
136 |
| -
|
137 |
| - if (diff !== 0) { |
138 |
| - // The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines, |
139 |
| - // which is interpreted as a code block by Markdown. |
140 |
| - const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace. |
141 |
| -
|
142 |
| - Original binary size: **${reference_str} B** |
143 |
| - Updated binary size: **${updated_str} B** |
144 |
| - Difference: **${diff_str} B** (${diff_pct_str})`; |
145 |
| -
|
146 |
| - github.rest.issues.createComment({ |
147 |
| - issue_number: context.issue.number, |
148 |
| - owner: context.repo.owner, |
149 |
| - repo: context.repo.repo, |
150 |
| - body |
151 |
| - }) |
152 |
| - } |
| 146 | + name: size-files |
| 147 | + path: ${{ env.SIZE_DATA_DIR }} |
| 148 | + - uses: ./.github/actions/report-code-size-changes |
| 149 | + with: |
| 150 | + data-directory: ${{ env.SIZE_DATA_DIR }} |
0 commit comments