Skip to content

Commit

Permalink
Update sqitch and pgTAP
Browse files Browse the repository at this point in the history
This will become release 2.3.0. The primary updates are:

- Upgraded sqitch version to 1.4.0
- Upgraded pgTAP to 1.2.1 at
  theory/pgtap@96a7a41.
- Added PostgreSQL 16 beta 2 for testing.
- Marked PostgreSQL 10 support as best effort since it is already at end
  of life.

Additional updates:

- Changed dependabot upgrades to monthly, not weekly.
- Add caching to the image test workflow.
- Added versioning update targets to the Justfile.
- Added the image version to the Justfile (as `.VERSION`).
- Updated the Maintenance documentation:
  - We do not cache the exported `pgtap.tar`, but the exported *files*
    (to allow for diff comparisons).
  - Added the versioning update targets documentation.
  - Improved Dockerfile versioning documentation for non-production release
    versions (such as 16 beta 2).
- Improved `scripts/do_pgtap` to formalize EOL support output.
- Improved `scripts/do_version` to fix a bug in `pgtap_version` reporting when
  `.pgtap.hashref` is missing.
  • Loading branch information
halostatue committed Aug 2, 2023
1 parent 3bcb110 commit c8917d9
Show file tree
Hide file tree
Showing 19 changed files with 12,629 additions and 37 deletions.
13 changes: 9 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
interval: monthly
groups:
actions:
patterns:
- '*'

- package-ecosystem: docker
directory: /
schedule:
interval: weekly
interval: monthly

- package-ecosystem: docker
directory: /build/pgtap
schedule:
interval: weekly
interval: monthly
2 changes: 2 additions & 0 deletions .github/workflows/build-test-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
PG_PROVE_VERSION=${{ fromJSON(steps.package-versions.outputs.data).pg_prove.version }}
PGTAP_VERSION=${{ fromJSON(steps.package-versions.outputs.data).pgtap.version }}
SQITCH_VERSION=${{ fromJSON(steps.package-versions.outputs.data).sqitch.version }}
cache-from: type=gha
cache-to: type=gha,mode=max

- run: ./run version
env:
Expand Down
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# kineticcafe/sqitch-pgtap Changelog

## 2.3.0 / 2023-08-03

- Upgraded sqitch version to 1.4.0

- Upgraded pgTAP to 1.2.1 at theory/pgtap@96a7a416311ea5f2fa140f59cfdf7c7afbded17c.

- Added PostgreSQL 16 beta 2 for testing.

- Marked PostgreSQL 10 support as best effort since it is already at end of
life.

## 2.2.0 / 2023-05-15

- Added explicit support for the internal macOS hostname under
Expand Down
69 changes: 68 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,65 @@ pg_prove_version := `jq -r .pg_prove.version < package-versions.json`
pgtap_version := `jq -r .pgtap.version < package-versions.json`
pgtap_hashref := `jq -r .pgtap.hashref < package-versions.json`
sqitch_version := `jq -r .sqitch.version < package-versions.json`
image_version := `jq -r .VERSION < package-versions.json`

# Show the version as it would be from the built image
version:
#!/usr/bin/env bash
set -euo pipefail

declare pgtap_version pgtap_hashref
pgtap_version="{{ pgtap_version }}"
pgtap_hashref="{{ pgtap_hashref }}"

if [[ -n "${pgtap_hashref}" ]] && [[ "${pgtap_hashref}" != null ]]; then
pgtap_version="${pgtap_version} (${pgtap_hashref})"
fi

cat <<EOS
[gchr.io/]kineticcafe/sqitch-pgtap:{{ image_version }}

sqitch (App::Sqitch) v{{ sqitch_version }}
pgtap ${pgtap_version}
pg_prove {{ pg_prove_version }}
EOS

# Set the new sqitch version
sqitch-set-version NEW_VERSION:
@just _update_package_versions sqitch.version {{ NEW_VERSION }}

# Set the new pgtap version
pgtap-set-version NEW_VERSION NEW_HASHREF="":
#!/usr/bin/env bash
just _update_package_versions pgtap.version {{ NEW_VERSION }}

declare new_hashref
new_hashref="{{ NEW_HASHREF }}"

if [[ -n "${new_hashref}"]]; then
just _update_package_versions pgtap.hashref "${new_hashref}"
fi

# Set the new pgtap git hashref
pgtap-set-hashref NEW_VERSION:
@just _update_package_versions pgtap.hashref {{ NEW_VERSION }}

# Clear the pgtap git hashref
pgtap-remove-hashref:
@jq -c 'if (.pgtap | has("hashref")) then del(.pgtap.hashref) else . end' \
package-versions.json | sponge package-versions.json

# Set the new pg_prove version
pg_prove-set-version NEW_VERSION:
@just _update_package_versions pg_prove.version {{ NEW_VERSION }}

# Set the image version
set-version NEW_VERSION:
@just _update_package_versions VERSION {{ NEW_VERSION }}

# Build the image
build:
#!/usr/bin/env bash
Expand All @@ -26,7 +84,8 @@ get-pgtap:
if [[ -n "{{ pgtap_hashref }}" ]]; then
git clone https://github.com/theory/pgtap.git \
"{{ justfile_directory() }}/build/pgtap/pgtap-{{ pgtap_version }}"
git -C "{{ justfile_directory() }}/build/pgtap/pgtap-{{ pgtap_version }}" switch --detach "{{ pgtap_hashref }}"
git -C "{{ justfile_directory() }}/build/pgtap/pgtap-{{ pgtap_version }}" \
switch --detach "{{ pgtap_hashref }}"
else
curl -sq -LO \
"https://api.pgxn.org/dist/pgtap/{{ pgtap_version }}/pgtap-{{ pgtap_version }}.zip"
Expand All @@ -44,3 +103,11 @@ get-pgtap:
rm -rf {{ justfile_directory() }}/build/pgtap/pgtap-"{{ pgtap_version }}" \
{{ justfile_directory() }}/build/pgtap/pgtap-"{{ pgtap_version }}".zip \
{{ justfile_directory() }}/pgtap.tar

git add opt/pgtap

_update_package_versions key value:
@jq -c '.{{ key }} = "{{ value }}"' {{ justfile_directory() }}/package-versions.json | \
sponge {{ justfile_directory() }}/package-versions.json

_read_package_versions key:
41 changes: 38 additions & 3 deletions Maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Maintenance of kineticcafe/sqitch-pgtap is fairly easy but has some points worth
documenting.

On every release, remember to update the `pgtap.tar` cache with `just
On every release, remember to update the `opt/pgtap` cache files with `just
get-pgtap`.

## Updating Package Versions
Expand All @@ -12,6 +12,17 @@ Primary package versions are updated through `package-versions.json`. `pg_prove`
and `sqitch` can currently only be updated with releases; `pgtap` can be updated
with download versions or git references.

It is recommended that you use `just PACKAGE-set-version` to set new versions,
as this will maintain the required condensed format:

```sh
just sqitch-set-version 1.4.0
just pgtap-set-version 1.2.1
just pgtap-set-version 1.2.1 96a7a416311ea5f2fa140f59cfdf7c7afbded17c
just pgtap-set-hashref 96a7a416311ea5f2fa140f59cfdf7c7afbded17c
just pg_prove-set-version 3.36
```

Note that this file _must_ be condensed as it is passed as a JSON object in
GitHub Actions:

Expand All @@ -24,13 +35,23 @@ jq -c < package-versions.json | sponge package-versions.json
To update `pg_prove`, update `pg_prove.version` in `package-versions.json`. That
version of `pg_prove` will be installed during the build of the Docker image.

```sh
just pg_prove-set-version 3.36
```

### Update `pgtap`

To update `pgtap`, update `pgtap.version` and/or `pgtap.hashref` in
`package-versions.json`. If `pgtap.hashref` is set, pgTAP will be updated from
git (from `https://github.com/theory/pgtap`). If omitted or empty, it will be
git (from <https://github.com/theory/pgtap>). If omitted or empty, it will be
downloaded from [PGXN][].

```sh
just pgtap-set-version 1.2.1
just pgtap-set-version 1.2.1 96a7a416311ea5f2fa140f59cfdf7c7afbded17c
just pgtap-set-hashref 96a7a416311ea5f2fa140f59cfdf7c7afbded17c
```

The scripts and functions used by pgTAP vary by PostgreSQL version, so the
updated versions must be cached as `pgtap.tar`, which is committed to this repo.
This cache file can be updated with `just get-pgtap` (this requires
Expand All @@ -41,6 +62,10 @@ This cache file can be updated with `just get-pgtap` (this requires
To update `sqitch`, update `sqitch.version` in `package-versions.json`. That
version of `sqitch` will be installed during the build of the Docker image.

```sh
just sqitch-set-version 1.4.0
```

## Adding or Removing PostgreSQL Versions

PostgreSQL versions require updating in multiple places:
Expand All @@ -54,7 +79,7 @@ PostgreSQL versions require updating in multiple places:
_major_ PostgreSQL versions.

```dockerfile
FROM postgres:<VERSION>-alpine3.<VERSION> AS build-pgtap-psql-<VERSION>
FROM postgres:<VERSION>-alpine3.<ALPINE_VERSION> AS build-pgtap-psql-<VERSION>

ARG PGTAP_VERSION

Expand All @@ -69,6 +94,16 @@ PostgreSQL versions require updating in multiple places:
&& rm -rf /var/cache/apk/* /tmp/*
```

If adding support for a non-production version (such as `16beta2`), then the
`FROM` line should look like this:

```dockerfile
FROM postgres:16beta2-alpine3.18 AS build-pgtap-psql-16
```

That is, the image name and pgtap folder name must be the major version
number with no qualifiers.

- Add a `COPY` line to the `package-pgtap` section:

```dockerfile
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ variables or on the command-line.

This version of the container includes:

- pgTAP 1.2.1 (via git at `56c591fc3bf6b2dba49e15739625916d49e3fc27`)
- pgTAP 1.2.1 (via git at `96a7a416311ea5f2fa140f59cfdf7c7afbded17c`)
- Support for PostgreSQL 9.6, 10, 11, 12, 13, 14, and 15
- pg_prove 3.36
- Sqitch 1.3.1
- Sqitch 1.4.0

The version of pgTAP is installed and uninstalled as needed; unit test files
_must not_ `CREATE EXTENSION pgtap`.

These images can be pulled either from Docker Hub
(`kineticcafe/sqitch-pgtap:2.1`) or the GitHub Container Registry
(`ghcr.io/kineticcafe/sqitch-pgtap:2.1`).
(`kineticcafe/sqitch-pgtap:2.3`) or the GitHub Container Registry
(`ghcr.io/kineticcafe/sqitch-pgtap:2.3`).

## `run` script Commands

The `run` script is recommended for running everything as it manages environment
variable configuration for each run. The `run` script will pull from
`ghcr.io/kineticcafe/sqitch-pgtap:2.1` by default; this can be overridden by
`ghcr.io/kineticcafe/sqitch-pgtap:2.3` by default; this can be overridden by
using `$IMAGE`:

```console
$ IMAGE=kineticcafe/sqitch-pgtap:latest ./run version
[gchr.io/]kineticcafe/sqitch-pgtap:2.1.0
[gchr.io/]kineticcafe/sqitch-pgtap:2.3.0

sqitch (App::Sqitch) v1.3.1
pgtap 1.2.1 (56c591fc3bf6b2dba49e15739625916d49e3fc27)
sqitch (App::Sqitch) v1.4.0
pgtap 1.2.1 (96a7a416311ea5f2fa140f59cfdf7c7afbded17c)
pg_prove 3.36
```

Expand Down
15 changes: 15 additions & 0 deletions build/pgtap/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
FROM postgres:16beta2-alpine3.18 AS build-pgtap-psql-16

ARG PGTAP_VERSION

COPY pgtap-$PGTAP_VERSION /opt/pgtap-$PGTAP_VERSION

RUN apk add --no-cache --update perl wget postgresql-dev openssl \
build-base make perl-dev bash \
&& mkdir -p /opt/pgtap/16 \
&& cd /opt/pgtap-$PGTAP_VERSION \
&& make && make install \
&& mv sql/pgtap.sql sql/uninstall_pgtap.sql /opt/pgtap/16 \
&& rm -rf /var/cache/apk/* /tmp/*

FROM postgres:15-alpine3.18 AS build-pgtap-psql-15

ARG PGTAP_VERSION
Expand Down Expand Up @@ -102,6 +116,7 @@ ARG PGTAP_VERSION

RUN mkdir -p /opt/pgtap

COPY --from=build-pgtap-psql-16 /opt/pgtap/16 /opt/pgtap/16
COPY --from=build-pgtap-psql-15 /opt/pgtap/15 /opt/pgtap/15
COPY --from=build-pgtap-psql-14 /opt/pgtap/14 /opt/pgtap/14
COPY --from=build-pgtap-psql-13 /opt/pgtap/13 /opt/pgtap/13
Expand Down
4 changes: 2 additions & 2 deletions opt/pgtap/10/pgtap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,7 @@ RETURNS TEXT AS $$
ARRAY(
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
EXCEPT
SELECT $1[i]
Expand All @@ -4652,7 +4652,7 @@ RETURNS TEXT AS $$
EXCEPT
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
),
$2
Expand Down
4 changes: 2 additions & 2 deletions opt/pgtap/11/pgtap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,7 @@ RETURNS TEXT AS $$
ARRAY(
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
EXCEPT
SELECT $1[i]
Expand All @@ -4652,7 +4652,7 @@ RETURNS TEXT AS $$
EXCEPT
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
),
$2
Expand Down
4 changes: 2 additions & 2 deletions opt/pgtap/12/pgtap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,7 @@ RETURNS TEXT AS $$
ARRAY(
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
EXCEPT
SELECT $1[i]
Expand All @@ -4652,7 +4652,7 @@ RETURNS TEXT AS $$
EXCEPT
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
),
$2
Expand Down
4 changes: 2 additions & 2 deletions opt/pgtap/13/pgtap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,7 @@ RETURNS TEXT AS $$
ARRAY(
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
EXCEPT
SELECT $1[i]
Expand All @@ -4652,7 +4652,7 @@ RETURNS TEXT AS $$
EXCEPT
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
),
$2
Expand Down
4 changes: 2 additions & 2 deletions opt/pgtap/14/pgtap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,7 @@ RETURNS TEXT AS $$
ARRAY(
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
EXCEPT
SELECT $1[i]
Expand All @@ -4652,7 +4652,7 @@ RETURNS TEXT AS $$
EXCEPT
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT LIKE 'pg_%'
WHERE nspname NOT LIKE 'pg\_%'
AND nspname <> 'information_schema'
),
$2
Expand Down
Loading

0 comments on commit c8917d9

Please sign in to comment.