name: CI

# Every push and pull request builds the extension and runs the full regression
# suite on every supported PostgreSQL. The suite is self-contained: the search and
# npu tests exercise the no-reader / no-NPU paths, so nothing outside PostgreSQL is
# needed. A tag v* also bundles the PGXN release, but only if the suite passes and
# the tag matches META.json.

on:
  push:
    branches: [main]
    tags: ["v*"]
  pull_request:
  schedule:
    - cron: "23 6 * * 1"   # Mondays: catch drift against the newest PostgreSQL

jobs:
  test:
    name: PostgreSQL ${{ matrix.pg }}
    runs-on: ubuntu-latest
    container: pgxn/pgxn-tools
    strategy:
      fail-fast: false
      matrix:
        pg: [18, 19]
    steps:
      - name: Start PostgreSQL ${{ matrix.pg }}
        run: pg-start ${{ matrix.pg }}
      - name: Check out the repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - name: Build, install and run the regression suite
        run: pg-build-test

  release:
    name: PGXN release bundle
    needs: test
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    container: pgxn/pgxn-tools
    steps:
      - name: Check out the repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - name: Check that the tag matches META.json
        run: |
          meta=$(sed -n 's/^   "version": "\(.*\)",$/\1/p' META.json | head -1)
          [ "v$meta" = "${GITHUB_REF_NAME}" ] || { echo "tag ${GITHUB_REF_NAME} but META.json says $meta"; exit 1; }
      - name: Bundle
        run: pgxn-bundle
      - name: Keep the bundle
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: pgxn-bundle
          path: "*.zip"
