configuration.nix/ci-scripts/report-size.sh

37 lines
937 B
Bash
Raw Normal View History

#!/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
tea login add --url "$GITHUB_SERVER_URL" --token "$GITHUB_TOKEN"
pr_index=$(tea pulls -f index,head -o simple | grep "$GITHUB_HEAD_REF" | head -n1 | cut -d' ' -f 1)
tea comment "$pr_index" "$(
cat <<-EOF
### NixOS Configurations sizes
TODO
### Package sizes
$(package_size_table)
EOF
)"
else
package_size_table
fi