Compare commits

..

1 commit

Author SHA1 Message Date
5f3b69c129
ci: test both push and pull_request events
Some checks failed
/ report-size-pr (pull_request) Failing after 2s
/ report-download-check-pr (pull_request) Has been skipped
/ check (treefmt) (push) Successful in 3s
/ report-size (push) Successful in 4s
/ report-download-check (push) Successful in 1s
I think we have a bug with pull_request events so...
2025-07-10 20:06:19 +02:00
10 changed files with 113 additions and 107 deletions

1
.gitignore vendored
View file

@ -1 +0,0 @@
result*

View file

@ -56,9 +56,9 @@ For more details see the [action.yaml](./action.yml) file.
| Name | Size | Size Change | NAR Size | NAR Size Change |
|------|-----:|------------:|---------:|----------------:|
| `gemini` | 11Gi | -2.4Mi | 28Ki | 0 |
| `leo` | 1.6Gi | 0 | 25Ki | 0 |
| `libra` | 9.4Gi | -2.4Mi | 28Ki | 0 |
| `taurus` | 7.6Gi | 0 | 34Ki | 0 |
| `gemini` | 11Gi | -2.4Mi | 28Ki | 0 |
| `leo` | 1.6Gi | 0 | 25Ki | 0 |
| `libra` | 9.4Gi | -2.4Mi | 28Ki | 0 |
| `taurus` | 7.6Gi | 0 | 34Ki | 0 |
</details>

View file

@ -71,7 +71,7 @@ runs:
id: pr-number
if: inputs.comment-on-pr == 'true'
run: |
. "$GITHUB_ACTION_PATH/scripts/utils.sh"
. "$GITHUB_ACTION_PATH/utils.sh"
# If we were triggered by a PR then this is easy
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
@ -135,7 +135,7 @@ runs:
BASE_BRANCH: ${{ inputs.base-branch }}
JOB_NAME: ${{ inputs.job-name }}
run: |
. "$GITHUB_ACTION_PATH/scripts/utils.sh"
. "$GITHUB_ACTION_PATH/utils.sh"
# Input validation
if [ "$DO_COMPARISON" = 'true' ] && [ -z "$JOB_NAME" ]; then
@ -144,17 +144,17 @@ runs:
fi
# Create Size Report
"$GITHUB_ACTION_PATH/scripts/create-report.sh" report.json
"$GITHUB_ACTION_PATH/create-report.sh" > report.json
# Nothing else to do
if [ "$COMMENT" != 'true' ]; then exit 0; fi
# Try to do a comparison report
if [ "$DO_COMPARISON" = 'true' ]; then
if "$GITHUB_ACTION_PATH/scripts/retrieve-old-report.sh" && [ -f old-report.json ]; then
if "$GITHUB_ACTION_PATH/retrieve-old-report.sh" && [ -f old-report.json ]; then
log "Reporting on sizes and comparing to sizes in $HEAD_BRANCH"
"$GITHUB_ACTION_PATH/scripts/comment_on_pr.sh" report.json old-report.json
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json old-report.json
exit 0
else
error 'Failed to do comparison, fallback to posting the report without them'
@ -163,7 +163,7 @@ runs:
# Just report values
log 'Reporting on sizes'
"$GITHUB_ACTION_PATH/scripts/comment_on_pr.sh" report.json
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json
- name: Upload Artifact
uses: https://git.salame.cl/actions/upload-artifact@v4
if: inputs.generate-artifact == 'true'

View file

@ -2,9 +2,9 @@
set -eu
util_path="${GITHUB_ACTION_PATH:-.}/scripts/utils.sh"
util_path="${GITHUB_ACTION_PATH:-.}/utils.sh"
# shellcheck source=scripts/utils.sh
# shellcheck source=utils.sh
. "${util_path}"
# USAGE: json_to_md_rows <FIELD> [JSON_FILE]

86
create-report.sh Executable file
View file

@ -0,0 +1,86 @@
#!/usr/bin/env bash
set -eu
util_path="${GITHUB_ACTION_PATH:-.}/utils.sh"
# shellcheck source=utils.sh
. "${util_path}"
group 'Retrieving Flake information'
flake_info=$(nix flake show --json)
endgroup
group 'Show Packages'
packages=$(
jq --raw-output '.packages."x86_64-linux" | select(. != null) | keys[]' <<-EOF
$flake_info
EOF
)
log "$packages"
endgroup
group 'Show Home Manager Configurations'
hmConfigs=$(
jq --raw-output '.homeConfigurations | select(. != null) | keys[]' <<-EOF
$flake_info
EOF
)
log "$hmConfigs"
endgroup
group 'Show NixOS Configurations'
nixosConfigs=$(
jq --raw-output '.nixosConfigurations | select(. != null) | keys[]' <<-EOF
$flake_info
EOF
)
log "$nixosConfigs"
endgroup
pkgs_json() {
group 'Building packages'
trap endgroup RETURN
for package in $packages; do
log "Building $package"
path=$(nix build --print-out-paths ".#$package")
log "Calculating size of $package"
nix path-info --closure-size --json "$path" |
jq --compact-output --arg pkg "$package" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}'
done
endgroup
}
hm_configs_json() {
group 'Building Home Manager configurations'
trap endgroup RETURN
for config in $hmConfigs; do
log "Building $config"
path=$(nix build --print-out-paths ".#homeConfigurations.$config.activationPackages")
log "Calculating size of $config"
nix path-info --closure-size --json "$path" |
jq --compact-output --arg pkg "$config" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}'
done
}
nixos_configs_json() {
group 'Building NixOS configurations'
trap endgroup RETURN
for config in $nixosConfigs; do
log "Building $config"
path=$(nix build --print-out-paths ".#nixosConfigurations.$config.config.system.build.toplevel")
log "Calculating size of $config"
nix path-info --closure-size --json "$path" |
jq --compact-output --arg pkg "$config" '.[] | {"name": $pkg, "size": .closureSize, "narSize": .narSize}'
done
}
pkgs=$(pkgs_json | jq --slurp '.')
hmConfigs=$(hm_configs_json | jq --slurp '.')
nixosConfigs=$(nixos_configs_json | jq --slurp '.')
echo "{}" | jq \
--argjson pkgs "$pkgs" \
--argjson nixosConfigs "$nixosConfigs" \
--argjson hmConfigs "$hmConfigs" \
'{"packages": $pkgs, "nixosConfigurations": $nixosConfigs, "homeConfigurations": $hmConfigs}'

17
flake.lock generated
View file

@ -20,15 +20,18 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1752076035,
"narHash": "sha256-ROMKbpfgrbogAWXNXJxUu+BoPyZdOq/MQ3UNYVP863o=",
"rev": "9807714d6944a957c2e036f84b0ff8caf9930bc0",
"type": "tarball",
"url": "https://releases.nixos.org/nixos/unstable/nixos-25.11pre826938.9807714d6944/nixexprs.tar.xz?rev=9807714d6944a957c2e036f84b0ff8caf9930bc0"
"lastModified": 1741513245,
"narHash": "sha256-7rTAMNTY1xoBwz0h7ZMtEcd8LELk9R5TzBPoHuhNSCk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e3e32b642a31e6714ec1b712de8c91a3352ce7e1",
"type": "github"
},
"original": {
"type": "tarball",
"url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {

View file

@ -3,7 +3,7 @@
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";

View file

@ -1,6 +1,6 @@
#!/bin/sh
. "${GITHUB_ACTION_PATH}/scripts/utils.sh"
. "${GITHUB_ACTION_PATH}/utils.sh"
repo_info() {
curl -X GET \
@ -74,7 +74,6 @@ curl -X 'GET' \
tar -zvx --strip-components=1 -C "$old"
endgroup
repo_dir=$PWD
(cd "$old" && "$GITHUB_ACTION_PATH/scripts/create-report.sh" "$repo_dir"/old-report.json)
(cd "$old" && "$GITHUB_ACTION_PATH/create-report.sh") >old-report.json
exit 0

View file

@ -1,81 +0,0 @@
#!/bin/sh
set -eu
util_path="${GITHUB_ACTION_PATH:-.}/scripts/utils.sh"
# shellcheck source=scripts/utils.sh
. "${util_path}"
group 'Retrieving Flake information'
flake_info=$(nix flake show --json --quiet --quiet)
endgroup
system=$(nix eval --impure --json --expr 'builtins.currentSystem')
group 'Show Packages'
packages=$(echo "$flake_info" | jq --raw-output --argjson system "$system" 'getpath(["packages", $system]) | select(. != null) | keys[]')
[ -z "$packages" ] || log "$packages"
endgroup
group 'Show Home Manager Configurations'
hmConfigs=$(echo "$flake_info" | jq --raw-output '.homeConfigurations | select(. != null) | keys[]')
[ -z "$hmConfigs" ] || log "$hmConfigs"
endgroup
group 'Show NixOS Configurations'
nixosConfigs=$(echo "$flake_info" | jq --raw-output '.nixosConfigurations | select(. != null) | keys[]')
[ -z "$nixosConfigs" ] || log "$nixosConfigs"
endgroup
closure_size() {
name=$1
path=$2
log "Calculating size of $name at $path"
path_info=$(nix path-info --closure-size --json "$path")
echo "$path_info" |
jq --compact-output \
--arg pkg "$name" \
--arg path "$path" \
'.[] | {"name": $pkg, "path": $path, "size": .closureSize, "narSize": .narSize, "raw": .}'
}
pkgs_json() {
for package in $packages; do
log "Building $package"
path=$(nix build --print-out-paths ".#$package")
closure_size "$package" "$path"
done
}
hm_configs_json() {
for config in $hmConfigs; do
log "Building $config"
path=$(nix build --print-out-paths ".#homeConfigurations.$config.activationPackages")
closure_size "$config" "$path"
done
}
nixos_configs_json() {
for config in $nixosConfigs; do
log "Building $config"
path=$(nix build --print-out-paths ".#nixosConfigurations.$config.config.system.build.toplevel")
closure_size "$config" "$path"
done
}
group 'Building packages'
pkgs=$(pkgs_json | jq --slurp .)
endgroup
group 'Building Home Manager configurations'
hmConfigs=$(hm_configs_json | jq --slurp .)
endgroup
group 'Building NixOS configurations'
nixosConfigs=$(nixos_configs_json | jq --slurp .)
endgroup
echo "{}" | jq \
--argjson pkgs "$pkgs" \
--argjson hmConfigs "$hmConfigs" \
--argjson nixosConfigs "$nixosConfigs" \
'{"packages": $pkgs, "nixosConfigurations": $nixosConfigs, "homeConfigurations": $hmConfigs}' >"${1:-/dev/stdout}"

View file

@ -13,9 +13,9 @@ error() {
}
group() {
echo "::group::$1"
log "::group::$1"
}
endgroup() {
echo '::endgroup::'
log '::endgroup::'
}