name: Build

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: self-hosted
    steps:
      - name: Pull
        working-directory: /opt/site
        run: git pull origin main
      
      - name: Build
        working-directory: /opt/site
        run: cargo build --release

      - name: Restart site
        working-directory: /opt/site
        run: |
          pkill site || true
          sleep 3
          export RUNNER_TRACKING_ID=self-managed
          nohup ./target/release/site > server.log 2>&1 &
          sleep 2
          pgrep site && echo "Site is running!"
