try putting everything in one workflow cause gitea doesn't support running the 2nd after the 1st
Some checks failed
nixos config pipeline / show-flake (push) Successful in 37s
nixos config pipeline / deploy (push) Failing after 5s

This commit is contained in:
smayzy 2025-08-09 17:49:22 +02:00
parent 8676253432
commit ade07ccd6f
2 changed files with 20 additions and 34 deletions

View File

@ -1,19 +0,0 @@
name: nix flake show
run-name: ${{ gitea.actor }} pushed to repo. Checking config syntax.
on: [push]
jobs:
show-flake:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Run nix flake show
run: |
echo "Running nix flake show..."
nix flake show --show-trace

View File

@ -1,17 +1,25 @@
name: rebuild server1
run-name: ${{ gitea.actor }} triggered server1 rebuild
name: nixos config pipeline
on:
workflow_run:
workflows: ["nix flake show"]
types:
- completed
on: [push]
jobs:
deploy:
if: ${{ gitea.event.workflow_run.conclusion == 'success' }}
show-flake:
runs-on: ubuntu-latest
outputs:
check-success: ${{ steps.check.outcome == 'success' }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v31
- id: check
name: Run nix flake show
run: nix flake show --show-trace
deploy:
needs: show-flake
if: needs.show-flake.result == 'success'
runs-on: ubuntu-latest
steps:
- name: ssh to server1 and rebuild
uses: appleboy/ssh-action@v1.2.0
@ -21,19 +29,16 @@ jobs:
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..."
new_gen="$(readlink /run/current-system)"
if [ "$new_gen" != "$old_gen" ]; then
nixos-rebuild switch --rollback
else
echo "Build failed before activation — staying on current config"
fi
exit 1
fi