Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/SizeComment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: SizeComment

# spell-checker:ignore zizmor backquote

on:
workflow_run:
workflows: ["make"]
types:
- completed # zizmor: ignore[dangerous-triggers]

permissions: {}
jobs:
post-comment:
permissions:
actions: read # to list workflow runs artifacts
pull-requests: write # to comment on pr

runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
- name: 'Download artifact'
uses: actions/github-script@v9
with:
script: |
// List all artifacts from the make workflow run
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});

// Download the "size-comment" artifact, which contains a PR
// number (NR) and result.txt produced by compare_size_results.py.
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "size-comment"
})[0];
if (!matchArtifact) {
core.info("No size-comment artifact found; nothing to post.");
return;
}
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/size-comment.zip', Buffer.from(download.data));
- name: 'Unzip artifact'
run: |
if [ -f size-comment.zip ]; then
unzip size-comment.zip
fi

- name: 'Comment on PR'
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
if (!fs.existsSync('./NR') || !fs.existsSync('./result.txt')) {
core.info("No size comment payload to post.");
return;
}
var issue_number = Number(fs.readFileSync('./NR'));
if (!issue_number) {
core.info("No PR number; skipping.");
return;
}
var content = fs.readFileSync('./result.txt');
// Only comment when there is something meaningful to say.
// compare_size_results.py only writes the file when there is a
// significant change, so an empty/short body is treated as
// "nothing to report".
if (content.toString().trim().length > 0) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: 'Binary size comparison:\n```\n' + content + '```'
});
}
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ jobs:
- name: Run Python unit tests
shell: bash
run: |
python3 -m unittest util/test_compare_test_results.py
python3 -m unittest util/test_compare_test_results.py util/test_compare_size_results.py

pre_commit:
name: Pre-commit hooks
Expand Down
37 changes: 31 additions & 6 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,33 @@ jobs:
name: size-result
repo: uutils/coreutils
path: dl
- name: Check uutil release sizes
- name: Compare individual binary sizes VS reference
shell: bash
run: |
## Produce a per-binary size comparison and a PR comment body.
## The comment body is consumed by the SizeComment workflow, which
## mirrors GnuComment for the GNU testsuite results.
COMMENT_DIR="size-comment"
mkdir -p "${COMMENT_DIR}"
# `github.event.number` is empty on non-PR events; the downstream
# workflow only posts comments when triggered for a pull request.
echo "${{ github.event.number }}" > "${COMMENT_DIR}/NR"
COMMENT_LOG="${COMMENT_DIR}/result.txt"

if test -f dl/individual-size-result.json; then
python3 util/compare_size_results.py \
individual-size-result.json \
dl/individual-size-result.json \
--output "${COMMENT_LOG}"
else
echo "::warning ::Skipping individual size comparison; no reference is available."
fi
- name: Check uutil release multi-binary sizes
shell: bash
run: |
## The aggregate `multiple binaries` and `multicall binary` totals
## are still checked inline; they are simple scalar comparisons and
## do not feed into the per-binary PR comment.
check() {
# Warn if the size increases by more than 5%
threshold='1.05'
Expand All @@ -232,18 +256,19 @@ jobs:
echo "::warning file=$4::Size of $1 increases by more than 5%"
fi
}
## Check individual size result
while read -r name previous_size; do
size=$(cat individual-size-result.json | jq -r ".[] | .sizes | .\"$name\"")
check "\`$name\` binary" "$size" "$previous_size" 'individual-size-result.json'
done < <(cat dl/individual-size-result.json | jq -r '.[] | .sizes | to_entries[] | "\(.key) \(.value)"')
## Check size result
size=$(cat size-result.json | jq -r '.[] | .size')
previous_size=$(cat dl/size-result.json | jq -r '.[] | .size')
check 'multiple binaries' "$size" "$previous_size" 'size-result.json'
multisize=$(cat size-result.json | jq -r '.[] | .multisize')
previous_multisize=$(cat dl/size-result.json | jq -r '.[] | .multisize')
check 'multicall binary' "$multisize" "$previous_multisize" 'size-result.json'
- name: Upload size comparison comment (for SizeComment workflow)
if: success() || failure() # run regardless of prior step success/failure
uses: actions/upload-artifact@v7
with:
name: size-comment
path: size-comment/
- name: Upload the individual size result
uses: actions/upload-artifact@v7
with:
Expand Down
Loading
Loading