Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ jobs:
- name: Dump database logs
if: failure()
run: docker compose logs --no-color

# Every pull request also upgrades from the latest release, so a
# change that breaks the upgrade is caught when it is made, not
# when the release workflow refuses to publish.
upgrade:
uses: ./.github/workflows/upgrade.yml
12 changes: 11 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,24 @@ jobs:
exit 1
fi

# Upgrade coverage (rds-distribution decision 8): the latest
# release upgraded to this build through both channels, with a
# consumer registration surviving and the full suite green on
# the upgraded database. No tag is cut without it.
upgrade:
if: >-
github.repository == 'emfga/cel4postgres' &&
github.ref == 'refs/heads/main'
uses: ./.github/workflows/upgrade.yml

# The tag does not exist beforehand; gh creates it at the
# released commit, and re-running on an already-released
# version fails here instead of republishing.
publish:
if: >-
github.repository == 'emfga/cel4postgres' &&
github.ref == 'refs/heads/main'
needs: [smoke, pgtle]
needs: [smoke, pgtle, upgrade]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Upgrade

# Upgrade coverage: no release without it. Installs the latest
# published release (N-1) the way a consumer did, registers a
# consumer overload, upgrades to this checkout's build, and runs the
# full suite against the upgraded database. Both shipped channels:
# plain psql scripts and pg_tle's ALTER EXTENSION ... UPDATE.
#
# Reusable only: CI runs it on every pull request, and the release
# workflow's publish job needs it.
on:
workflow_call:

permissions:
contents: read

jobs:
upgrade:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
channel: [plain, pgtle]
steps:
- uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true

# The latest release is N-1 by construction: the release
# workflow refuses to publish a version that already exists.
- name: Download the previous release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release download -R "$GITHUB_REPOSITORY" -D "$RUNNER_TEMP/prev" \
-p 'cel4postgres--*.sql' -p SHA256SUMS

- name: Build images and artifacts
run: |
./scripts/build-release.sh
base=$(sed -n 's/^ *image: \(postgres:[^ ]*\)$/\1/p' \
compose.yaml)
if [ "${{ matrix.channel }}" = pgtle ]; then
docker build -f docker/pg_tle.Dockerfile \
--build-arg BASE_IMAGE="$base" -t pgtle .
image=pgtle
else
image=$base
fi
echo "IMAGE=$image" >>"$GITHUB_ENV"

- name: Upgrade from the previous release
run: |
./scripts/upgrade-check.sh "${{ matrix.channel }}" "$IMAGE" \
"$RUNNER_TEMP/prev" 5432

# Same corpus pin as ci.yml; a test checks both against
# internal/corpus.Pin.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: cel-expr/cel-spec
ref: ba58ae5007845f3a1279b488cdeb79645ce958bb
path: .cel-expr/cel-spec

# An upgraded database has to be exactly as conformant as a
# fresh install.
- run: go test ./... -v
env:
CEL_EXPR_DIR: ${{ github.workspace }}/.cel-expr
DATABASE_URL: postgres://cel:pw@127.0.0.1:5432/cel?sslmode=disable

- name: Dump database logs
if: failure()
run: docker logs "cel-upgrade-${{ matrix.channel }}"
35 changes: 31 additions & 4 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,37 @@ reads the registry tables. The role still cannot register anything
`SELECT cel.version()` reports the installed version, recorded in
`cel.schema_version` at install time.

There is no in-place upgrade path yet: moving to a new version
means uninstalling and installing the new artifact. Note that this
also removes anything you registered in the registry tables
yourself — re-register after reinstalling.
To upgrade, run the new release's artifact over the installed one,
exactly as you installed it. The installer is idempotent: it
replaces every function and every registry row it ships, and leaves
alone anything you registered yourself.

```bash
psql -v ON_ERROR_STOP=1 --single-transaction "$DATABASE_URL" \
-f cel4postgres--<new>.sql
```

Through pg_tle, register the new bundle as an update path and
update the extension:

```bash
./scripts/pgtle-wrap.sh --update-from <old> cel4postgres <new> \
cel4postgres--<new>.sql > cel4postgres-update.pgtle.sql

psql -v ON_ERROR_STOP=1 "$DATABASE_URL" \
-f cel4postgres-update.pgtle.sql \
-c "ALTER EXTENSION cel4postgres UPDATE TO '<new>';"
```

Both paths are tested before every release: CI installs the
previous release, registers an overload of its own, upgrades to
the new build, and runs the full conformance suite against the
upgraded database. The upgrade tested is from the immediately
previous release; when skipping versions, upgrade through each.

A release that adds functions needs the access-control grants
re-run afterwards: `GRANT … ON ALL FUNCTIONS` covers only the
functions that existed when it ran.

[releases]: https://github.com/emfga/cel4postgres/releases
[pg_tle]: https://github.com/aws/pg_tle
Expand Down
41 changes: 24 additions & 17 deletions internal/corpus/corpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,35 @@ func TestPinMatchesWorkflow(t *testing.T) {
t.Fatal(err)
}

path := filepath.Join(root, ".github", "workflows", "ci.yml")
source, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read ci.yml: %v", err)
}

pattern := regexp.MustCompile(
`repository:\s*cel-expr/cel-spec\s*\n\s*ref:\s*([0-9a-f]{40})`,
)

match := pattern.FindSubmatch(source)
if match == nil {
t.Fatal("ci.yml does not check cel-expr/cel-spec out by commit")
}
// Every workflow that runs the suite checks the corpus out
// itself: CI on a fresh install, and the upgrade job on an
// upgraded one.
for _, name := range []string{"ci.yml", "upgrade.yml"} {
path := filepath.Join(root, ".github", "workflows", name)
source, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read %s: %v", name, err)
}

if ref := string(match[1]); ref != Pin {
t.Fatalf(
"ci.yml checks out cel-spec %s but corpus.Pin says %s\n"+
"The corpus defines what the conformance number means: "+
"move both together, with a re-measurement behind it.",
ref, Pin,
)
match := pattern.FindSubmatch(source)
if match == nil {
t.Fatalf("%s does not check cel-expr/cel-spec out by commit",
name)
}

if ref := string(match[1]); ref != Pin {
t.Fatalf(
"%s checks out cel-spec %s but corpus.Pin says %s\n"+
"The corpus defines what the conformance number "+
"means: move both together, with a re-measurement "+
"behind it.",
name, ref, Pin,
)
}
}
}

Expand Down
24 changes: 21 additions & 3 deletions scripts/pgtle-wrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@
# the output is generated where needed, never published.
#
# pgtle-wrap.sh <extname> <version> <artifact.sql>... > out.sql
# pgtle-wrap.sh --update-from <old> <extname> <version> \
# <artifact.sql>... > out.sql
#
# The first form registers <version> for CREATE EXTENSION; the
# second registers the <old> -> <version> update path for ALTER
# EXTENSION ... UPDATE. The update script is the same bundle: the
# installer is idempotent and resyncs what it ships.
#
# The artifacts run unchanged. Pass the plain ones, never a -tx
# twin: a pg_tle script executes inside CREATE EXTENSION's own
# transaction, where transaction control is not allowed.

set -eu

from=
if [ "$1" = --update-from ]; then
from=$2
shift 2
fi

name=$1
version=$2
shift 2
Expand All @@ -36,9 +49,14 @@ if grep -qF "\$$tag\$" "$tmp"; then
exit 1
fi

printf "SELECT pgtle.install_extension(\n"
printf " '%s',\n '%s',\n 'CEL for PostgreSQL',\n" \
"$name" "$version"
if [ -n "$from" ]; then
printf "SELECT pgtle.install_update_path(\n"
printf " '%s',\n '%s',\n '%s',\n" "$name" "$from" "$version"
else
printf "SELECT pgtle.install_extension(\n"
printf " '%s',\n '%s',\n 'CEL for PostgreSQL',\n" \
"$name" "$version"
fi
printf '$%s$\n' "$tag"
cat "$tmp"
printf '$%s$\n);\n' "$tag"
Loading
Loading