name: CI PRs

on:
  pull_request:
    branches:
      - 'main'
      - '4.0.x'
      - '3.2.x'
    paths-ignore:
      - '.github/**'

env:
  MAVEN_THREADS: '-T 2'

jobs:
  build_and_verify:
    name: Build and Verify
    if: github.repository == 'spring-cloud/spring-cloud-stream'
    runs-on: ubuntu-latest
    steps:

      - name: Checkout SCSt repo
        uses: actions/checkout@v2

      - name: Setup Maven cache
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-m2-

      - name: Setup Java 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'liberica'

      - name: Setup Maven
        uses: jvalkeal/setup-maven@v1
        with:
          maven-version: 3.8.8
          maven-mirror: 'https://dlcdn.apache.org/maven/maven-3/'

      - name: Build and run unit tests
        run: |
          mvn -B -s .github/settings.xml clean install

      - name: Clean Maven cache
        run: |
          find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr

      - name: Capture Test Results
        if: failure()
        uses: actions/upload-artifact@v3
        with:
          name: test-results
          path: '*/target/surefire-reports/*.*'
          retention-days: 3
