name: Deploy Frontend

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Extract version tag
        run: echo "VERSION_TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV

      - name: Build Docker image
        run: |
          docker build \
            --build-arg REACT_APP_API_URL="" \
            -t poster-picker-frontend:latest \
            -t poster-picker-frontend:${{ env.VERSION_TAG }} .

      - name: Stop old container
        run: |
          cd ~/dev-server/poster-picker
          docker compose stop frontend || true

      - name: Start new container
        run: |
          cd ~/dev-server/poster-picker
          docker compose up -d --no-build frontend
