Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
302 changes: 300 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,315 @@
name: CI
on: [push, pull_request]
jobs:
# Cheap gate that lets the heavy jobs below skip themselves on commits that
# touch only docs. Must run on every push/pull_request (no paths-ignore on
# the workflow itself), otherwise the required all-checks-passed check
# would never report on doc-only pushes and get stuck Pending in branch
# protection.
#
# Also derives, from a SINGLE set of constants, the supported-PostgreSQL-
# major list the test / extension-update jobs consume (see the "Derive ..."
# step) - per Postgres-Extensions/cat_tools PR #48, taken near-verbatim:
# count_nulls has no legacy-floor complication (unlike cat_tools's PG10-only
# pre-0.2.2 scripts), so this needs only ONE list, not cat_tools's three.
changes:
name: 🔍 Detect docs-only changes & derive PG matrix
runs-on: ubuntu-latest
outputs:
docs_only: ${{ steps.diff.outputs.docs_only }}
supported_pg: ${{ steps.pg.outputs.supported_pg }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
# Full history needed so BASE and HEAD below are both reachable
# for `git diff`.
fetch-depth: 0
- name: Compute per-push changed files
id: diff
run: |
if [ "${{ github.event_name }}" = "pull_request" ] && \
[ "${{ github.event.action }}" = "synchronize" ] && \
[ -n "${{ github.event.before }}" ]; then
# A push to an already-open PR: before/after give the true
# per-push diff, same as for a branch push.
BASE="${{ github.event.before }}"
HEAD="${{ github.event.after }}"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
# First run for this PR (opened/reopened/etc, or synchronize
# without a usable before): fall back to the whole base...head
# diff.
BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
else
BASE="${{ github.event.before }}"
HEAD="${{ github.event.after }}"
fi

echo "base=$BASE"
echo "head=$HEAD"

# Fail-safe: a missing HEAD, or an all-zeros BASE (e.g. a new
# branch's first push, where GitHub reports no prior commit),
# means we can't compute a real diff. Run the full matrix rather
# than risk skipping tests.
if [ -z "$HEAD" ] || [ -z "$BASE" ] || [[ "$BASE" =~ ^0+$ ]]; then
echo "docs_only=false" >> "$GITHUB_OUTPUT"
exit 0
fi

CHANGED=$(git diff --name-only "$BASE" "$HEAD" || echo __DIFF_FAILED__)

DOCS_ONLY=true
if [ "$CHANGED" = "__DIFF_FAILED__" ] || [ -z "$CHANGED" ]; then
DOCS_ONLY=false
else
while IFS= read -r f; do
if ! [[ "$f" =~ \.(md|asc)$ ]]; then
DOCS_ONLY=false
break
fi
done <<< "$CHANGED"
fi

echo "changed files:"
echo "$CHANGED"
echo "docs_only=$DOCS_ONLY" >> "$GITHUB_OUTPUT"

- name: Derive the supported-PostgreSQL-major list
id: pg
run: |
# Spending a dozen-odd lines to replace what looks like a handful of
# version references is worth doing anyway: the point is
# CONSISTENCY - both the fresh-install `test` matrix and the
# `extension-update-test` matrix derive their PostgreSQL set from
# this ONE source, so they cannot silently drift onto different
# lists. Adding a new major is a one-line NEWEST bump here, not an
# edit in N places.
#
# count_nulls has only ONE floor (unlike cat_tools's separate
# current-version floor and legacy pre-0.2.2 floor): 0.9.6 is a
# pure-SQL-function install script with no catalog-version
# sensitivity, so it installs on every PostgreSQL major count_nulls
# supports - there is no PG10-only legacy leg to carve out.
NEWEST=17
FLOOR=10

supported=$(seq "$NEWEST" -1 "$FLOOR")

# Emit a JSON array from a list of ints, for the job matrices to
# consume with fromJSON (GitHub evaluates a literal dollar-brace
# expression even inside a run block, so none is written here).
json() { printf '%s\n' "$@" | paste -sd, - | sed 's/^/[/; s/$/]/'; }

echo "supported_pg=$(json $supported)" >> "$GITHUB_OUTPUT"

# Baseline: fresh CREATE EXTENSION, across the PG matrix AND a schema
# matrix (TEST_SCHEMA, picked up from the environment by test/deps.sql via
# the count_nulls.test_schema GUC - see the Makefile). 'public' is the
# common case; 'Quoted' requires SQL identifier quoting (mixed case -
# unquoted would fold to lowercase and silently test 'public' again),
# exercising the suite's %I schema-qualification rather than just its
# literal test data.
test:
needs: [changes]
if: needs.changes.outputs.docs_only != 'true'
strategy:
matrix:
pg: [17, 16, 15, 14, 13, 12, 11, 10]
name: 🐘 PostgreSQL ${{ matrix.pg }}
# From the single source in the changes job.
pg: ${{ fromJSON(needs.changes.outputs.supported_pg) }}
schema: [public, Quoted]
name: 🐘 PostgreSQL ${{ matrix.pg }} (schema ${{ matrix.schema }})
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
env:
TEST_SCHEMA: ${{ matrix.schema }}
steps:
- name: Start PostgreSQL ${{ matrix.pg }}
run: pg-start ${{ matrix.pg }}
- name: Check out the repo
uses: actions/checkout@v4
- name: Test on PostgreSQL ${{ matrix.pg }}
run: pg-build-test

# Proves the in-place extension update path: CREATE EXTENSION at the
# oldest version we still ship a full install script for (0.9.6), then
# ALTER EXTENSION UPDATE (no pg_upgrade, same PostgreSQL), then run the
# FULL suite against the updated database (same expected output as a
# fresh install of the same schema, so an updated DB must behave
# identically). Complements pg-upgrade-test, which covers the
# cross-major-version binary upgrade instead.
extension-update-test:
needs: [changes]
if: needs.changes.outputs.docs_only != 'true'
strategy:
matrix:
# From the single source in the changes job.
pg: ${{ fromJSON(needs.changes.outputs.supported_pg) }}
schema: [public, Quoted]
name: ⬆️ Extension update test on PostgreSQL ${{ matrix.pg }} (schema ${{ matrix.schema }})
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
steps:
- name: Start PostgreSQL ${{ matrix.pg }}
run: pg-start ${{ matrix.pg }}
- name: Check out the repo
uses: actions/checkout@v4
- name: Install count_nulls
run: make install
- name: Update 0.9.6 -> current and run the suite (existing mode)
# update-scenario creates a real database at 0.9.6, plants + proves
# the dependency guard, ALTER EXTENSION UPDATEs to the current
# version, and runs the suite against that updated database in
# existing mode (asserting the version and that the guard still
# blocked a drop, before dropping it itself - see bin/test_existing).
run: bin/test_existing update-scenario count_nulls_update "${{ matrix.schema }}" 0.9.6

# Proves count_nulls survives a BINARY pg_upgrade (in-place catalog
# migration to a newer PostgreSQL major), not just an in-place extension
# update. Installs 0.9.6 on an old cluster, plants a dependency guard,
# binary-pg_upgrades to a newer cluster, updates the extension to current,
# then runs the suite against the REAL migrated objects in existing mode.
# No bridge-update step (unlike cat_tools's pg-upgrade-test, which has to
# dig itself out of pg_upgrade-unsafe versions it shipped before this
# testing pattern existed): count_nulls has always been pure SQL functions
# with no SELECT-*-over-catalog views, so it has no known
# pg_upgrade-unsafe old version to bridge past
# (advanced-extension-testing.md #7/#9).
#
# Deliberately NOT adding cat_tools's companion `pg-upgrade-stepwise` job
# (one cluster climbing every major in sequence, vs. the single big jumps
# here): that job exists to catch a regression specific to one particular
# major-to-major boundary, which matters for cat_tools's views/functions
# that touch catalog internals (advanced-extension-testing.md #7) but not
# for count_nulls - pure SQL functions over anyarray/json/jsonb, nothing
# version-sensitive to break at a specific boundary. The two big-jump legs
# below (10->17, 12->17) already cover the axis that matters here. Revisit
# if count_nulls ever grows something catalog-touching.
pg-upgrade-test:
needs: [changes]
if: needs.changes.outputs.docs_only != 'true'
strategy:
matrix:
include:
- old_pg: "10"
new_pg: "17"
schema: public
- old_pg: "10"
new_pg: "17"
schema: Quoted
- old_pg: "12"
new_pg: "17"
schema: public
- old_pg: "12"
new_pg: "17"
schema: Quoted
name: 🔄 Binary pg_upgrade ${{ matrix.old_pg }} → ${{ matrix.new_pg }} (schema ${{ matrix.schema }})
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
env:
# Both clusters must use the same initdb options or pg_upgrade
# refuses to run.
INITDB_OPTS: --data-checksums --auth trust
steps:
- name: Start PostgreSQL ${{ matrix.old_pg }}
run: pg-start ${{ matrix.old_pg }}
- name: Recreate old cluster with data checksums enabled
run: |
pg_ctlcluster ${{ matrix.old_pg }} test stop
pg_dropcluster ${{ matrix.old_pg }} test
# -p 5432: pg_createcluster assigns the next available port, which
# may not be 5432 after pg-start has claimed and released it.
# Force 5432 so subsequent psql/createdb calls connect without -p.
pg_createcluster -p 5432 ${{ matrix.old_pg }} test -- $INITDB_OPTS
pg_ctlcluster ${{ matrix.old_pg }} test start
pg_isready -t 30
- name: Check out the repo
uses: actions/checkout@v4
- name: Install count_nulls into old cluster
run: make install
- name: Prepare the old cluster (install + dependency guard)
# prepare-old installs count_nulls at 0.9.6 in the leg's schema,
# then plants + proves the dependency guard, so a later accidental
# CASCADE drop anywhere in this job cannot silently make the
# eventual existing-mode run test a fresh install instead.
run: bin/test_existing prepare-old count_nulls_upgrade "${{ matrix.schema }}" 0.9.6
- name: Install PostgreSQL ${{ matrix.new_pg }}
run: apt-get install -y postgresql-${{ matrix.new_pg }} postgresql-server-dev-${{ matrix.new_pg }}
- name: Install count_nulls into new cluster
# PG_CONFIG must be specified explicitly: at this point both old
# and new PostgreSQL are installed, and the default pg_config on
# PATH may not be the new version's.
run: make install PG_CONFIG=/usr/lib/postgresql/${{ matrix.new_pg }}/bin/pg_config
- name: Stop old cluster, binary pg_upgrade to PostgreSQL ${{ matrix.new_pg }}, start new cluster
run: |
pg_ctlcluster ${{ matrix.old_pg }} test stop
pg_createcluster -p 5432 ${{ matrix.new_pg }} test -- $INITDB_OPTS
# PG17+ writes logs to $new_datadir/pg_upgrade_output.d/; older
# versions write to CWD. Search both on failure.
mkdir -p /tmp/pg_upgrade_logs
chown postgres:postgres /tmp/pg_upgrade_logs
su -c "cd /tmp/pg_upgrade_logs && /usr/lib/postgresql/${{ matrix.new_pg }}/bin/pg_upgrade \
-b /usr/lib/postgresql/${{ matrix.old_pg }}/bin \
-B /usr/lib/postgresql/${{ matrix.new_pg }}/bin \
-d /var/lib/postgresql/${{ matrix.old_pg }}/test \
-D /var/lib/postgresql/${{ matrix.new_pg }}/test \
-o '-c config_file=/etc/postgresql/${{ matrix.old_pg }}/test/postgresql.conf' \
-O '-c config_file=/etc/postgresql/${{ matrix.new_pg }}/test/postgresql.conf'" postgres \
|| { find /tmp/pg_upgrade_logs \
/var/lib/postgresql/${{ matrix.new_pg }}/test/pg_upgrade_output.d \
-name '*.log' 2>/dev/null | sort | xargs -r tail -n +1; exit 1; }
pg_ctlcluster ${{ matrix.new_pg }} test start
- name: Update the pg_upgraded extension to the current version
# Exercises ALTER EXTENSION UPDATE on genuinely pg_upgraded objects
# (the extension binary pg_upgrade just migrated), running the
# 0.9.6->1.0.0 update script.
run: bin/test_existing update count_nulls_upgrade
- name: Run the suite against the pg_upgraded database (existing mode)
# run-suite asserts the version, re-proves the dependency guard
# still blocks a non-CASCADE drop (i.e. it survived pg_upgrade),
# drops the guard, then runs the suite against the REAL pg_upgraded
# + updated database via --use-existing (so pg_regress does not
# drop/recreate it) - a plain fresh `make test` would silently test
# a fresh install instead of the migrated objects.
run: bin/test_existing run-suite count_nulls_upgrade "${{ matrix.schema }}"

# A single stable check name for use as a required status check in branch
# protection rules. Matrix jobs produce check names like
# "🐘 PostgreSQL 14 (schema public)" which would all need to be listed
# individually and updated whenever the matrix changes. This job passes if
# all others passed or were skipped (e.g. the heavy jobs gated off by the
# `changes` job on a docs-only push), and fails if any failed or were
# cancelled.
all-checks-passed:
needs: [changes, test, extension-update-test, pg-upgrade-test]
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Verify all jobs are listed in needs
# Ensures this job won't silently ignore a newly-added job that was
# omitted from the needs list above.
run: |
DEFINED=$(python3 -c "
import yaml
with open('.github/workflows/ci.yml') as f:
w = yaml.safe_load(f)
print('\n'.join(sorted(j for j in w['jobs'] if j != 'all-checks-passed')))
")
NEEDED=$(echo '${{ toJson(needs) }}' | python3 -c "
import json, sys
print('\n'.join(sorted(json.load(sys.stdin))))
")
if [ "$DEFINED" != "$NEEDED" ]; then
echo "Some jobs are missing from all-checks-passed needs:"
diff <(echo "$DEFINED") <(echo "$NEEDED")
exit 1
fi
- name: Check all jobs passed or were skipped
run: |
if [[ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
echo "One or more jobs failed or were cancelled"
exit 1
fi
# vi: expandtab ts=2 sw=2
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,65 @@ include pgxntool/base.mk

# Temporary hack
testdeps: $(wildcard test/*/*.sql) $(wildcard test/*.sql) # Be careful not to include directories in this

# Install the oldest historical version's full install script so the update
# test in test/build/upgrade.sql and test/deps.sql's update mode can
# CREATE EXTENSION count_nulls VERSION '0.9.6'.
# Not covered by base.mk's DATA wildcard, which only picks up upgrade scripts
# (sql/*--*--*.sql) and the current version file.
DATA += sql/count_nulls--0.9.6.sql

# TEST_LOAD_SOURCE selects how test/deps.sql installs the extension for the
# WHOLE test suite:
# - fresh (default): CREATE EXTENSION count_nulls (current version).
# - update: CREATE EXTENSION at the oldest version we still ship a full
# install script for (0.9.6), then ALTER EXTENSION UPDATE to current.
# - existing: the extension is already installed (a real `pg_upgrade` run,
# or an out-of-band update) - deps.sql only asserts it's present and
# current, it does not drop/create/update anything. Meant to be run with
# CONTRIB_TESTDB=<db> EXTRA_REGRESS_OPTS=--use-existing
# PGXNTOOL_ENABLE_TEST_BUILD=no against a real database, not via a make
# wrapper here (see the pg_upgrade CI job).
# Running the SAME suite with the SAME expected output against the updated/
# upgraded database proves it behaves identically to a fresh install.
#
# "update" (this) is extension-level (ALTER EXTENSION UPDATE); "upgrade" is
# cluster-level (pg_upgrade) - 'existing' is how that axis is exercised.
# Don't conflate the two in variable names or comments.
#
# The mode is signalled to test/deps.sql via the count_nulls.test_load_mode
# placeholder GUC. pg_regress does not forward make variables, but the psql
# processes it spawns inherit the environment, so PGOPTIONS reaches deps.sql.
# It's exported unconditionally so deps.sql can read it without missing_ok
# and fail loudly if it didn't propagate, instead of silently defaulting to
# fresh and running the wrong suite.
TEST_LOAD_SOURCE ?= fresh
ifeq ($(filter $(TEST_LOAD_SOURCE),fresh update existing),)
$(error TEST_LOAD_SOURCE must be 'fresh', 'update' or 'existing', got '$(TEST_LOAD_SOURCE)')
endif
export PGOPTIONS := $(PGOPTIONS) -c count_nulls.test_load_mode=$(TEST_LOAD_SOURCE)

# TEST_SCHEMA selects which schema test/deps.sql installs count_nulls into,
# for the WHOLE test run (every test file uses the SAME schema in a given
# run - previously each test file hardcoded its own literal schema name as a
# stand-in for real schema-qualification coverage, which only ever tested
# two fixed, always-lowercase names). Combined with TEST_LOAD_SOURCE this
# drives a schema x mode CI matrix; in particular, a schema whose name
# requires SQL identifier quoting (mixed case - unquoted would silently fold
# to lowercase and test the wrong, matching schema instead) needs its own
# leg, not just 'public'. Locally: `make test TEST_SCHEMA=Quoted`.
#
# Propagated the same way as TEST_LOAD_SOURCE: via the count_nulls.test_schema
# GUC, exported unconditionally through PGOPTIONS.
TEST_SCHEMA ?= public
ifeq ($(strip $(TEST_SCHEMA)),)
$(error TEST_SCHEMA must not be empty)
endif
export PGOPTIONS := $(PGOPTIONS) -c count_nulls.test_schema=$(TEST_SCHEMA)

# Convenience wrapper: `make test-update` == `make test TEST_LOAD_SOURCE=update`.
# Must recurse (a fresh $(MAKE)) rather than depend on `test`, so the
# parse-time TEST_LOAD_SOURCE conditional above re-evaluates with update set.
.PHONY: test-update
test-update:
$(MAKE) test TEST_LOAD_SOURCE=update
Loading
Loading