name: Pull Request Tests

on:
  pull_request:

concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: true

jobs:
  warm-repo-cache:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Cache
        uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
        with:
          path: .git
          key: gitdb-${{ github.repository_id }}-${{ github.sha }}
  unit-integration-tests:
    name: PR Unit and Integration Tests
    needs:
      - warm-repo-cache
    strategy:
      matrix:
        go-version: [ "1.24", "1.25" ]
      fail-fast: false
    uses: ./.github/workflows/unit-integration-tests.yml
    with:
      go-version: ${{ matrix.go-version }}
    secrets: inherit
  multios-unit-tests:
    needs:
      - warm-repo-cache
    strategy:
      matrix:
        runs-on: [ macos-latest, windows-latest, ubuntu-latest ]
        go-version: [ "1.24", "1.25" ]
      fail-fast: false
    uses: ./.github/workflows/multios-unit-tests.yml
    with:
      go-version: ${{ matrix.go-version }}
      runs-on: ${{ matrix.runs-on }}
    secrets: inherit
  # This is a simple join point to make it easy to set up branch protection rules in GitHub.
  pull-request-tests-done:
    name: PR Unit and Integration Tests / ${{ matrix.name }}
    strategy:
      matrix:
        name: [ "test-contrib", "test-core" ]
    needs:
      - unit-integration-tests
      - multios-unit-tests
    runs-on: ubuntu-latest
    if: success() || failure()
    steps:
      - name: Success
        if: needs.unit-integration-tests.result == 'success' && needs.multios-unit-tests.result == 'success'
        run: echo "Success!"
      - name: Failure
        if: needs.unit-integration-tests.result != 'success' || needs.multios-unit-tests.result != 'success'
        run: echo "Failure!" && exit 1