name: Build and Test
on:
  pull_request:
    paths-ignore:
      - documentation/**
  push:
    branches:
      - main
      - release-[0-9]+.[0-9]+*
    paths-ignore:
      - documentation/**

jobs:
  psp:
    name: Percona Server for PostgreSQL
    strategy:
      fail-fast: false
      matrix:
        pg_package: [psp]
        pg_version: [14, 15, 16, 17, 18]
        os: [ubuntu-24.04]
        compiler: [gcc]
        build_type: [debugoptimized]
    uses: ./.github/workflows/build-and-test.yml
    with:
        pg_package: ${{ matrix.pg_package }}
        pg_version: ${{ matrix.pg_version }}
        os: ${{ matrix.os }}
        compiler: ${{ matrix.compiler }}
        build_type: ${{ matrix.build_type }}
    secrets: inherit

  pgdg:
    name: PostgreSQL Development Group
    strategy:
      fail-fast: false
      matrix:
        pg_package: [pgdg]
        pg_version: [14, 15, 16, 17, 18]
        os: [ubuntu-24.04]
        compiler: [gcc]
        build_type: [debugoptimized]
    uses: ./.github/workflows/build-and-test.yml
    with:
        pg_package: ${{ matrix.pg_package }}
        pg_version: ${{ matrix.pg_version }}
        os: ${{ matrix.os }}
        compiler: ${{ matrix.compiler }}
        build_type: ${{ matrix.build_type }}
    secrets: inherit

  source:
    name: Source
    strategy:
      fail-fast: false
      matrix:
        pg_package: [source]
        pg_version: [14, 15, 16, 17, 18, 19]
        os: [ubuntu-24.04]
        compiler: [gcc, clang]
        build_type: [debugoptimized]
    uses: ./.github/workflows/build-and-test.yml
    with:
        pg_package: ${{ matrix.pg_package }}
        pg_version: ${{ matrix.pg_version }}
        os: ${{ matrix.os }}
        compiler: ${{ matrix.compiler }}
        build_type: ${{ matrix.build_type }}
    secrets: inherit

  exec_backend:
    name: EXEC_BACKEND
    strategy:
      fail-fast: false
      matrix:
        pg_package: [source]
        pg_version: [14, 15, 16, 17, 18, 19]
        os: [ubuntu-24.04]
        compiler: [gcc]
        build_type: [exec-backend]
    uses: ./.github/workflows/build-and-test.yml
    with:
        pg_package: ${{ matrix.pg_package }}
        pg_version: ${{ matrix.pg_version }}
        os: ${{ matrix.os }}
        compiler: ${{ matrix.compiler }}
        build_type: ${{ matrix.build_type }}
    secrets: inherit

  macos:
    name: MacOS
    strategy:
      fail-fast: false
      matrix:
        pg_package: [pgdg-macos]
        pg_version: [18]
        os: [macos-15]
        compiler: [clang]
        build_type: [debugoptimized]
    uses: ./.github/workflows/build-and-test.yml
    with:
        pg_package: ${{ matrix.pg_package }}
        pg_version: ${{ matrix.pg_version }}
        os: ${{ matrix.os }}
        compiler: ${{ matrix.compiler }}
        build_type: ${{ matrix.build_type }}
    secrets: inherit

  arm:
    name: ARM
    if: github.event_name != 'pull_request'
    strategy:
      fail-fast: false
      matrix:
        pg_package: [psp]
        pg_version: [17, 18]
        os: [ubuntu-24.04-arm]
        compiler: [gcc, clang]
        build_type: [debugoptimized]
    uses: ./.github/workflows/build-and-test.yml
    with:
        pg_package: ${{ matrix.pg_package }}
        pg_version: ${{ matrix.pg_version }}
        os: ${{ matrix.os }}
        compiler: ${{ matrix.compiler }}
        build_type: ${{ matrix.build_type }}
    secrets: inherit

  slack-notification:
    if: failure() && github.event_name == 'push'
    needs: [psp, pgdg, macos, arm]
    name: Slack Notification
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    steps:
      - name: Notify
        uses: slackapi/slack-github-action@v4.0.0
        with:
          webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
          webhook-type: incoming-webhook
          payload: |
            blocks:
              - type: "section"
                text:
                  type: "mrkdwn"
                  text: "Workflow *${{ github.workflow }}* failed on branch *${{ github.ref_name }}*\n
                   Commit: <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>\n
                   \n
                   <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>"
