feat(fish): add remote deploy helper #55
@@ -101,3 +101,5 @@ The domain model (Host, Module, Skeleton, Auto-loader, Enable convention, overla
|
|||||||
Keep fractional scaling sharp with Hyprland's `xwayland.force_zero_scaling` and Steam's own `STEAM_FORCE_DESKTOPUI_SCALING` instead.
|
Keep fractional scaling sharp with Hyprland's `xwayland.force_zero_scaling` and Steam's own `STEAM_FORCE_DESKTOPUI_SCALING` instead.
|
||||||
- AdGuard's LAN wildcard rewrite for `*.alexion.dev` points names at the reverse-proxy guest, including non-HTTP ports.
|
- AdGuard's LAN wildcard rewrite for `*.alexion.dev` points names at the reverse-proxy guest, including non-HTTP ports.
|
||||||
Keep `git.alexion.dev:2022` working by proxying that TCP stream through the reverse-proxy guest to Gitea.
|
Keep `git.alexion.dev:2022` working by proxying that TCP stream through the reverse-proxy guest to Gitea.
|
||||||
|
- Remote deploy helpers that run target-side `sudo` over SSH need a TTY.
|
||||||
|
Use `ssh -t` unless the target command is guaranteed not to prompt for sudo credentials.
|
||||||
|
|||||||
@@ -120,6 +120,11 @@ in
|
|||||||
description = "Copy a file, or recursively copy a source directory into a destination";
|
description = "Copy a file, or recursively copy a source directory into a destination";
|
||||||
body = builtins.readFile ./functions/copy.fish;
|
body = builtins.readFile ./functions/copy.fish;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deploy-to = {
|
||||||
|
description = "Deploy the current dotfiles branch to a host through target-local nixos-rebuild";
|
||||||
|
body = builtins.readFile ./functions/deploy-to.fish;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Rendered by home-manager into ~/.config/fish/config.fish.
|
# Rendered by home-manager into ~/.config/fish/config.fish.
|
||||||
|
|||||||
53
modules/fish/functions/deploy-to.fish
Normal file
53
modules/fish/functions/deploy-to.fish
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
if test (count $argv) -lt 1; or test (count $argv) -gt 2
|
||||||
|
echo "usage: deploy-to <host> [branch]" >&2
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
|
||||||
|
set host $argv[1]
|
||||||
|
set branch $argv[2]
|
||||||
|
|
||||||
|
if test -z "$branch"
|
||||||
|
set branch (git branch --show-current)
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -z "$branch"
|
||||||
|
echo "deploy-to: could not determine the current branch" >&2
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
|
||||||
|
git rev-parse --show-toplevel >/dev/null 2>&1
|
||||||
|
or begin
|
||||||
|
echo "deploy-to: run this from a git checkout" >&2
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
|
||||||
|
set dirty_lines (git status --porcelain)
|
||||||
|
if test (count $dirty_lines) -gt 0
|
||||||
|
echo "deploy-to: refusing to deploy with a dirty local worktree" >&2
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
git fetch origin
|
||||||
|
or return $status
|
||||||
|
|
||||||
|
set remote_ref refs/remotes/origin/$branch
|
||||||
|
git rev-parse --verify --quiet $remote_ref >/dev/null
|
||||||
|
or begin
|
||||||
|
echo "deploy-to: origin/$branch does not exist" >&2
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set local_head (git rev-parse HEAD)
|
||||||
|
set remote_head (git rev-parse $remote_ref)
|
||||||
|
|
||||||
|
if test "$local_head" != "$remote_head"
|
||||||
|
echo "deploy-to: local HEAD differs from origin/$branch" >&2
|
||||||
|
echo "deploy-to: push or reset the branch before deploying" >&2
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set escaped_branch (string escape -- $branch)
|
||||||
|
set escaped_host (string escape -- $host)
|
||||||
|
set remote_command "cd ~/wrk/dotfiles && git fetch origin && git switch -- $escaped_branch && git reset --hard origin/$escaped_branch && sudo nixos-rebuild switch --flake .#$escaped_host --print-build-logs"
|
||||||
|
|
||||||
|
ssh -t $host $remote_command
|
||||||
Reference in New Issue
Block a user