From ade07ccd6facf0d067b5eaf2746bf19af4c4d35a Mon Sep 17 00:00:00 2001 From: smayzy Date: Sat, 9 Aug 2025 17:49:22 +0200 Subject: [PATCH] try putting everything in one workflow cause gitea doesn't support running the 2nd after the 1st --- .gitea/workflows/nix-flake-show.yml | 19 ---------- .../{nix-rebuild-server1.yml => pipeline.yml} | 35 +++++++++++-------- 2 files changed, 20 insertions(+), 34 deletions(-) delete mode 100644 .gitea/workflows/nix-flake-show.yml rename .gitea/workflows/{nix-rebuild-server1.yml => pipeline.yml} (53%) diff --git a/.gitea/workflows/nix-flake-show.yml b/.gitea/workflows/nix-flake-show.yml deleted file mode 100644 index a628940..0000000 --- a/.gitea/workflows/nix-flake-show.yml +++ /dev/null @@ -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 diff --git a/.gitea/workflows/nix-rebuild-server1.yml b/.gitea/workflows/pipeline.yml similarity index 53% rename from .gitea/workflows/nix-rebuild-server1.yml rename to .gitea/workflows/pipeline.yml index 1bc849d..f89f447 100644 --- a/.gitea/workflows/nix-rebuild-server1.yml +++ b/.gitea/workflows/pipeline.yml @@ -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 +