|
| 1 | +name: Bloaty size diff |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: '*' |
| 6 | + push: |
| 7 | + branches: '*' |
| 8 | + |
| 9 | +jobs: |
| 10 | + size-diff: |
| 11 | + name: Run Bloaty |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + ######################### |
| 15 | + # Install the toolchain # |
| 16 | + ######################### |
| 17 | + - name: Setup Python |
| 18 | + uses: actions/setup-python@v4 |
| 19 | + with: |
| 20 | + python-version: '3.8' |
| 21 | + - name: Setup arm-none-eabi-gcc 10.3 |
| 22 | + uses: carlosperate/arm-none-eabi-gcc-action@v1 |
| 23 | + with: |
| 24 | + release: 10.3-2021.10 |
| 25 | + - name: Install Ninja 1.11 & CMake 3.25 via PyPI |
| 26 | + run: python -m pip install ninja==1.11.1 cmake==3.25.0 |
| 27 | + |
| 28 | + ######################################### |
| 29 | + # Set up the CODAL project and build it # |
| 30 | + ######################################### |
| 31 | + - name: Clone the microbit-v2-samples repository |
| 32 | + uses: actions/checkout@v3 |
| 33 | + with: |
| 34 | + repository: 'lancaster-university/microbit-v2-samples' |
| 35 | + # We need to use the checkout action (instead of build.py cloning the |
| 36 | + # repository) so that on PRs we can get the commit from the PR merge |
| 37 | + - name: Clone this repository in the libraries folder |
| 38 | + uses: actions/checkout@v3 |
| 39 | + with: |
| 40 | + path: libraries/codal-microbit-v2 |
| 41 | + fetch-depth: '0' |
| 42 | + # Changing the commit SHA might be unnecessary, as we've already cloned this |
| 43 | + # repo, but could be useful to ensure codal.json points to the same commit |
| 44 | + - name: Modify files to use BLE & this codal-microbit-v2 commit |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + echo "coda.json before:" |
| 48 | + cat codal.json |
| 49 | + mv codal.ble.json codal.json |
| 50 | + python - << EOF |
| 51 | + import pathlib; |
| 52 | + f = pathlib.Path('codal.json'); |
| 53 | + f.write_text(f.read_text() \ |
| 54 | + .replace('lancaster-university/codal-microbit-v2', '${GITHUB_REPOSITORY}') \ |
| 55 | + .replace('master', '${GITHUB_SHA}') \ |
| 56 | + .replace(',\n \"dev\": true', '')) |
| 57 | + f = pathlib.Path('source/main.cpp') |
| 58 | + f.write_text(f.read_text().replace('out_of_box_experience()', 'ble_test()')) |
| 59 | + EOF |
| 60 | + echo "coda.json after:" |
| 61 | + cat codal.json |
| 62 | + - name: Build using build.py |
| 63 | + run: python build.py |
| 64 | + - name: Save ELF file in a different directory |
| 65 | + run: | |
| 66 | + mkdir original-build |
| 67 | + mv build/MICROBIT original-build/MICROBIT.elf |
| 68 | + # Manually clean the project, but keep the codal-microbit-v2 library |
| 69 | + # If the codal-microbit-v2 target adds more libs this step will need to include them as well |
| 70 | + - name: Clean project |
| 71 | + run: rm -rf build/ libraries/codal-core libraries/codal-microbit-nrf5sdk libraries/codal-nrf52 |
| 72 | + |
| 73 | + #################################################################### |
| 74 | + # Set up codal-microbit-v2 to a parent/base commit and build again # |
| 75 | + #################################################################### |
| 76 | + - name: "PR only: Get base commit SHA" |
| 77 | + if: ${{ github.event.pull_request.base.sha }} |
| 78 | + run: | |
| 79 | + echo "${{ github.event.pull_request.base.sha }}" |
| 80 | + echo "GIT_BASE_SHA=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV |
| 81 | + echo "# Bloaty comparison with PR base commit" >> $GITHUB_STEP_SUMMARY |
| 82 | + echo "Base commit: ${{ github.event.pull_request.base.sha }}" >> $GITHUB_STEP_SUMMARY |
| 83 | + - name: "Commit only: Get parent commit SHA" |
| 84 | + if: ${{ ! github.event.pull_request.base.sha }} |
| 85 | + run: | |
| 86 | + cd libraries/codal-microbit-v2 |
| 87 | + echo "$(git log --pretty=%P -n 1 HEAD^0)" |
| 88 | + echo "GIT_BASE_SHA=$(git log --pretty=%P -n 1 HEAD^0)" >> $GITHUB_ENV |
| 89 | + echo "# Bloaty comparison with parent commit" >> $GITHUB_STEP_SUMMARY |
| 90 | + echo "Parent commit: $(git log --pretty=%P -n 1 HEAD^0)" >> $GITHUB_STEP_SUMMARY |
| 91 | + # We don't need to update codal.json because we've kept the |
| 92 | + # codal-microbit-v2 repo and we manually check out the right base commit |
| 93 | + - name: Checkout parent/base commit of codal-microbit-v2 |
| 94 | + run: | |
| 95 | + cd libraries/codal-microbit-v2 |
| 96 | + git checkout ${GIT_BASE_SHA} |
| 97 | + - name: Build 'base' project using build.py |
| 98 | + run: python build.py --clean |
| 99 | + |
| 100 | + ####################################### |
| 101 | + # Run the Bloaty McBloatface analysis # |
| 102 | + ####################################### |
| 103 | + # 1st run the bloaty diff so that it's added to the top of the summary page |
| 104 | + - name: Run Bloaty to compare before and after ELF files |
| 105 | + id: bloaty-comparison |
| 106 | + uses: carlosperate/bloaty-action@v1 |
| 107 | + with: |
| 108 | + bloaty-args: -s vm original-build/MICROBIT.elf -- build/MICROBIT |
| 109 | + output-to-summary: true |
| 110 | + # Then show memory consumption of top 30 components for this build |
| 111 | + - name: Run Bloaty to view ELF file full info |
| 112 | + uses: carlosperate/bloaty-action@v1 |
| 113 | + with: |
| 114 | + bloaty-args: original-build/MICROBIT.elf -d compileunits -n 30 -s vm |
| 115 | + output-to-summary: true |
| 116 | + - name: Add comment to PR with the bloaty diff |
| 117 | + if: ${{ github.event.pull_request }} |
| 118 | + continue-on-error: true |
| 119 | + uses: actions/github-script@v6 |
| 120 | + with: |
| 121 | + script: | |
| 122 | + let prComment = '## Build diff\n' + |
| 123 | + 'Base commit: [${{ env.GIT_BASE_SHA }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ env.GIT_BASE_SHA }})\n' + |
| 124 | + 'Action run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n' + |
| 125 | + '```\n' + |
| 126 | + '${{ steps.bloaty-comparison.outputs.bloaty-output-encoded }}' + |
| 127 | + '```\n' |
| 128 | + github.rest.issues.createComment({ |
| 129 | + issue_number: context.issue.number, |
| 130 | + owner: context.repo.owner, |
| 131 | + repo: context.repo.repo, |
| 132 | + body: prComment |
| 133 | + }) |
0 commit comments