name: Frontend CI/CD

on:
  push:
    branches: [production]
    paths:
      - '**'
      - '.gitea/workflows/frontend.yml'

  pull_request:
    branches: [production]
    paths:
      - '**'
      - '.gitea/workflows/frontend.yml'

jobs:
  build-and-test:
    name: Build, Lint & Test
    runs-on: self-hosted
    container:
      image: mirror2.chabokan.net/ubuntu:24.04

  
      - name: Setup SSH key
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          ssh-keyscan -p ${{ secrets.SERVER_SSH_PORT }} -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts

      - name: Deploy
        run: |
          ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} -p ${{ secrets.SERVER_SSH_PORT }} << 'EOF'
          cd application/Frontend
          git pull origin production
          docker compose -f docker-compose-prod.yml down
          docker compose -f docker-compose-prod.yml up -d --build
          EOF
