# If requested by means of a pull request comment, runs integration tests
# against the project, using the code found on the pull request branch.
# XXX: Generalize this to a matrix build of multiple integration tests,
# possibly using multiple JDK or OS versions.
# XXX: Investigate whether the comment can specify which integration tests run
# run. See this example of a dynamic build matrix:
# https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object
name: "Integration tests"
on:
  issue_comment:
    types: [ created ]
permissions:
  contents: read
jobs:
  run-integration-tests:
    name: On-demand integration test
    if: |
      github.event.issue.pull_request && contains(github.event.comment.body, '/integration-test')
    runs-on: ubuntu-22.04
    steps:
      - name: Install Harden-Runner
        uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
        with:
          disable-sudo: true
          egress-policy: block
          allowed-endpoints: >
            api.adoptium.net:443
            checkstyle.org:443
            github.com:443
            objects.githubusercontent.com:443
            oss.sonatype.org:443
            raw.githubusercontent.com:443
            repo.maven.apache.org:443
            repository.sonatype.org:443
      - name: Check out code and set up JDK and Maven
        uses: s4u/setup-maven-action@489441643219d2b93ee2a127b2402eb640a1b947 # v1.13.0
        with:
          checkout-ref: "refs/pull/${{ github.event.issue.number }}/head"
          java-version: 17.0.13
          java-distribution: temurin
          maven-version: 3.9.9
      - name: Install project to local Maven repository
        run: mvn -T1C install -DskipTests -Dverification.skip
      - name: Run integration test
        run: xvfb-run ./integration-tests/checkstyle.sh "${{ runner.temp }}/artifacts"
      - name: Upload artifacts on failure
        if: ${{ failure() }}
        uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
        with:
          name: integration-test-checkstyle
          path: "${{ runner.temp }}/artifacts"
      - name: Remove installed project artifacts
        run: mvn build-helper:remove-project-artifact
