name: Deploy infrastructure on: check_suite: types: [completed] workflow_dispatch: jobs: nixos: name: Deploy NixOS systems runs-on: ubuntu-latest # https://github.com/sellout/bash-strict-mode/commit/9bf1d65c2f786a9887facfcb81e06d8b8b5f4667 if: github.event.check_suite.app.name == 'Garnix CI' && github.event.check_suite.conclusion == 'success' && github.event.check_suite.latest_check_runs_count >= 10 && github.event.check_suite.head_branch == 'main' concurrency: group: deploy cancel-in-progress: true steps: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@v9 - name: Setup local Nix cache uses: DeterminateSystems/magic-nix-cache-action@v2 - name: Connect to Tailscale uses: tailscale/github-action@v2 with: oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} tags: tag:gha - name: Copy known_hosts run: | set -eux [ ! -d ~/.ssh ] && mkdir -p ~/.ssh cp .known_hosts ~/.ssh/known_hosts - name: Run deploy run: | nix develop --accept-flake-config \ --command deploy opentofu: name: Apply OpenTofu plan needs: nixos runs-on: ubuntu-latest concurrency: group: tofu cancel-in-progress: true steps: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@v9 - name: Setup local Nix cache uses: DeterminateSystems/magic-nix-cache-action@v2 - name: Setup OpenTofu cache uses: terraform-cache/terraform-cache@v1 - name: Authenticate with TF Cloud run: | dir="$HOME/.terraform.d" [ ! -d "$dir" ] && mkdir -p "$dir" cat > "$dir"/credentials.tfrc.json << EOF { "credentials": { "app.terraform.io": { "token": "${{ secrets.TF_API_TOKEN }}" } } } EOF - name: Generate configuration run: nix run .#gen-tf - name: Init workspace run: | nix develop --accept-flake-config \ --command tofu init - name: Validate plan run: | nix develop --accept-flake-config \ --command tofu validate - name: Apply run: | nix develop --accept-flake-config \ --command tofu apply -auto-approve