Compare commits
5 commits
5f3b69c129
...
f91d393cf9
Author | SHA1 | Date | |
---|---|---|---|
f91d393cf9 | |||
1b14f63169 | |||
a26909cb8c | |||
9364b5d352 | |||
95718c754d |
12 changed files with 158 additions and 118 deletions
|
@ -24,18 +24,17 @@ jobs:
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
# Create a comment on the associated PR
|
# Create a comment on the associated PR
|
||||||
comment-on-pr: ${{ github.ref_name != 'main' }}
|
comment-on-pr: 'false'
|
||||||
# Generate artifacts on main (to speed up comparisons)
|
# Generate artifacts on main (to speed up comparisons)
|
||||||
# generate-artifact: ${{ github.ref_name == 'main' }}
|
# generate-artifact: ${{ github.ref_name == 'main' }}
|
||||||
# Always generate artifacts for testing purposes
|
# Always generate artifacts for testing purposes
|
||||||
generate-artifact: 'true'
|
generate-artifact: 'true'
|
||||||
# Generate comparisons to main
|
# This job's name (so we can find the previous artifacts)
|
||||||
do-comparison: 'true'
|
|
||||||
# This job's name (so we can find the artifacts)
|
|
||||||
job-name: report-size
|
job-name: report-size
|
||||||
report-download-check:
|
report-download-check:
|
||||||
runs-on: nixos
|
runs-on: nixos
|
||||||
needs: report-size
|
needs: report-size-push
|
||||||
|
if: github.event_name == 'push'
|
||||||
steps:
|
steps:
|
||||||
- name: Download previous report
|
- name: Download previous report
|
||||||
uses: https://git.salame.cl/actions/download-artifact@d8d0a99033603453ad2255e58720b460a0555e1e # v4
|
uses: https://git.salame.cl/actions/download-artifact@d8d0a99033603453ad2255e58720b460a0555e1e # v4
|
||||||
|
|
33
.forgejo/workflows/test-pr.yml
Normal file
33
.forgejo/workflows/test-pr.yml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
report-size-pr:
|
||||||
|
runs-on: nixos
|
||||||
|
steps:
|
||||||
|
- uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4
|
||||||
|
- run: nix --version
|
||||||
|
- name: Create Size Report
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
# Create a comment on the associated PR
|
||||||
|
comment-on-pr: 'true'
|
||||||
|
# Generate artifacts on main (to speed up comparisons)
|
||||||
|
# generate-artifact: ${{ github.ref_name == 'main' }}
|
||||||
|
# Always generate artifacts for testing purposes
|
||||||
|
generate-artifact: 'true'
|
||||||
|
# Generate comparisons to main
|
||||||
|
do-comparison: 'true'
|
||||||
|
# Get the previous artifacts from report-size-push (since those run on main)
|
||||||
|
job-name: report-size
|
||||||
|
artifact-name: report.json
|
||||||
|
report-download-check-pr:
|
||||||
|
runs-on: nixos
|
||||||
|
needs: report-size-pr
|
||||||
|
steps:
|
||||||
|
- name: Download previous report
|
||||||
|
uses: https://git.salame.cl/actions/download-artifact@d8d0a99033603453ad2255e58720b460a0555e1e # v4
|
||||||
|
with:
|
||||||
|
name: report.json
|
||||||
|
- name: Verify report exists
|
||||||
|
run: |
|
||||||
|
cat report.json
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
result*
|
26
action.yml
26
action.yml
|
@ -71,7 +71,19 @@ runs:
|
||||||
id: pr-number
|
id: pr-number
|
||||||
if: inputs.comment-on-pr == 'true'
|
if: inputs.comment-on-pr == 'true'
|
||||||
run: |
|
run: |
|
||||||
. "$GITHUB_ACTION_PATH/utils.sh"
|
. "$GITHUB_ACTION_PATH/scripts/utils.sh"
|
||||||
|
|
||||||
|
# If we were triggered by a PR then this is easy
|
||||||
|
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
# expanded by the runner
|
||||||
|
pr_number='${{ github.event.number }}'
|
||||||
|
log "Triggered by a pull request with index: $pr_number"
|
||||||
|
log "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number"
|
||||||
|
log "Writing output to: $GITHUB_OUTPUT"
|
||||||
|
echo "pr-number=$pr_number" >> "$GIHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
log 'Determine head_ref'
|
log 'Determine head_ref'
|
||||||
# For push & tag events it'll bet GITHUB_REF_NAME, for pull_request events it'll be GITHUB_HEAD_REF
|
# For push & tag events it'll bet GITHUB_REF_NAME, for pull_request events it'll be GITHUB_HEAD_REF
|
||||||
|
@ -83,6 +95,8 @@ runs:
|
||||||
-H "Authorization: token $GITHUB_TOKEN" \
|
-H "Authorization: token $GITHUB_TOKEN" \
|
||||||
-H 'Accept: application/json')
|
-H 'Accept: application/json')
|
||||||
|
|
||||||
|
log "Open PRs: $(echo "$prs" | jq --compact output 'map(.number)')"
|
||||||
|
|
||||||
pr_number=$(echo "$prs" |
|
pr_number=$(echo "$prs" |
|
||||||
jq --arg head_ref "$head_ref" '.[] | select(.head.ref == $head_ref) | .number')
|
jq --arg head_ref "$head_ref" '.[] | select(.head.ref == $head_ref) | .number')
|
||||||
|
|
||||||
|
@ -121,7 +135,7 @@ runs:
|
||||||
BASE_BRANCH: ${{ inputs.base-branch }}
|
BASE_BRANCH: ${{ inputs.base-branch }}
|
||||||
JOB_NAME: ${{ inputs.job-name }}
|
JOB_NAME: ${{ inputs.job-name }}
|
||||||
run: |
|
run: |
|
||||||
. "$GITHUB_ACTION_PATH/utils.sh"
|
. "$GITHUB_ACTION_PATH/scripts/utils.sh"
|
||||||
|
|
||||||
# Input validation
|
# Input validation
|
||||||
if [ "$DO_COMPARISON" = 'true' ] && [ -z "$JOB_NAME" ]; then
|
if [ "$DO_COMPARISON" = 'true' ] && [ -z "$JOB_NAME" ]; then
|
||||||
|
@ -130,17 +144,17 @@ runs:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create Size Report
|
# Create Size Report
|
||||||
"$GITHUB_ACTION_PATH/create-report.sh" > report.json
|
"$GITHUB_ACTION_PATH/scripts/create-report.sh" report.json
|
||||||
|
|
||||||
# Nothing else to do
|
# Nothing else to do
|
||||||
if [ "$COMMENT" != 'true' ]; then exit 0; fi
|
if [ "$COMMENT" != 'true' ]; then exit 0; fi
|
||||||
|
|
||||||
# Try to do a comparison report
|
# Try to do a comparison report
|
||||||
if [ "$DO_COMPARISON" = 'true' ]; then
|
if [ "$DO_COMPARISON" = 'true' ]; then
|
||||||
if "$GITHUB_ACTION_PATH/retrieve-old-report.sh" && [ -f old-report.json ]; then
|
if "$GITHUB_ACTION_PATH/scripts/retrieve-old-report.sh" && [ -f old-report.json ]; then
|
||||||
log "Reporting on sizes and comparing to sizes in $HEAD_BRANCH"
|
log "Reporting on sizes and comparing to sizes in $HEAD_BRANCH"
|
||||||
|
|
||||||
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json old-report.json
|
"$GITHUB_ACTION_PATH/scripts/comment_on_pr.sh" report.json old-report.json
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
error 'Failed to do comparison, fallback to posting the report without them'
|
error 'Failed to do comparison, fallback to posting the report without them'
|
||||||
|
@ -149,7 +163,7 @@ runs:
|
||||||
|
|
||||||
# Just report values
|
# Just report values
|
||||||
log 'Reporting on sizes'
|
log 'Reporting on sizes'
|
||||||
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json
|
"$GITHUB_ACTION_PATH/scripts/comment_on_pr.sh" report.json
|
||||||
- name: Upload Artifact
|
- name: Upload Artifact
|
||||||
uses: https://git.salame.cl/actions/upload-artifact@v4
|
uses: https://git.salame.cl/actions/upload-artifact@v4
|
||||||
if: inputs.generate-artifact == 'true'
|
if: inputs.generate-artifact == 'true'
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
#!/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
17
flake.lock
generated
|
@ -20,18 +20,15 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1741513245,
|
"lastModified": 1752076035,
|
||||||
"narHash": "sha256-7rTAMNTY1xoBwz0h7ZMtEcd8LELk9R5TzBPoHuhNSCk=",
|
"narHash": "sha256-ROMKbpfgrbogAWXNXJxUu+BoPyZdOq/MQ3UNYVP863o=",
|
||||||
"owner": "NixOS",
|
"rev": "9807714d6944a957c2e036f84b0ff8caf9930bc0",
|
||||||
"repo": "nixpkgs",
|
"type": "tarball",
|
||||||
"rev": "e3e32b642a31e6714ec1b712de8c91a3352ce7e1",
|
"url": "https://releases.nixos.org/nixos/unstable/nixos-25.11pre826938.9807714d6944/nixexprs.tar.xz?rev=9807714d6944a957c2e036f84b0ff8caf9930bc0"
|
||||||
"type": "github"
|
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"type": "tarball",
|
||||||
"ref": "nixos-unstable",
|
"url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-lib": {
|
"nixpkgs-lib": {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz";
|
||||||
treefmt-nix = {
|
treefmt-nix = {
|
||||||
url = "github:numtide/treefmt-nix";
|
url = "github:numtide/treefmt-nix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
util_path="${GITHUB_ACTION_PATH:-.}/utils.sh"
|
util_path="${GITHUB_ACTION_PATH:-.}/scripts/utils.sh"
|
||||||
|
|
||||||
# shellcheck source=utils.sh
|
# shellcheck source=scripts/utils.sh
|
||||||
. "${util_path}"
|
. "${util_path}"
|
||||||
|
|
||||||
# USAGE: json_to_md_rows <FIELD> [JSON_FILE]
|
# USAGE: json_to_md_rows <FIELD> [JSON_FILE]
|
81
scripts/create-report.sh
Executable file
81
scripts/create-report.sh
Executable file
|
@ -0,0 +1,81 @@
|
||||||
|
#!/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}"
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
. "${GITHUB_ACTION_PATH}/utils.sh"
|
. "${GITHUB_ACTION_PATH}/scripts/utils.sh"
|
||||||
|
|
||||||
repo_info() {
|
repo_info() {
|
||||||
curl -X GET \
|
curl -X GET \
|
||||||
|
@ -74,6 +74,7 @@ curl -X 'GET' \
|
||||||
tar -zvx --strip-components=1 -C "$old"
|
tar -zvx --strip-components=1 -C "$old"
|
||||||
endgroup
|
endgroup
|
||||||
|
|
||||||
(cd "$old" && "$GITHUB_ACTION_PATH/create-report.sh") >old-report.json
|
repo_dir=$PWD
|
||||||
|
(cd "$old" && "$GITHUB_ACTION_PATH/scripts/create-report.sh" "$repo_dir"/old-report.json)
|
||||||
|
|
||||||
exit 0
|
exit 0
|
|
@ -13,9 +13,9 @@ error() {
|
||||||
}
|
}
|
||||||
|
|
||||||
group() {
|
group() {
|
||||||
log "::group::$1"
|
echo "::group::$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
endgroup() {
|
endgroup() {
|
||||||
log '::endgroup::'
|
echo '::endgroup::'
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue