Compare commits
1 commit
87a8d87143
...
eb79878f7d
Author | SHA1 | Date | |
---|---|---|---|
eb79878f7d |
1 changed files with 69 additions and 33 deletions
|
@ -2,21 +2,67 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
package_size_table() {
|
echo 'Retrieving Flake information' >&2
|
||||||
packages=$(nix flake show --json 2>/dev/null | jq --raw-output '.packages."x86_64-linux" | ".#" + keys[]')
|
flake_info=$(nix flake show --json 2>/dev/null)
|
||||||
echo 'Building packages' >&2
|
packages=$(
|
||||||
# we want to split the words as each of them is a different installable
|
jq --raw-output '.packages."x86_64-linux" | keys[]' <<-EOF
|
||||||
# shellcheck disable=SC2086
|
$flake_info
|
||||||
nix build $packages
|
EOF
|
||||||
# shellcheck disable=SC2086
|
)
|
||||||
table=$(nix path-info --size --closure-size --human-readable \
|
echo "Packages:" >&2
|
||||||
$packages |
|
echo "$packages" >&2
|
||||||
sed 's/^\(\S\+\)\(\s\+\)\(\S\+\)\(\s\+\)\(\S\+\)$/| \1\2| \3 | \4\5 |/')
|
configurations=$(
|
||||||
|
jq --raw-output '.nixosConfigurations | keys[]' <<-EOF
|
||||||
|
$flake_info
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
echo "NixOS Configurations:" >&2
|
||||||
|
echo "$configurations" >&2
|
||||||
|
|
||||||
|
package_size_table() {
|
||||||
|
table='| Installable | NAR Size | Closure Size |
|
||||||
|
|-------------|---------:|-------------:|
|
||||||
|
'
|
||||||
|
for package in $packages; do
|
||||||
|
echo "Building $package" >&2
|
||||||
|
path=$(nix build --print-out-paths ".#$package" 2>/dev/null)
|
||||||
|
row=$(nix path-info --size --closure-size --human-readable "$path" 2>/dev/null |
|
||||||
|
sed "s/^\(\S\+\)\(\s\+\)\(\S\+\)\(\s\+\)\(\S\+\)$/| $package | \3 | \4\5 |/")
|
||||||
|
table="$table$row
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
|
printf '%s' "$table"
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration_size_table() {
|
||||||
|
table='| NixOS Configuration | NAR Size | Closure Size |
|
||||||
|
|-------------|---------:|-------------:|
|
||||||
|
'
|
||||||
|
for config in $configurations; do
|
||||||
|
echo "Building $config" >&2
|
||||||
|
path=$(nix build --print-out-paths ".#nixosConfigurations.$config.config.system.build.toplevel" 2>/dev/null)
|
||||||
|
row=$(nix path-info --size --closure-size --human-readable "$path" 2>/dev/null |
|
||||||
|
sed "s/^\(\S\+\)\(\s\+\)\(\S\+\)\(\s\+\)\(\S\+\)$/| $config | \3 | \4 |/")
|
||||||
|
table="$table$row
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
|
printf '%s' "$table"
|
||||||
|
}
|
||||||
|
|
||||||
|
markdown() {
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
| Nix Store Path | NAR Size | Closure Size |
|
## Outputs' size
|
||||||
|----------------|---------:|-------------:|
|
|
||||||
$table
|
### NixOS Configurations sizes
|
||||||
|
|
||||||
|
$(configuration_size_table)
|
||||||
|
|
||||||
|
|
||||||
|
### Package sizes
|
||||||
|
|
||||||
|
$(package_size_table)
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,31 +71,21 @@ if [ "${CI-false}" = "true" ]; then
|
||||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls?state=open&sort=recentupdate" \
|
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls?state=open&sort=recentupdate" \
|
||||||
-H 'accept: application/json' |
|
-H 'accept: application/json' |
|
||||||
jq --arg head_ref "$GITHUB_HEAD_REF" '.[] | select(.head.ref == $head_ref) | .number')
|
jq --arg head_ref "$GITHUB_HEAD_REF" '.[] | select(.head.ref == $head_ref) | .number')
|
||||||
echo "Retrieved index: $pr_number"
|
echo "Retrieved index: $pr_number" >&2
|
||||||
echo "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number"
|
echo "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number" >&2
|
||||||
echo 'Generating comment body'
|
echo 'Generating comment body' >&2
|
||||||
comment=$(
|
comment=$(markdown)
|
||||||
cat <<-EOF
|
echo 'Posting comment:' >&2
|
||||||
### NixOS Configurations sizes
|
echo "$comment" >&2
|
||||||
|
echo 'Request data:' >&2
|
||||||
TODO
|
|
||||||
|
|
||||||
### Package sizes
|
|
||||||
|
|
||||||
$(package_size_table)
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
echo 'Posting comment:'
|
|
||||||
echo "$comment"
|
|
||||||
echo 'Request data:'
|
|
||||||
data=$(echo '{}' | jq --arg comment "$comment" '.body=$comment')
|
data=$(echo '{}' | jq --arg comment "$comment" '.body=$comment')
|
||||||
echo "$data"
|
echo "$data" >&2
|
||||||
curl -o - -v -X 'POST' \
|
curl -o - -X 'POST' \
|
||||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments" \
|
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments" \
|
||||||
-H 'accept: application/json' \
|
-H 'accept: application/json' \
|
||||||
-H "Authorization: token $GITHUB_TOKEN" \
|
-H "Authorization: token $GITHUB_TOKEN" \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "$data"
|
-d "$data"
|
||||||
else
|
else
|
||||||
package_size_table
|
markdown
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue