Skip to content

compare-binary-sizes #41

compare-binary-sizes

compare-binary-sizes #41

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_CI_RUN_ID: "${{ github.event.workflow_run.id }}"
HEAD_OWNER: "${{ github.event.workflow_run.head_repository.owner.login }}"
HEAD_BRANCH: "${{ github.event.workflow_run.head_branch }}"
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}/pulls?head=${HEAD_OWNER}:${HEAD_BRANCH}&state=open" --jq '.[0] | "\(.number) \(.base.sha)"')
base_run_id=$(gh api "repos/${REPO}/actions/runs?head_sha=${base_sha}&event=push" --jq '[.workflow_runs[] | select(.name == "CI")] | .[0].id')
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}" "${base_run_id}" -n "async-profiler-${p}-${base_sha:0:7}" -D "base/${p}" || continue
gh run download -R "${REPO}" "${PR_CI_RUN_ID}" -p "async-profiler-${p}-*" -D "pr/${p}" || 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