name: Build_Deploy

on:
  workflow_run:
    workflows: [ "Update_Flake" ]
    types:
      - completed
  push:
    branches:
      - 'main'
    paths:
      - applications/**/*
      - machines/**/*
      - secrets/**/*
      - flake.*
      - config/**/*
      - .forgejo/**/*

jobs:
  linter:
    runs-on: nix
    steps:
      - uses: actions/checkout@v4
      - run: nix fmt -- --check .
      - run: nix --version

  #if: github.repository == 'Skynet/nixos'
  build:
    runs-on: nix
    steps:
      - uses: actions/checkout@v4
      - run: nix develop -v
#      - name: Archive Test Results
#        if: always()
#        run: sleep 100m
#      - run: colmena build -v --on @active-dns
#      - run: colmena build -v --on @active-core
#      - run: colmena build -v --on @active
#      - run: colmena build -v --on @active-ext
#      - run: colmena build -v --on @active-gitlab

  deploy_dns:
    runs-on: nix
    needs: [ linter, build ]
    steps:
      - uses: actions/checkout@v4
      - run: colmena apply -v --on @active-dns --show-trace
        shell: bash

  deploy_active:
    strategy:
      matrix:
        batch: [ active-core, active, active-ext ]
    runs-on: nix
    needs: [ deploy_dns ]
    steps:
      - uses: actions/checkout@v4
      - run: colmena apply -v --on @${{ matrix.batch }} --show-trace
        shell: bash