name: Check Style in Pull Request
on:
  pull_request_target:

jobs:
  checkstyle:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      checks: write
      contents: read
    steps:
      - name: checkout
        uses: actions/checkout@v4
        with:
          ref: refs/pull/${{ github.event.number }}/merge
      - name: Setup Java 17
        uses: actions/setup-java@v3.6.0
        with:
          distribution: zulu
          java-version: 17
      - uses: reviewdog/action-setup@v1
        with:
          reviewdog_version: latest
      - name: download checkstyle
        run: curl -o checkstyle.jar -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-12.1.2/checkstyle-12.1.2-all.jar
      - name: checkstyle
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: java -jar checkstyle.jar -c style.xml -f xml */src | reviewdog -f=checkstyle -name="Checkstyle" -reporter=github-pr-review -fail-level=any