name: Check
on:
  pull_request:

env:
  PG_VERSION: 18

jobs:
  format:
    name: Format
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    steps:
      - name: Remove existing PostgreSQL
        run: sudo apt purge postgresql* libpq*

      - name: Clone repository
        uses: actions/checkout@v7
        with:
          submodules: recursive
          path: src
          ref: ${{ github.ref }}

      - name: Clone postgres repository
        uses: actions/checkout@v7
        with:
          path: postgres
          repository: percona/postgres.git
          ref: PSP_REL_${{ env.PG_VERSION }}_STABLE

      - name: Install dependencies
        run: src/.github/scripts/ubuntu-deps.sh dev

      - name: Build and install PostgreSQL
        run: src/.github/scripts/build-postgres.sh debug

      - name: Build pg_stat_monitor
        run: src/.github/scripts/build.sh debug

      - name: Update typedefs
        run: src/.github/scripts/dump-typedefs.sh

      - name: Run pgindent
        run: src/.github/scripts/run-pgindent.sh --check --diff

      - name: Run pgperltidy
        run: src/.github/scripts/run-pgperltidy.sh --assert-tidy --standard-error-output

  license:
    name: License
    runs-on: ubuntu-22.04
    timeout-minutes: 5

    steps:
      - name: Checkout sources
        uses: actions/checkout@v7

      - name: Check license headers
        uses: apache/skywalking-eyes/header@v0.8.0
        with:
          token: "" # Prevent comments
