name: Build

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

jobs:
  build:
    runs-on: self-hosted
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      
      - name: Build
        run: |
          export CARGO_TARGET_DIR=~/cache/site_target
          cargo build --release

      - name: Move to opt
        run: |
          mkdir -p /opt/site
          mv target/release/site /opt/site
          mv static /opt/site
          mv templates /opt/site

      - name: Restart site
        working-directory: /opt/site
        run: |
          pkill site || true 
          nohup ./target/release/site > server.log 2>&1 &
