configuration.nix/ci-scripts/report-size.sh
Jalil David Salamé Messina dcb8126e67
All checks were successful
/ report-size (pull_request) Successful in 25s
wip: report package sizes
Added as a comment to the current pull request
2024-12-15 11:41:45 +01:00

50 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
package_size_table() {
packages=$(nix flake show --json 2>/dev/null | jq --raw-output '.packages."x86_64-linux" | ".#" + keys[]')
# we want to split the words as each of them is a different installable
# shellcheck disable=SC2086
nix build $packages
# shellcheck disable=SC2086
table=$(nix path-info --size --closure-size --human-readable \
$packages |
sed 's/^\(\S\+\)\(\s\+\)\(\S\+\)\(\s\+\)\(\S\+\)$/| \1\2| \3 | \4\5 |/')
cat <<-EOF
| Nix Store Path | NAR Size | Closure Size |
|----------------|---------:|-------------:|
$table
EOF
}
if [ "$CI" = "true" ]; then
pr_number=$(curl -X 'GET' \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls?state=open&sort=recentupdate" \
-H 'accept: application/json' |
jq --arg head_ref "$GITHUB_HEAD_REF" '.[] | select(.head.ref == $head_ref) | .number')
echo "Retrieved index: $pr_number"
echo "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number"
echo 'Generating comment body'
comment=$(
cat <<-EOF
### NixOS Configurations sizes
TODO
### Package sizes
$(package_size_table)
EOF
)
echo 'Posting comment:'
echo "$comment"
echo 'Request data:'
data=$(echo '{}' | jq --arg comment "$comment" '.body=$comment')
echo "$data"
curl -o - -v -X 'POST' \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments?token=$GITHUB_TOKEN" \
-H 'accept: application/json' \
-d "$data"
else
package_size_table
fi