@@ -26,86 +26,114 @@ writeShellApplication {
2626 shift
2727 done
2828
29- update_args=( )
30- if [ -n "$commit" ]; then
31- update_args+=( "--commit-lock-file" )
32- fi
33-
3429 # Ensure we run at the root of the flake
3530 cd "$(git rev-parse --show-toplevel)"
3631
37- currentCommit() {
38- git show --no-patch --format=%h
39- }
32+ workdir=$(mktemp -d -t update-XXXXXX)
33+ trap 'rm -rf "$workdir"' EXIT
34+ root_update="$workdir/root_update"
35+ dev_update="$workdir/dev_update"
36+ root_msg="$workdir/root_msg"
37+ dev_msg="$workdir/dev_msg"
38+ commit_msg="$workdir/commit_msg"
4039
41- hasChanges() {
42- old="$1"
43- new="$2"
44- if [ -n "$commit" ]; then
45- [ "$old" != "$new" ]
46- elif git diff --quiet; then
47- return 1
48- else
49- return 0
50- fi
40+ cleanUpdateOutput() {
41+ awk --assign prefix="$PWD/" '
42+ # Find the start of the update info block
43+ /^warning: updating lock file "/ {
44+ if (match($0, /"([^"]+)"/, m)) {
45+ # Print the first line as `{path} updates:`
46+ path = m[1]
47+ sub("^" prefix, "", path)
48+ print path " updates:"
49+
50+ # Mark that we have entered the update info block
51+ printing=1
52+ }
53+ next
54+ }
55+
56+ # Print while in the update info block
57+ printing {
58+ if ($0 == "") exit
59+ print
60+ }
61+ ' "$1"
5162 }
5263
5364 writeGitHubOutput() {
54- if [ -n "$use_github_output" ] && [ -n "$commit" ] ; then
65+ if [ -n "$use_github_output" ]; then
5566 {
5667 echo "$1<<EOF"
57- git show --no-patch --format=%b
68+ cat "$2"
5869 echo "EOF"
5970 } >> "$GITHUB_OUTPUT"
6071 fi
6172 }
6273
6374 versionInfo() {
64- extra_args=( )
65- if [ "$1" = "--amend" ]; then
66- extra_args+=(
67- "--amend"
68- "--no-edit"
69- )
70- fi
71-
75+ echo "Updating version-info"
7276 "$(nix-build ./ci -A version-info --no-out-link)"/bin/version-info
73-
74- if [ -n "$commit" ]; then
75- git add version-info.toml
76- git commit "'' ${extra_args[@]}"
77- fi
7877 }
7978
8079 # Initialise version-info.toml
8180 if [ ! -f version-info.toml ]; then
8281 echo "Creating version-info file"
83- versionInfo -m "version-info: init"
82+ versionInfo
83+ if [ -n "$commit" ]; then
84+ git add version-info.toml
85+ git commit -m "version-info: init"
86+ fi
8487 fi
8588
89+ # Commit message summary
90+ {
91+ # Avoid using impure global config from `nix config show commit-lock-file-summary`
92+ nix-instantiate --raw --eval flake.nix --attr nixConfig.commit-lock-file-summary 2>/dev/null \
93+ || echo -n "flake: Update"
94+ printf '\n'
95+ } >"$commit_msg"
96+
8697 # Update the root lockfile
87- old=$(currentCommit)
8898 echo "Updating root lockfile"
89- nix flake update "'' ${update_args[@]}"
90- new=$(currentCommit)
91- if hasChanges "$old" "$new"; then
92- echo "Updating version-info"
93- versionInfo --amend
94- writeGitHubOutput root_lock_body
99+ nix flake update 2> >(tee "$root_update" >&2)
100+ cleanUpdateOutput "$root_update" > "$root_msg"
101+ if [ -s "$root_msg" ]; then
102+ {
103+ printf '\n'
104+ cat "$root_msg"
105+ } >>"$commit_msg"
106+ versionInfo
107+ writeGitHubOutput root_lock_body "$root_msg"
95108 fi
96109
97110 # Update the dev lockfile
98111 root_nixpkgs=$(nix eval --raw --file . 'inputs.nixpkgs.rev')
99- old=$(currentCommit)
100112 echo "Updating dev lockfile"
101- nix flake update " '' ${update_args[@]}" \
113+ nix flake update \
102114 --override-input 'dev-nixpkgs' "github:NixOS/nixpkgs/$root_nixpkgs" \
103- --flake './flake/dev'
104- new=$(currentCommit)
105- if hasChanges "$old" "$new"; then
106- echo "Updating version-info"
107- versionInfo --amend
108- writeGitHubOutput dev_lock_body
115+ --flake './flake/dev' \
116+ 2> >(tee "$dev_update" >&2)
117+ cleanUpdateOutput "$dev_update" > "$dev_msg"
118+ if [ -s "$dev_msg" ]; then
119+ {
120+ printf '\n'
121+ cat "$dev_msg"
122+ } >>"$commit_msg"
123+ versionInfo
124+ writeGitHubOutput dev_lock_body "$dev_msg"
125+ fi
126+
127+ # Only commit if at least one file has changes
128+ if git diff --quiet flake.lock flake/dev/flake.lock version-info.toml; then
129+ echo "Nothing to commit"
130+ elif [ -n "$commit" ]; then
131+ echo "Committing"
132+ git add flake.lock flake/dev/flake.lock version-info.toml
133+ git commit --file "$commit_msg"
134+ else
135+ echo "Would commit as (skipping):"
136+ cat "$commit_msg"
109137 fi
110138 '' ;
111139}
0 commit comments