name: Deploy arikigame.com

on:
  push:
    branches: [main]
    paths:
      - 'public/**'
      - '.gitea/workflows/deploy.yml'

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

jobs:
  deploy:
    runs-on: deploy
    steps:
      - uses: tinqs/ci/checkout@v1

      - uses: tinqs/ci/setup-aws@v1

      - name: Deploy static site to S3 + CloudFront
        env:
          S3_BUCKET: arikigame-com-website
          CF_DISTRIBUTION: EDMY8TXLTDXLQ
        run: |
          set -e
          SRC="public"
          if [ ! -d "$SRC" ]; then
            echo "Missing $SRC — nothing to deploy"
            exit 1
          fi
          echo "Syncing $SRC -> s3://${S3_BUCKET}/"
          aws s3 sync "$SRC" "s3://${S3_BUCKET}/" --delete \
            --cache-control "public, max-age=300"
          echo "Invalidating CloudFront ${CF_DISTRIBUTION}..."
          aws cloudfront create-invalidation \
            --distribution-id "${CF_DISTRIBUTION}" \
            --paths "/*"
          echo "OK arikigame.com deployed from ozan/ariki-website/public"
