aboutsummaryrefslogtreecommitdiffhomepage
path: root/.github/workflows/sizediff.yml
blob: b9c40b1ea0a733050f7eaf0d2e8aa069e4d14fe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Binary size difference

on:
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  sizediff:
    # Note: when updating the Ubuntu version, also update the Ubuntu version in
    # sizediff-install-pkgs.sh
    runs-on: ubuntu-24.04
    permissions:
      pull-requests: write
    steps:
      # Prepare, install tools
      - name: Add GOBIN to $PATH
        run: |
          echo "$HOME/go/bin" >> $GITHUB_PATH
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # fetch all history (no sparse checkout)
          submodules: true
      - name: Install apt dependencies
        run: ./.github/workflows/sizediff-install-pkgs.sh
      - name: Restore LLVM source cache
        uses: actions/cache@v4
        id: cache-llvm-source
        with:
          key: llvm-source-18-sizediff-v1
          path: |
            llvm-project/compiler-rt
      - name: Download LLVM source
        if: steps.cache-llvm-source.outputs.cache-hit != 'true'
        run: make llvm-source
      - name: Cache Go
        uses: actions/cache@v4
        with:
          key: go-cache-linux-sizediff-v2-${{ hashFiles('go.mod') }}
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
      - run: make gen-device -j4
      - name: Download drivers repo
        run: git clone https://github.com/tinygo-org/drivers.git
      - name: Save HEAD
        run: git branch github-actions-saved-HEAD HEAD

      # Compute sizes for the PR branch
      - name: Build tinygo binary for the PR branch
        run: go install
      - name: Determine binary sizes on the PR branch
        run: (cd drivers; make smoke-test XTENSA=0 | tee sizes-pr.txt)

      # Compute sizes for the dev branch
      - name: Checkout dev branch
        run: |
          git reset --hard origin/dev
          git checkout --no-recurse-submodules `git merge-base HEAD origin/dev`
      - name: Install apt dependencies on the dev branch
        # this is only needed on a PR that changes the LLVM version
        run: ./.github/workflows/sizediff-install-pkgs.sh
      - name: Build tinygo binary for the dev branch
        run: go install
      - name: Determine binary sizes on the dev branch
        run: (cd drivers; make smoke-test XTENSA=0 | tee sizes-dev.txt)

      # Create comment
      # TODO: add a summary, something like:
      #  - overall size difference (percent)
      #  - number of binaries that grew / shrank / remained the same
      #  - don't show the full diff when no binaries changed
      - name: Calculate size diff
        run: ./tools/sizediff drivers/sizes-dev.txt drivers/sizes-pr.txt | tee sizediff.txt
      - name: Create comment
        run: |
          echo "Size difference with the dev branch:" > comment.txt
          echo "<details><summary>Binary size difference</summary>" >> comment.txt
          echo "<pre>" >> comment.txt
          cat sizediff.txt >> comment.txt
          echo "</pre></details>" >> comment.txt
      - name: Comment contents
        run: cat comment.txt
      - name: Add comment
        if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
        uses: thollander/actions-comment-pull-request@v2.3.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          filePath: comment.txt
          comment_tag: sizediff