-
-
Notifications
You must be signed in to change notification settings - Fork 266
ci: add package version diff comment on PRs #2450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brainrake
wants to merge
9
commits into
develop
Choose a base branch
from
ci/nix-version-diff
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e5aed37
ci: add package version diff comment on PRs
brainrake 21057d7
ci: scope version-diff to changed attrs via drvPath comparison
brainrake 1557660
ci: drop redundant "(see below)" from version-diff summary fallback
brainrake 0e74793
ci: fix stale job names and stop double-evaluating version-diff's HEA…
brainrake f88c75a
ci: shorten comments to one line
brainrake 7bdb267
ci: guard empty artifact glob in version-diff comment
brainrake 80da499
ci: address review, drop dead push-to-cache env and extract shell to …
brainrake f0ac2b7
Update .github/workflows/nix-build.yml
brainrake 433db03
ci: drop --accept-flake-config, use --no-pure-eval, fix treefmt
brainrake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| shopt -s nullglob | ||
|
|
||
| all_no_diff=true | ||
| for dir in diffs/diff-*; do | ||
| file="$dir/diff.txt" | ||
| if [ ! -f "$file" ] || ! grep -q '^No `legacyPackages' "$file"; then | ||
| all_no_diff=false | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| if [ "$all_no_diff" = "true" ]; then | ||
| systems=$(for dir in diffs/diff-*; do echo "\`${dir#diffs/diff-}\`"; done | paste -sd', ') | ||
| { | ||
| echo "<!-- version-diff -->" | ||
| echo "## Package version diff: none" | ||
| echo 'Compares built package versions in `legacyPackages` between this PR and its base commit, per system.' | ||
| echo | ||
| echo "### No Package Differences" | ||
| echo "All packages are hash-identical on all systems (${systems})." | ||
| } >/tmp/comment.md | ||
| else | ||
| { | ||
| echo "<!-- version-diff -->" | ||
| echo "## Package version diff" | ||
| echo 'Compares built package versions in `legacyPackages` between this PR and its base commit, per system.' | ||
| echo | ||
| for dir in diffs/diff-*; do | ||
| system="${dir#diffs/diff-}" | ||
| file="$dir/diff.txt" | ||
| if [ ! -f "$file" ]; then | ||
| echo "<details>" | ||
| echo "<summary>${system}: diff unavailable (job failed or skipped)</summary>" | ||
| echo "</details>" | ||
| echo | ||
| continue | ||
| fi | ||
| if grep -q '^No `legacyPackages' "$file"; then | ||
| # short, no-op case: summary alone, nothing to expand | ||
| echo "<details>" | ||
| echo "<summary>${system}: $(cat "$file")</summary>" | ||
| echo "</details>" | ||
| echo | ||
| continue | ||
| fi | ||
| summary=$(grep '^Closure size:' "$file" | tail -1) | ||
| echo "<details>" | ||
| echo "<summary>${system}: ${summary:-changed}</summary>" | ||
| echo | ||
| echo '```' | ||
| # cap the visible diff so a single arch can't blow the comment size limit | ||
| head -c 20000 "$file" | ||
| if [ "$(wc -c <"$file")" -gt 20000 ]; then | ||
| echo | ||
| echo "... truncated, see workflow run for full output ..." | ||
| fi | ||
| echo '```' | ||
| echo "</details>" | ||
| echo | ||
| done | ||
| } >/tmp/comment.md | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| system="$1" | ||
| head_json="/tmp/head-drvpaths/$system.json" | ||
| base_json="/tmp/base-drvpaths.json" | ||
|
|
||
| if diff -q <(jq -S . "$head_json") <(jq -S . "$base_json") >/dev/null; then | ||
| echo "No \`legacyPackages.$system\` version changes in this PR." >/tmp/diff.txt | ||
| cat /tmp/diff.txt | ||
| exit 0 | ||
| fi | ||
|
|
||
| changed=$(jq -r -n --slurpfile h "$head_json" --slurpfile b "$base_json" ' | ||
| ($h[0]) as $H | ($b[0]) as $B | | ||
| ($H | keys) as $hk | ($B | keys) as $bk | | ||
| ($hk - ($hk - $bk))[] | select($H[.] != $B[.]) | ||
| ') | ||
| added=$(jq -r -n --slurpfile h "$head_json" --slurpfile b "$base_json" ' | ||
| (($h[0] | keys) - ($b[0] | keys))[] | ||
| ') | ||
| removed=$(jq -r -n --slurpfile h "$head_json" --slurpfile b "$base_json" ' | ||
| (($b[0] | keys) - ($h[0] | keys))[] | ||
| ') | ||
|
|
||
| : >/tmp/diff.txt | ||
| for attr in $changed; do | ||
| head_path=$(cd head && nix build ".#legacyPackages.$system.$attr" --no-link --print-out-paths) | ||
| base_path=$(cd base && nix build ".#legacyPackages.$system.$attr" --no-link --print-out-paths) | ||
| nix run nixpkgs#nvd -- diff "$base_path" "$head_path" >>/tmp/diff.txt | ||
| done | ||
| for attr in $added; do | ||
| echo "+ $attr added" >>/tmp/diff.txt | ||
| done | ||
| for attr in $removed; do | ||
| echo "- $attr removed" >>/tmp/diff.txt | ||
| done | ||
|
|
||
| if [ ! -s /tmp/diff.txt ]; then | ||
| echo "No \`legacyPackages.$system\` version changes in this PR." >/tmp/diff.txt | ||
| fi | ||
| cat /tmp/diff.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # dumps legacyPackages.<system> -> drvPath, recursively; used to diff head vs base | ||
| { dir, system }: | ||
| let | ||
| flake = builtins.getFlake dir; | ||
| isDrv = v: (v.type or "") == "derivation"; | ||
| collect = | ||
| prefix: set: | ||
| builtins.concatLists ( | ||
| map ( | ||
| n: | ||
| let | ||
| v = set.${n}; | ||
| in | ||
| if isDrv v then | ||
| [ | ||
| { | ||
| name = prefix + n; | ||
| drvPath = v.drvPath; | ||
| } | ||
| ] | ||
| else if builtins.isAttrs v then | ||
| collect (prefix + n + ".") v | ||
| else | ||
| [ ] | ||
| ) (builtins.attrNames set) | ||
| ); | ||
| in | ||
| builtins.listToAttrs ( | ||
| map (e: { | ||
| inherit (e) name; | ||
| value = e.drvPath; | ||
| }) (collect "" flake.legacyPackages.${system}) | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.