feat(ci): report package sizes
All checks were successful
/ check (push) Successful in 48s
/ build (audiomenu) (push) Successful in 2s
/ build (docs) (push) Successful in 1s
/ build (jpassmenu) (push) Successful in 1s
/ build (nixosConfigurations.vm.config.system.build.toplevel) (push) Successful in 2s
/ build (nvim) (push) Successful in 1s
/ report-size (push) Successful in 1s
All checks were successful
/ check (push) Successful in 48s
/ build (audiomenu) (push) Successful in 2s
/ build (docs) (push) Successful in 1s
/ build (jpassmenu) (push) Successful in 1s
/ build (nixosConfigurations.vm.config.system.build.toplevel) (push) Successful in 2s
/ build (nvim) (push) Successful in 1s
/ report-size (push) Successful in 1s
Added as a comment to the current pull request
This commit is contained in:
parent
6bde92bd91
commit
e7cf864c29
3 changed files with 117 additions and 2 deletions
|
@ -3,12 +3,15 @@ on:
|
|||
jobs:
|
||||
check:
|
||||
runs-on: nixos
|
||||
needs: build
|
||||
steps:
|
||||
- uses: "https://code.forgejo.org/actions/checkout@v4"
|
||||
- run: nix --version
|
||||
- run: nix flake check --keep-going --verbose
|
||||
- name: Run Checks
|
||||
run: nix flake check --keep-going --verbose
|
||||
build:
|
||||
runs-on: nixos
|
||||
if: github.event_name == 'push'
|
||||
strategy:
|
||||
matrix:
|
||||
target:
|
||||
|
@ -20,4 +23,13 @@ jobs:
|
|||
steps:
|
||||
- uses: "https://code.forgejo.org/actions/checkout@v4"
|
||||
- run: nix --version
|
||||
- run: nix build --print-build-logs '.#${{ matrix.target }}'
|
||||
- name: Build target
|
||||
run: nix build --print-build-logs '.#${{ matrix.target }}'
|
||||
report-size:
|
||||
runs-on: nixos
|
||||
needs: build
|
||||
steps:
|
||||
- uses: "https://git.salame.cl/actions/checkout@v4"
|
||||
- run: nix --version
|
||||
- name: Report Size
|
||||
run: ci-scripts/report-size.sh
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
result
|
||||
result-*
|
||||
.direnv/
|
||||
.pre-commit-config.yaml
|
||||
# ignore vm images
|
||||
|
|
102
ci-scripts/report-size.sh
Executable file
102
ci-scripts/report-size.sh
Executable file
|
@ -0,0 +1,102 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
echo 'Retrieving Flake information' >&2
|
||||
flake_info=$(nix flake show --json 2>/dev/null)
|
||||
packages=$(
|
||||
jq --raw-output '.packages."x86_64-linux" | keys[]' <<-EOF
|
||||
$flake_info
|
||||
EOF
|
||||
)
|
||||
echo "Packages:" >&2
|
||||
echo "$packages" >&2
|
||||
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)
|
||||
echo "Calculating size of $package" >&2
|
||||
row=$(nix path-info --size --closure-size --human-readable "$path" 2>/dev/null |
|
||||
sed "s/^\(\S\+\)\(\s\+\)\(\S\+\)\(\s\+\)\(\S\+\)$/| \`$package\` | \3 | \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)
|
||||
echo "Calculating size of $config" >&2
|
||||
row=$(nix path-info --size --closure-size --human-readable "$path" 2>/dev/null |
|
||||
sed "s/^\(\S\+\)\(\s\+\)\(\S\+\)\(\s\+\)\(\S\+\)$/| \`$config\` | \3 | \5 |/")
|
||||
table="$table$row
|
||||
"
|
||||
done
|
||||
|
||||
printf '%s' "$table"
|
||||
}
|
||||
|
||||
markdown() {
|
||||
cat <<-EOF
|
||||
## Outputs' size
|
||||
|
||||
### NixOS Configurations sizes
|
||||
|
||||
$(configuration_size_table)
|
||||
|
||||
|
||||
### Package sizes
|
||||
|
||||
$(package_size_table)
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ "${CI-false}" = "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_REF_NAME" '.[] | select(.head.ref == $head_ref) | .number')
|
||||
|
||||
if [ -z "$pr_number" ]; then
|
||||
echo "No PR created for this commit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Retrieved index: $pr_number" >&2
|
||||
echo "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number" >&2
|
||||
|
||||
echo 'Generating comment body' >&2
|
||||
comment=$(markdown)
|
||||
|
||||
echo 'Posting comment:' >&2
|
||||
echo "$comment" >&2
|
||||
|
||||
echo 'Request data:' >&2
|
||||
data=$(echo '{}' | jq --arg comment "$comment" '.body=$comment')
|
||||
echo "$data" >&2
|
||||
curl -o - -X 'POST' \
|
||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$data"
|
||||
else
|
||||
markdown
|
||||
fi
|
Loading…
Reference in a new issue