Johnathan Van Why | 3bb7a30 | 2020-06-17 14:26:53 -0700 | [diff] [blame] | 1 | # Calculates the size diffs for the each example binary. Runs when a pull |
| 2 | # request is created or modified. |
| 3 | |
| 4 | name: size-diff |
Johnathan Van Why | 686bab9 | 2020-10-06 14:24:42 -0700 | [diff] [blame] | 5 | |
| 6 | # We want to run this on all pull requests. Additionally, Bors needs workflows |
| 7 | # to run on the `staging` and `trying` branches to block merges on them. |
| 8 | on: |
| 9 | pull_request: |
| 10 | push: |
| 11 | branches: |
| 12 | - staging |
| 13 | - trying |
Johnathan Van Why | 3bb7a30 | 2020-06-17 14:26:53 -0700 | [diff] [blame] | 14 | |
| 15 | jobs: |
| 16 | size-diff: |
| 17 | # Using ubuntu-latest can cause breakage when ubuntu-latest is updated to |
| 18 | # point at a new Ubuntu version. Instead, explicitly specify the version, so |
| 19 | # we can update when we need to. This *could* break if we don't update it |
| 20 | # until support for 18.04 is dropped, but it is likely we'll have a reason |
| 21 | # to update to a newer Ubuntu before then anyway. |
| 22 | runs-on: ubuntu-18.04 |
| 23 | |
| 24 | steps: |
| 25 | # Clones a single commit from the libtock-rs repository. The commit cloned |
| 26 | # is a merge commit between the PR's target branch and the PR's source. |
| 27 | # We'll later add another commit (the pre-merge target branch) to the |
| 28 | # repository. |
| 29 | - name: Clone repository |
| 30 | uses: actions/checkout@v2.3.0 |
| 31 | |
| 32 | # Install a Rust toolchain with the components necessary to run |
| 33 | # `print-sizes`. This action doesn't seem to be able to install toolchains |
| 34 | # for multiple targets, so I add the targets later in the "size report" |
| 35 | # step. |
| 36 | - name: Install Rust toolchain |
| 37 | uses: actions-rs/toolchain@v1.0.6 |
| 38 | with: |
| 39 | profile: minimal |
| 40 | |
| 41 | # The main diff script. Stores the sizes of the example binaries for both |
| 42 | # the merge commit and the target branch. We display the diff in a |
| 43 | # separate step to make it easy to navigate to in the GitHub Actions UI. |
| 44 | - name: Compute sizes |
| 45 | run: | |
| 46 | UPSTREAM_REMOTE_NAME="${UPSTREAM_REMOTE_NAME:-origin}" |
| 47 | GITHUB_BASE_REF="${GITHUB_BASE_REF:-master}" |
| 48 | cd "${GITHUB_WORKSPACE}" |
| 49 | rustup target add riscv32imc-unknown-none-elf thumbv7em-none-eabi |
| 50 | make -j2 examples # The VM this runs on has 2 logical cores. |
Johnathan Van Why | adbb487 | 2020-06-22 12:39:17 -0700 | [diff] [blame] | 51 | cargo run --release -p print_sizes >'${{runner.temp}}/merge-sizes' |
Johnathan Van Why | 3bb7a30 | 2020-06-17 14:26:53 -0700 | [diff] [blame] | 52 | git remote set-branches "${UPSTREAM_REMOTE_NAME}" "${GITHUB_BASE_REF}" |
| 53 | git fetch --depth=1 "${UPSTREAM_REMOTE_NAME}" "${GITHUB_BASE_REF}" |
| 54 | git checkout "${UPSTREAM_REMOTE_NAME}/${GITHUB_BASE_REF}" |
Johnathan Van Why | 4a2c55a | 2020-06-23 14:13:59 -0700 | [diff] [blame] | 55 | rustup target add riscv32imc-unknown-none-elf thumbv7em-none-eabi |
Johnathan Van Why | 3bb7a30 | 2020-06-17 14:26:53 -0700 | [diff] [blame] | 56 | make -j2 examples |
Johnathan Van Why | adbb487 | 2020-06-22 12:39:17 -0700 | [diff] [blame] | 57 | cargo run --release -p print_sizes >'${{runner.temp}}/base-sizes' |
Johnathan Van Why | 3bb7a30 | 2020-06-17 14:26:53 -0700 | [diff] [blame] | 58 | |
| 59 | # Computes and displays the size diff. diff returns a nonzero status code |
| 60 | # if the files differ, and GitHub interprets a nonzero status code as an |
| 61 | # error. To avoid GitHub interpreting a difference as an error, we add |
| 62 | # || exit 0 to the command. |
| 63 | - name: Size diff |
| 64 | run: diff '${{runner.temp}}/base-sizes' '${{runner.temp}}/merge-sizes' || exit 0 |