mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-02 07:01:04 +01:00
ci/update: refactor to produce a single lockfile commit
Refactors the flake update script to consolidate root and dev lockfile updates into a single commit. Changes include: - Captures and normalizes `nix flake update` output. - Removes reliance on `--commit-lock-file` and `--amend`. - Eliminates the need to track or compare HEAD commits manually. - Only commit when flake.lock, flake/dev/flake.lock, or version-info.toml have changes.
This commit is contained in:
parent
f02d566f4c
commit
d269170e38
1 changed files with 77 additions and 49 deletions
126
ci/update.nix
126
ci/update.nix
|
|
@ -26,86 +26,114 @@ writeShellApplication {
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
update_args=( )
|
|
||||||
if [ -n "$commit" ]; then
|
|
||||||
update_args+=( "--commit-lock-file" )
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ensure we run at the root of the flake
|
# Ensure we run at the root of the flake
|
||||||
cd "$(git rev-parse --show-toplevel)"
|
cd "$(git rev-parse --show-toplevel)"
|
||||||
|
|
||||||
currentCommit() {
|
workdir=$(mktemp -d -t update-XXXXXX)
|
||||||
git show --no-patch --format=%h
|
trap 'rm -rf "$workdir"' EXIT
|
||||||
}
|
root_update="$workdir/root_update"
|
||||||
|
dev_update="$workdir/dev_update"
|
||||||
|
root_msg="$workdir/root_msg"
|
||||||
|
dev_msg="$workdir/dev_msg"
|
||||||
|
commit_msg="$workdir/commit_msg"
|
||||||
|
|
||||||
hasChanges() {
|
cleanUpdateOutput() {
|
||||||
old="$1"
|
awk --assign prefix="$PWD/" '
|
||||||
new="$2"
|
# Find the start of the update info block
|
||||||
if [ -n "$commit" ]; then
|
/^warning: updating lock file "/ {
|
||||||
[ "$old" != "$new" ]
|
if (match($0, /"([^"]+)"/, m)) {
|
||||||
elif git diff --quiet; then
|
# Print the first line as `{path} updates:`
|
||||||
return 1
|
path = m[1]
|
||||||
else
|
sub("^" prefix, "", path)
|
||||||
return 0
|
print path " updates:"
|
||||||
fi
|
|
||||||
|
# Mark that we have entered the update info block
|
||||||
|
printing=1
|
||||||
|
}
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print while in the update info block
|
||||||
|
printing {
|
||||||
|
if ($0 == "") exit
|
||||||
|
print
|
||||||
|
}
|
||||||
|
' "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
writeGitHubOutput() {
|
writeGitHubOutput() {
|
||||||
if [ -n "$use_github_output" ] && [ -n "$commit" ]; then
|
if [ -n "$use_github_output" ]; then
|
||||||
{
|
{
|
||||||
echo "$1<<EOF"
|
echo "$1<<EOF"
|
||||||
git show --no-patch --format=%b
|
cat "$2"
|
||||||
echo "EOF"
|
echo "EOF"
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
versionInfo() {
|
versionInfo() {
|
||||||
extra_args=( )
|
echo "Updating version-info"
|
||||||
if [ "$1" = "--amend" ]; then
|
|
||||||
extra_args+=(
|
|
||||||
"--amend"
|
|
||||||
"--no-edit"
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
"$(nix-build ./ci -A version-info --no-out-link)"/bin/version-info
|
"$(nix-build ./ci -A version-info --no-out-link)"/bin/version-info
|
||||||
|
|
||||||
if [ -n "$commit" ]; then
|
|
||||||
git add version-info.toml
|
|
||||||
git commit "''${extra_args[@]}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialise version-info.toml
|
# Initialise version-info.toml
|
||||||
if [ ! -f version-info.toml ]; then
|
if [ ! -f version-info.toml ]; then
|
||||||
echo "Creating version-info file"
|
echo "Creating version-info file"
|
||||||
versionInfo -m "version-info: init"
|
versionInfo
|
||||||
|
if [ -n "$commit" ]; then
|
||||||
|
git add version-info.toml
|
||||||
|
git commit -m "version-info: init"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Commit message summary
|
||||||
|
{
|
||||||
|
# Avoid using impure global config from `nix config show commit-lock-file-summary`
|
||||||
|
nix-instantiate --raw --eval flake.nix --attr nixConfig.commit-lock-file-summary 2>/dev/null \
|
||||||
|
|| echo -n "flake: Update"
|
||||||
|
printf '\n'
|
||||||
|
} >"$commit_msg"
|
||||||
|
|
||||||
# Update the root lockfile
|
# Update the root lockfile
|
||||||
old=$(currentCommit)
|
|
||||||
echo "Updating root lockfile"
|
echo "Updating root lockfile"
|
||||||
nix flake update "''${update_args[@]}"
|
nix flake update 2> >(tee "$root_update" >&2)
|
||||||
new=$(currentCommit)
|
cleanUpdateOutput "$root_update" > "$root_msg"
|
||||||
if hasChanges "$old" "$new"; then
|
if [ -s "$root_msg" ]; then
|
||||||
echo "Updating version-info"
|
{
|
||||||
versionInfo --amend
|
printf '\n'
|
||||||
writeGitHubOutput root_lock_body
|
cat "$root_msg"
|
||||||
|
} >>"$commit_msg"
|
||||||
|
versionInfo
|
||||||
|
writeGitHubOutput root_lock_body "$root_msg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update the dev lockfile
|
# Update the dev lockfile
|
||||||
root_nixpkgs=$(nix eval --raw --file . 'inputs.nixpkgs.rev')
|
root_nixpkgs=$(nix eval --raw --file . 'inputs.nixpkgs.rev')
|
||||||
old=$(currentCommit)
|
|
||||||
echo "Updating dev lockfile"
|
echo "Updating dev lockfile"
|
||||||
nix flake update "''${update_args[@]}" \
|
nix flake update \
|
||||||
--override-input 'dev-nixpkgs' "github:NixOS/nixpkgs/$root_nixpkgs" \
|
--override-input 'dev-nixpkgs' "github:NixOS/nixpkgs/$root_nixpkgs" \
|
||||||
--flake './flake/dev'
|
--flake './flake/dev' \
|
||||||
new=$(currentCommit)
|
2> >(tee "$dev_update" >&2)
|
||||||
if hasChanges "$old" "$new"; then
|
cleanUpdateOutput "$dev_update" > "$dev_msg"
|
||||||
echo "Updating version-info"
|
if [ -s "$dev_msg" ]; then
|
||||||
versionInfo --amend
|
{
|
||||||
writeGitHubOutput dev_lock_body
|
printf '\n'
|
||||||
|
cat "$dev_msg"
|
||||||
|
} >>"$commit_msg"
|
||||||
|
versionInfo
|
||||||
|
writeGitHubOutput dev_lock_body "$dev_msg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Only commit if at least one file has changes
|
||||||
|
if git diff --quiet flake.lock flake/dev/flake.lock version-info.toml; then
|
||||||
|
echo "Nothing to commit"
|
||||||
|
elif [ -n "$commit" ]; then
|
||||||
|
echo "Committing"
|
||||||
|
git add flake.lock flake/dev/flake.lock version-info.toml
|
||||||
|
git commit --file "$commit_msg"
|
||||||
|
else
|
||||||
|
echo "Would commit as (skipping):"
|
||||||
|
cat "$commit_msg"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue