name: git commit AiDA python develop 分支构建部署
on:
  workflow_dispatch:
  push:
    branches:
      - develop

jobs:
  scheduled_deploy:
    runs-on: ubuntu-latest
    if: "contains(github.event.head_commit.message, '[run build]')"

    env:
      REMOTE_DEPLOY_PATH: /workspace/Trinity/Fastapi_AiDA_Trinity_Dev

    steps:
      - name: 1.检出代码
        uses: actions/checkout@v4
        with:
          ref: 'develop'

      - name: 2.复制文件到服务器
        uses: appleboy/scp-action@v0.1.7
        with:
          host: ${{ secrets.SERVER_HOST }}
          username: ${{ secrets.SERVER_USER }}
          password: ${{ secrets.SERVER_PASSWORD }}
          source: "."
          target: ${{ env.REMOTE_DEPLOY_PATH }}
      
      - name: Restart Docker containers
        uses: appleboy/ssh-action@v0.1.10
        with:
          host: ${{ secrets.SERVER_HOST }}
          username: ${{ secrets.SERVER_USER }}
          password: ${{ secrets.SERVER_PASSWORD }}
          script: |
            # 进入项目目录
            cd ${{ env.REMOTE_DEPLOY_PATH }}
            
            docker-compose down 2>&1
            docker-compose up -d --build --remove-orphans 2>&1
            
            docker image prune -f 2>&1