name: Deploy

on:
  push:
    branches: [main]
    paths-ignore:
      - 'docs/**'
      - 'mkdocs.yml'
      - '*.md'

concurrency:
  group: deploy-${{ github.ref }}
  cancel-in-progress: true

jobs:
  ci:
    uses: ./.github/workflows/ci.yaml

  deploy:
    needs: [ci]
    runs-on: ubuntu-latest

    steps:
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}

      - name: Deploy via SSM
        run: |
          aws ssm send-command \
            --instance-ids "${{ secrets.EC2_INSTANCE_ID }}" \
            --document-name "AWS-RunShellScript" \
            --parameters 'commands=["fossilrepo-deploy"]' \
            --timeout-seconds 300 \
            --output text
          echo "Deploy sent"
