name: Validate against IJ versions
on:
  # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g., for dependabot pull requests)
  push:
    branches: [ main ]
  # Trigger the workflow on any pull request
  pull_request:

jobs:
  # Run plugin structure verification along with IntelliJ Plugin Verifier
  verify:
    name: Verify plugin
    runs-on: ubuntu-latest
    steps:

      # Free GitHub Actions Environment Disk Space
      - name: Maximize Build Space
        uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # main
        with:
          tool-cache: false
          large-packages: false

      # Check out current repository
      - name: Fetch Sources
        uses: actions/checkout@v4

      # Set up Java environment for the next steps
      - name: Setup Java
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: 17
          cache: 'gradle'

      # Setup Gradle
      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v4

      # Run Verify Plugin task and IntelliJ Plugin Verifier tool
      - name: Run Plugin Verification tasks
        run: |
          ./gradlew runPluginVerifier -Dplugin.verifier.home.dir=~/.pluginVerifier
          REPORTS=$(cat ${{ github.workspace }}/build/reports/pluginVerifier/*/report.md | sed 's/^#/##/')
          echo "$REPORTS" >> $GITHUB_STEP_SUMMARY

      # Collect Plugin Verifier Result
      - name: Collect Plugin Verifier Result
        if: ${{ always() }}
        uses: actions/upload-artifact@v4
        with:
          name: pluginVerifier-result
          path: ${{ github.workspace }}/build/reports/pluginVerifier