From ea3361a19165902c110529fda5ee1a91e1c627d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sat, 14 Dec 2024 23:49:23 +0100 Subject: [PATCH] wip: report package sizes Added as a comment to the current pull request --- .forgejo/workflows/check.yml | 23 --------------- .forgejo/workflows/size-report.yml | 10 +++++++ .gitignore | 1 + ci-scripts/report-size.sh | 47 ++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 23 deletions(-) delete mode 100644 .forgejo/workflows/check.yml create mode 100644 .forgejo/workflows/size-report.yml create mode 100755 ci-scripts/report-size.sh diff --git a/.forgejo/workflows/check.yml b/.forgejo/workflows/check.yml deleted file mode 100644 index f736669..0000000 --- a/.forgejo/workflows/check.yml +++ /dev/null @@ -1,23 +0,0 @@ -on: - push: -jobs: - check: - runs-on: nixos - steps: - - uses: "https://code.forgejo.org/actions/checkout@v4" - - run: nix --version - - run: nix flake check --keep-going --verbose - build: - runs-on: nixos - strategy: - matrix: - target: - - audiomenu - - docs - - jpassmenu - - nixosConfigurations.vm.config.system.build.toplevel - - nvim - steps: - - uses: "https://code.forgejo.org/actions/checkout@v4" - - run: nix --version - - run: nix build --print-build-logs '.#${{ matrix.target }}' diff --git a/.forgejo/workflows/size-report.yml b/.forgejo/workflows/size-report.yml new file mode 100644 index 0000000..1bf2a41 --- /dev/null +++ b/.forgejo/workflows/size-report.yml @@ -0,0 +1,10 @@ +on: + pull_request: +jobs: + report-size: + runs-on: nixos + steps: + - uses: "https://git.salame.cl/actions/checkout@v4" + - run: nix --version + - name: Report Size + run: ci-scripts/report-size.sh diff --git a/.gitignore b/.gitignore index 880066b..040b2e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ result +result-* .direnv/ .pre-commit-config.yaml # ignore vm images diff --git a/ci-scripts/report-size.sh b/ci-scripts/report-size.sh new file mode 100755 index 0000000..4f5ae89 --- /dev/null +++ b/ci-scripts/report-size.sh @@ -0,0 +1,47 @@ +#!/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 + 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_HEAD_REF" '.[] | select(.head.ref == $head_ref) | .number') + echo "Retrieved index: $pr_number" + echo "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number" + echo 'Generating comment body' + comment=$( + cat <<-EOF + ### NixOS Configurations sizes + + TODO + + ### Package sizes + + $(package_size_table) + EOF + ) + echo 'Posting comment:' + echo "$comment" + curl -o - -v -X 'POST' \ + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments?token=$GITHUB_TOKEN" \ + -H 'accept: application/json' \ + -d "$(echo '{}' | jq --arg comment "$comment" '.body=$comment')" +else + package_size_table +fi