name: Deploy to Mac Mini

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: 서버에 배포
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.SERVER_HOST }}
          username: ${{ secrets.SERVER_USER }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          port: 22
          script: |
            export PATH=$PATH:/usr/local/bin:/opt/homebrew/bin:$HOME/.docker/bin
            cd /tmp
            rm -rf a301-game-server
            git clone https://${{ secrets.GIT_USER }}:${{ secrets.GIT_TOKEN }}@${{ secrets.GIT_HOST }}/A301/a301_game_server.git a301-game-server
            cd a301-game-server
            docker compose down
            docker compose up -d --build
            docker compose logs --tail=20 server
            rm -rf /tmp/a301-game-server
