add auto rebuild workflow
All checks were successful
nix flake show / show-flake (push) Successful in 32s
All checks were successful
nix flake show / show-flake (push) Successful in 32s
This commit is contained in:
parent
46c9281a62
commit
a5cf020c70
40
.gitea/workflows/nix-rebuild-server1.yml
Normal file
40
.gitea/workflows/nix-rebuild-server1.yml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
name: rebuild server1
|
||||||
|
run-name: ${{ gitea.actor }} triggered server1 rebuild
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["nix flake show"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
if: ${{ gitea.event.workflow_run.conclusion == 'success' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: ssh to server1 and rebuild
|
||||||
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SERVER1_HOST }}
|
||||||
|
username: root
|
||||||
|
key: ${{ secrets.SERVER1_KEY }}
|
||||||
|
script: |
|
||||||
|
set -e
|
||||||
|
echo "Pulling repo ..."
|
||||||
|
cd /home/smayzy/nix-config
|
||||||
|
git pull
|
||||||
|
|
||||||
|
echo "Rebuilding system ..."
|
||||||
|
old_gen="$(readlink /run/current-system)"
|
||||||
|
if nixos-rebuild switch --flake .#server1 --show-trace; then
|
||||||
|
echo "Deployment successful"
|
||||||
|
else
|
||||||
|
if [ "$(readlink /run/current-system)" != "$old_gen" ]; then
|
||||||
|
echo "Build failed after activation — rolling back..."
|
||||||
|
nixos-rebuild switch --rollback
|
||||||
|
else
|
||||||
|
echo "Build failed before activation — staying on current config"
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Loading…
Reference in New Issue
Block a user