name: Run Tests

on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - main

  workflow_dispatch:

jobs:
  build_package:
    name: Run tests
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        PGVERSION:
          - 16
        TEST:
          - ci
          - pagila
          - pagila-multi-steps
          - pagila-standby
          - unit
          - blobs
          - filtering
          - extensions
          - cdc-low-level
          - cdc-test-decoding
          - cdc-endpos-between-transaction
          - cdc-wal2json
          - follow-wal2json
          - follow-9.6
          - follow-data-only
          - endpos-in-multi-wal-txn
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # all history for all branches and tags

      - name: Set Version String From .git
        run: make version

      - name: Set environment variables
        run: |
            echo "TEST=${{ matrix.TEST }}" >> $GITHUB_ENV

      - name: Fix workdir host permissions
        run: |
          chmod a+rwx tests/*/workdir

      - name: Run a test
        timeout-minutes: 5
        run: |
          make tests/${TEST}

  style_checker:
    runs-on: ubuntu-latest
    container: citus/stylechecker:no-py
    steps:
    - uses: actions/checkout@v4.1.7
      name: Checkout code

    - name: Set safe directory for git
      run: |
        git config --global --add safe.directory ${GITHUB_WORKSPACE}

    - name: Check C style
      run: citus_indent --check

  docs:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Build docs
        uses: ammaraskar/sphinx-action@master
        with:
          docs-folder: "docs/"

      - name: Set Version String From .git
        run: make version

      - name: Check that docs are up to date
        run: |
          cat Dockerfile ci/Dockerfile.docs.template > ci/Dockerfile.docs && \
          docker build --file=ci/Dockerfile.docs --tag test-docs . && \
          docker run test-docs
