From 99ac52261a5737cfda5cd6227ee15a0cd1b3330e Mon Sep 17 00:00:00 2001 From: 1adept <69433209+1adept@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:10:50 +0200 Subject: [PATCH] nushell: update script script to update nushell using `nix-update` Then to update each plugin - build the plugin as-is - replacing the hash with the new one from the failed build - building again All updated files will be added in git and commited The resulting commit is checked with `nixpkgs-review` --- pkgs/shells/nushell/update.sh | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 pkgs/shells/nushell/update.sh diff --git a/pkgs/shells/nushell/update.sh b/pkgs/shells/nushell/update.sh new file mode 100644 index 000000000000..9a8015e74600 --- /dev/null +++ b/pkgs/shells/nushell/update.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash +#!nix-shell -p git nix-update nixpkgs-review nixfmt-rfc-style + +set -euxo pipefail + +basedir="$(git rev-parse --show-toplevel)" +cd "$basedir" + +branch="update-nushell" +nuPath="pkgs/shells/nushell" + +function staged() { + if git status --porcelain | grep -q -E "^[AM].? +$1"; then + return 0 + else + return 1 + fi +} + +function version() { + grep '\s*version = ' "$nuPath/default.nix" | cut -d'"' -f 2 | head --lines 1 +} + +git checkout -B "$branch" + +version_old=$(version) +if ! staged "$nuPath/default.nix"; then + nix-update nushell + git add "$nuPath/default.nix" +fi +version_new=$(version) + +declare -a plugins=(formats query polars gstat) +for plugin in "${plugins[@]}"; do + attr="nushellPlugins.$plugin" + pluginPath="$nuPath/plugins/$plugin.nix" + + if staged "$pluginPath"; then + echo "Skipping '$plugin' because it's alredy staged" + continue + fi + + echo "Attempting to build $attr" + + set +e + newHash=$(nix build ".#$attr" 2> \ + >(grep got | + awk -F' ' '{ print $2 }')) + set -e + + # New hash ? + if [ -n "$newHash" ]; then + # Add the new hash + sed -i "s!cargoHash = ".*";!cargoHash = \"$newHash\";!" "$pluginPath" + nixfmt "$pluginPath" + + echo "Building $plugin again with new hash $newHash" + nix build ".#$attr" + git add "$pluginPath" + echo "Plugin $plugin built sucessfully" + else + echo "No new hash for '$plugin'" + fi +done + +git commit -m "nushell: $version_old -> $version_new" + +echo "Starting nixpkgs-review" +nixpkgs-review rev "$branch"