name: Check PR Template

on:
  pull_request:
    branches:
      - develop
      - 'release/*'

jobs:
  check:
    name: Check PR Template
    if: ${{ github.repository_owner == 'PaddlePaddle' }}
    runs-on: ubuntu-latest
    env:
      PR_ID: ${{ github.event.pull_request.number }}
      BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
      AUTHOR: ${{ github.event.pull_request.user.login }}

    steps:
      - name: Cleanup
        run: |
          rm -rf * .[^.]*

      - name: Checkout base branch
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.base.ref }}
          fetch-depth: 1000

      - name: Merge PR to test branch
        run: |
          git fetch origin pull/${PR_ID}/merge
          git checkout -b test FETCH_HEAD

      - name: Setup Python 3.10
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'
          cache: 'pip'

      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          pip install httpx

      - name: Check PR Template
        env:
          AGILE_PULL_ID: ${{ env.PR_ID }}
          AGILE_COMPILE_BRANCH: ${{ env.BASE_BRANCH }}
          AGILE_CHECKIN_AUTHOR: ${{ env.AUTHOR }}
          GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          python scripts/CheckPRTemplate.py; EXCODE=$?
          exit $EXCODE
