Binary Size Compare workflow (SurgeDM/Surge)
The Binary Size Compare workflow from SurgeDM/Surge, explained and optimized by Latchkey.
A
CI health: A - excellent
Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Binary Size Compare workflow from the SurgeDM/Surge repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
name: Binary Size Compare
on:
pull_request:
branches:
- main
paths-ignore:
- "extension/**"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
compare:
name: Compare Binary Size
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25.0"
check-latest: false
- name: Build and Compare
id: compare
shell: bash
run: |
set -euo pipefail
# Build PR version (using stripped flags to get true production size)
go build -ldflags="-s -w" -o /tmp/binary-pr .
size_pr=$(stat -c%s /tmp/binary-pr)
# Fetch and build Main version
git fetch origin main:refs/remotes/origin/main
git checkout --detach origin/main
go build -ldflags="-s -w" -o /tmp/binary-main .
size_main=$(stat -c%s /tmp/binary-main)
diff=$((size_pr - size_main))
echo "$size_pr" > size_pr.txt
echo "$size_main" > size_main.txt
echo "$diff" > diff.txt
if [ "$size_pr" -gt "$size_main" ]; then
echo "true" > exceeds.txt
else
echo "false" > exceeds.txt
fi
echo "${{ github.event.pull_request.number }}" > pr_number.txt
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-size-data
path: |
size_pr.txt
size_main.txt
diff.txt
exceeds.txt
pr_number.txt
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Binary Size Compare on: pull_request: branches: - main paths-ignore: - "extension/**" permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: compare: timeout-minutes: 30 name: Compare Binary Size runs-on: latchkey-small steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v5 with: go-version: "1.25.0" check-latest: false - name: Build and Compare id: compare shell: bash run: | set -euo pipefail # Build PR version (using stripped flags to get true production size) go build -ldflags="-s -w" -o /tmp/binary-pr . size_pr=$(stat -c%s /tmp/binary-pr) # Fetch and build Main version git fetch origin main:refs/remotes/origin/main git checkout --detach origin/main go build -ldflags="-s -w" -o /tmp/binary-main . size_main=$(stat -c%s /tmp/binary-main) diff=$((size_pr - size_main)) echo "$size_pr" > size_pr.txt echo "$size_main" > size_main.txt echo "$diff" > diff.txt if [ "$size_pr" -gt "$size_main" ]; then echo "true" > exceeds.txt else echo "false" > exceeds.txt fi echo "${{ github.event.pull_request.number }}" > pr_number.txt - name: Upload artifact uses: actions/upload-artifact@v4 with: name: binary-size-data path: | size_pr.txt size_main.txt diff.txt exceeds.txt pr_number.txt
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.