Add workflow to post binary size comparison to pull request comments (#1722)

This commit is contained in:
Ben Taylor
2026-04-27 17:41:18 -07:00
committed by GitHub
parent d3e30d9d6a
commit 5853965e4c
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
name: compare-binary-sizes
on:
workflow_run:
workflows: [CI]
types: [completed]
permissions:
contents: read
pull-requests: write
actions: read
env:
GH_TOKEN: "${{ github.token }}"
REPO: "${{ github.repository }}"
PR_SHA: "${{ github.event.workflow_run.head_sha }}"
jobs:
compare:
if: ${{ github.event.workflow_run.event == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- run: |
gh api "repos/${REPO}/contents/scripts/compare-binary-sizes.sh" -H 'Accept: application/vnd.github.raw' > compare.sh
read pr base_sha < <(gh api "repos/${REPO}/commits/${PR_SHA}/pulls" --jq '.[0] | "\(.number) \(.base.sha)"')
function find-archive() { find "${1}" -type f \( -name "async-profiler-*${2}.tar.gz" -o -name "async-profiler-*${2}.zip" \) ! -name '*-debug*' | head -n1; }
for p in linux-x64 linux-arm64 macos; do
gh run download -R "${REPO}" -n "async-profiler-${p}-${base_sha:0:7}" -D "base/${p}" 2>/dev/null || continue
gh run download -R "${REPO}" -n "async-profiler-${p}-${PR_SHA:0:7}" -D "pr/${p}" 2>/dev/null || continue
bash compare.sh "$(find-archive "base/${p}" "${p}")" "$(find-archive "pr/${p}" "${p}")" >> report.md
done
gh pr comment "${pr}" -R "${REPO}" --body-file report.md --edit-last --create-if-none

31
scripts/compare-binary-sizes.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Copyright The async-profiler authors
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
function list-archive() {
case "${1}" in
*.tar.gz) tar -tzvf "${1}" --wildcards '*/bin/*' '*/lib/*' | awk '$1 ~ /^-/ { print $NF, $3 }' ;;
*.zip) zipinfo -l "${1}" '*/bin/*' '*/lib/*' | awk '$1 ~ /^-/ { print $NF, $4 }' ;;
esac | cut -d/ -f2- | sort
}
function main() {
if [[ ${#} -ne 2 ]]; then
printf 'Usage: compare-binary-sizes.sh <base-archive> <treatment-archive>\n' >&2
exit 1
fi
[[ ${1} =~ (linux-x64|linux-arm64|macos) ]]
printf '### %s\n\n| File | Base (KiB) | Treatment (KiB) | Delta (KiB) | %% Change |\n| --- | ---: | ---: | ---: | ---: |\n' "${BASH_REMATCH[1]}"
join -a1 -a2 -e0 -o '0,1.2,2.2' \
<(list-archive "${1}") \
<(list-archive "${2}") \
| awk '{
b = $2; t = $3; d = t - b; pct = b > 0 ? d * 100 / b : 0
printf "| `%s` | %.2f | %.2f | %+.2f | %+.2f%% |\n", $1, b/1024, t/1024, d/1024, pct
}'
}
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main "$@"