blob: 2c3b5976ec21e165ebee0750612e1f5d4bc6de14 [file] [log] [blame]
Johnathan Van Why3bb7a302020-06-17 14:26:53 -07001# Calculates the size diffs for the each example binary. Runs when a pull
2# request is created or modified.
3
4name: size-diff
Johnathan Van Why686bab92020-10-06 14:24:42 -07005
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.
8on:
9 pull_request:
10 push:
11 branches:
12 - staging
13 - trying
Johnathan Van Why3bb7a302020-06-17 14:26:53 -070014
15jobs:
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 Whyadbb4872020-06-22 12:39:17 -070051 cargo run --release -p print_sizes >'${{runner.temp}}/merge-sizes'
Johnathan Van Why3bb7a302020-06-17 14:26:53 -070052 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 Why4a2c55a2020-06-23 14:13:59 -070055 rustup target add riscv32imc-unknown-none-elf thumbv7em-none-eabi
Johnathan Van Why3bb7a302020-06-17 14:26:53 -070056 make -j2 examples
Johnathan Van Whyadbb4872020-06-22 12:39:17 -070057 cargo run --release -p print_sizes >'${{runner.temp}}/base-sizes'
Johnathan Van Why3bb7a302020-06-17 14:26:53 -070058
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