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
67 changes: 67 additions & 0 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: publish snapshot

# Publishes the selected branch's -SNAPSHOT build to the Central Portal snapshot repository
# (docs/plans/publishing.md, Phase 3). Run by hand from the Actions tab; nothing triggers it
# automatically. Snapshots are not signed, so no GPG key is involved. The Central user token
# comes from the MAVEN_CENTRAL_USERNAME and MAVEN_CENTRAL_PASSWORD repository secrets, which
# .mvn/settings.xml maps to the `central` server.

on:
workflow_dispatch:

# One publish at a time per branch, so two runs cannot interleave their uploads.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: read

jobs:
publish:
name: publish snapshot
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
cache: maven
- name: Refuse anything but a -SNAPSHOT version
id: coordinates
# A release goes through -Prelease and the Portal's Publish button, never this workflow.
run: |
group=$(./mvnw -B -ntp -q -N help:evaluate -Dexpression=project.groupId -DforceStdout)
version=$(./mvnw -B -ntp -q -N help:evaluate -Dexpression=project.version -DforceStdout)
echo "coordinates: $group:*:$version"
case "$version" in
*-SNAPSHOT) ;;
*) echo "::error::$version is not a -SNAPSHOT version"; exit 1 ;;
esac
echo "group=$group" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Require the Central token
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
# Unset, settings.xml would send the literal ${env...} text and fail late with a 401.
run: |
if [ -z "$MAVEN_CENTRAL_USERNAME" ] || [ -z "$MAVEN_CENTRAL_PASSWORD" ]; then
echo "::error::set the MAVEN_CENTRAL_USERNAME and MAVEN_CENTRAL_PASSWORD secrets"
exit 1
fi
- name: Build, test, and deploy
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
# deploy runs the unit tests and gates first, so a broken build is never published.
run: ./mvnw -B -ntp -s .mvn/settings.xml deploy
- name: Summarize the published coordinates
env:
GROUP: ${{ steps.coordinates.outputs.group }}
VERSION: ${{ steps.coordinates.outputs.version }}
run: scripts/snapshot-summary.sh "$GROUP" "$VERSION" >> "$GITHUB_STEP_SUMMARY"
16 changes: 16 additions & 0 deletions .mvn/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Central Portal credentials for deploy, read from the environment so nothing secret is
committed. Pass it to the deploy only: ./mvnw -s .mvn/settings.xml deploy. It is not in
maven.config because -s replaces ~/.m2/settings.xml (mirrors, proxies) for every build. -->
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<servers>
<server>
<!-- Matches publishingServerId in the root pom. -->
<id>central</id>
<username>${env.MAVEN_CENTRAL_USERNAME}</username>
<password>${env.MAVEN_CENTRAL_PASSWORD}</password>
</server>
</servers>
</settings>
1 change: 1 addition & 0 deletions docs/plans/overall.md
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ in CI; at least two "pgjdbc can't do this cleanly" capabilities documented.
- [ ] **N7.1** Reproducible builds, signing, Maven Central (C24.8); semver +
changelog. The reproducible `project.build.outputTimestamp` is set; GPG
signing, Central deployment wiring, and the semver/changelog policy remain.
The step-by-step is `docs/plans/publishing.md`.
Wire the revapi (or japicmp) binary-compatibility gate as part of this, not
after it: it diffs against the last released artifact, so the first release is
the moment it becomes possible, and it is what makes the Stable tier mean
Expand Down
262 changes: 262 additions & 0 deletions docs/plans/publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
# Plan: publishing to Maven Central (N7.1 / C24.8)

Status: **snapshots rehearsed; releases deferred.** The POM wiring (steps 6a
to 10) is done, and a first snapshot was published under `io.github.sehrope`
from a local deploy (step 11). The groupId swap (6c) has since been dropped,
so the build is `org.postgresql` again, and `publish-snapshot.yml` publishes
one by hand (step 19) once the repository holds a token with rights on
`org.postgresql` (step 22). No signing key exists yet, so Phases 4 and 5 wait.
The running status is in [`overall.md`](overall.md) under N7.1.

The approach: rehearse the whole pipeline in a fork under a personal
`io.github.<name>` namespace, snapshots first and then a real release, and
merge the wiring back once it works. The final coordinates are `org.postgresql`
(ADR-0022); the fork differs from upstream only in the groupId literal and the
credentials, so the merge is the groupId swap plus whatever landed in the POMs.

## What gets published

Five artifacts: `postgresql-client-parent` (POM only, but every module's POM
points at it so it must be on Central), `postgresql-client-protocol`,
`postgresql-client`, `postgresql-client-jdbc`, and
`postgresql-client-pgjdbc-compat`. `postgresql-client-bench`,
`postgresql-client-bench-jmh`, `postgresql-client-coverage`, and
`postgresql-client-native-smoke` set `maven.deploy.skip` and never ship.

Open question, to settle before the first non-snapshot release: whether the
compat module belongs in a public release at all. It is a migration aid, not a
certified drop-in, and it publishes classes under pgjdbc's own package names, so
adding it next to real pgjdbc produces a split package. Options are to ship it,
ship it with an explicit warning in its POM description, or skip it until it is
certified. Snapshots can carry it either way.

## How the Central Portal works (verified 2026-10-23)

- OSSRH is gone (retired 2025-06-30). Everything goes through the Central
Publisher Portal at central.sonatype.com, authenticated by a user token.
- A release deploy creates a *deployment* that is validated and then waits in
VALIDATED state until someone presses Publish in the Portal UI or calls the
publish endpoint. Drop discards it. This is `publishingType=USER_MANAGED`, the
default; `AUTOMATIC` skips the human step. Validated deployments are kept 90
days.
- The Portal login has no second factor of its own; a Central account is as
strong as the GitHub or Google account linked to it. There is no OIDC or
trusted-publishing flow: CI holds a user token as a secret.
- Snapshots: enabled per namespace in the Portal UI, pushed to
`https://central.sonatype.com/repository/maven-snapshots/`, no validation and
no signing, purged after 90 days.
- Releases: every file needs a detached PGP `.asc` and the public key must be on
`keyserver.ubuntu.com`, `keys.openpgp.org`, or `pgp.mit.edu`. The POM needs
`name`, `description`, `url`, `licenses`, `scm`, and `developers`, and each
jar needs sources and javadoc jars. Sigstore signatures are accepted only in
addition to PGP; GitHub artifact attestations are not consumed by Central or
by Maven at all.
- `central-publishing-maven-plugin` (`org.sonatype.central`, 0.9.0) replaces
the deploy plugin, bundles the whole reactor, and uploads it at the end of the
build. It routes `-SNAPSHOT` versions to the snapshot repository on its own.

## How pgjdbc publishes (for reference, checked 2026-10-23)

pgjdbc is Gradle, so the plugins differ, but the shape is the one to copy. The
publishing logic is in `build-logic/publishing/src/main/kotlin/` and
`build-logic/root-build/`, with knobs declared in `build-logic/build-parameters/`.

- **Central Portal via `com.gradleup.nmcp` 1.5.0.** The root project applies
`nmcp.aggregation` and configures `centralPortal` with username and password
read from the `CENTRAL_PORTAL_USERNAME` / `CENTRAL_PORTAL_PASSWORD`
environment variables, a `publishingType` build parameter (`AUTOMATIC` by
default, `MANUAL` available), and a 60-minute `validationTimeout`. Each
published subproject applies `build-logic.publish-to-central`, which pulls
`maven-publish`, `signing`, and `nmcp`.
- **Snapshot vs release is a build parameter.** `-Prelease` (default false)
switches the version suffix. Without it, the publish plugin registers a
`centralSnapshots` Maven repository at
`https://central.sonatype.com/repository/maven-snapshots` with
`PasswordCredentials`, fed from Gradle properties
`centralSnapshotsUsername` / `centralSnapshotsPassword`. With it, signing is
configured instead and the Portal upload is used. So snapshots never sign
and releases never go to the snapshot repository, by construction.
- **Signing.** Build parameters `signing.pgp.enabled` (`AUTO`, meaning on
for releases, or `OFF`) and `signing.pgp.implementation` (`IN_MEMORY`
default, or `GPG_CLI`). In-memory signing reads `SIGNING_PGP_PRIVATE_KEY`
and `SIGNING_PGP_PASSPHRASE` from the environment and fails the build with a
Gradle Problems report if either is missing. `GPG_CLI` is the local escape
hatch. The key itself is generated and maintained *inside* GitHub Actions by
the reusable workflow `vlsi/provision-release-pgp-key`
(`pgp-key-maintenance.yaml`, `workflow_dispatch` only): key name "pgjdbc
releases", email `pgjdbc-releases@jdbc.postgresql.org`, five-year lifetime,
uploaded to `keyserver.ubuntu.com`, `keys.openpgp.org`, and `pgp.mit.edu`.
Rerunning extends the expiry, so any committer can renew without holding the
key. It needs a fine-grained token with `secrets: write` and
`variables: write` (`RELEASE_PGP_SECRET_UPDATE_TOKEN`).
- **Artifacts and POM.** `withSourcesJar()` always, `withJavadocJar()` unless
`skipJavadoc`. The POM block sets name, description, inceptionYear, url,
licenses, organization, developers (seven named committers), issueManagement,
mailingLists, and scm with `tag` fixed to `HEAD`. Dependency versions in the
POM come from Gradle's resolution result rather than declared ranges.
- **A local staging copy.** `build-logic.publish-to-tmp-maven-repo` adds a
`tmp-maven` repository under `build/local-maven-repo`, cleaned before each
publish. The release workflow publishes to Central and to `tmp-maven` in the
same Gradle run, so the jar and `.asc` attached to the GitHub release are
byte-for-byte what went to Central. A `createReleaseBundle` task gathers
every publishable artifact into `build/release` and mentions SLSA
attestation in its description, but `release.yml` runs no attestation step
today.
- **`nightlysnapshot.yml`** runs on every push to `master`, first checks the
two secrets exist and skips cleanly if not, then runs
`publishAllPublicationsToCentralSnapshotsRepository` with the Portal token
(still stored as `NEXUS_USERNAME` / `NEXUS_PASSWORD`) mapped to the Gradle
properties through `ORG_GRADLE_PROJECT_*`.
- **`release.yml`** is `workflow_dispatch` only with an optional version input
(default from `gradle.properties`). It refuses to run off `master` or
`release/**`, refuses an existing `REL<version>` tag, and bumps the version
through a GitHub App token. The publish step runs
`publishAggregationToCentralPortal` with `release=true` and
`centralPortalPublishingType=AUTOMATIC`, so the manual dispatch is the human
gate rather than the Portal's Publish button. It publishes *before* tagging,
so a failed upload leaves no tag to clean up, then creates the GitHub release
with release-drafter, attaches the staged jar and signature, and bumps to the
next snapshot. Permissions are `contents: write` only: no `id-token`, no
environment protection.

Worth adopting from that: the generated-in-CI key with the extend-on-rerun
workflow (no developer ever holds the release key), the fail-loud check for
missing signing secrets, the secrets-present guard on the snapshot job, the
branch and tag guards, publishing before tagging, and attaching the same bytes
that went to Central to the GitHub release. The snapshot/release split is
simpler for us: the Central plugin routes `-SNAPSHOT` on its own, and the
`release` profile is what adds signing. Worth doing differently: keep
`autoPublish` off, at least until the pipeline has run clean a few times, so
the Portal's Publish button stays as a second look.

## Phase 1: account and namespace (once, in the Portal)

1. Log in at central.sonatype.com, open View Namespaces, Add Namespace, enter
`io.github.<name>`. `io.github.<user>` verifies automatically if the Central
account was created through GitHub login; `io.github.<org>` never does.
2. If it shows Unverified, create a public repository named exactly the
verification key under that account (works for an org too), wait for the
check, then delete the repository.
3. On the namespace's dropdown, choose Enable SNAPSHOTs.
4. Generate a user token at central.sonatype.com/usertoken. Both halves are shown
once; save them.
5. Export the token halves as `MAVEN_CENTRAL_USERNAME` and
`MAVEN_CENTRAL_PASSWORD`. The committed `.mvn/settings.xml` maps them to
the `central` server, and every deploy passes it with
`-s .mvn/settings.xml`. It is not in `.mvn/maven.config`: `-s` replaces
`~/.m2/settings.xml` (mirrors, proxies) rather than merging with it, so it
would change every build. Other builds never read the credentials; with
the variables unset, only a deploy fails (401).

## Phase 2: fork POM changes

6a. Done: every inter-module dependency's `<groupId>` is `${project.groupId}`
(15 blocks across the root `dependencyManagement` and the module POMs), so
publishing under other coordinates means editing the root `<groupId>` and
the `<parent>` blocks and nothing else. Parent references cannot be
properties, which is why those stay literal.
6b. Done: `maven.deploy.skip` on `postgresql-client-coverage`, matching the
other three build-only modules; without it a deploy pushed the coverage
POM.
6c. Done for the rehearsal, then dropped (step 21): swap the groupId, the one
spot:

```sh
git grep -l '<groupId>org.postgresql</groupId>' -- pom.xml '*/pom.xml' \
| xargs sed -i 's|<groupId>org.postgresql</groupId>|<groupId>io.github.NAME</groupId>|'
```

After 6a this hits the root `<groupId>` and the nine `<parent>` blocks and
nothing else; no dependency in the reactor shares that literal. Keep this
as its own commit so it can be reverted cleanly at merge time.
7. Done: `<url>`, `<scm>` (`connection`, `developerConnection`, `url`, `tag`),
and `<developers>` in the root POM, pointing at `github.com/pgjdbc/pg-java`
so they carry over at merge time. The `child.*.inherit.append.path`
attributes stop the modules appending their artifactId to the URLs.
8. Done: `central-publishing-maven-plugin` 0.9.0 in the root `<build><plugins>`
with `<extensions>true</extensions>`, `publishingServerId` `central`,
`autoPublish` false, and the four build-only modules in `excludeArtifacts`.
9. Done: a `release` profile in the root POM with `maven-source-plugin`
(`jar-no-fork`), `maven-javadoc-plugin` (`jar`), and `maven-gpg-plugin`
3.2.7 (`sign`, `bestPractices` true, passphrase from
`MAVEN_GPG_PASSPHRASE`). The build-only modules skip all three.
10. Done: `./mvnw -ntp -DskipTests -Prelease -Dgpg.skip package` passes with
doclint at `all,-missing`. Missing comments were the bulk of the findings;
the rest (an unescaped `<<`, a link into `java.sql` from core, two broken
`{@link}`s) were fixed in their own commits.

## Phase 3: first snapshot

11. `./mvnw -ntp -s .mvn/settings.xml deploy` with the version still
`0.1.0-SNAPSHOT`. No signing, no validation.
12. Check the Portal lists exactly the five artifacts above. If a build-only
module appears, the plugin ignored `maven.deploy.skip`, and each of the four
POMs needs `<skipPublishing>true</skipPublishing>` instead.
13. Resolve it from a scratch project:

```xml
<repository>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
```

## Phase 4: signing key (once)

Two ways; pick one.

14a. Local key: `gpg --gen-key` with a project identity, then
`gpg --keyserver keys.openpgp.org --send-keys KEYID` (keys.openpgp.org
serves the identity only after the confirmation email is answered). Export
with `gpg --export-secret-keys -a KEYID` and store it, the passphrase, and
the Central token as GitHub Actions secrets.
14b. CI-held key, pgjdbc style: add a `pgp-key-maintenance.yaml` that calls
`vlsi/provision-release-pgp-key` (digest-pinned) with the project's key
name and email, give it a fine-grained token with `secrets: write` and
`variables: write`, and dispatch it once. The private key lands in
`RELEASE_PGP_PRIVATE_KEY` and never leaves Actions; rerun to extend.
Preferable for upstream, since no individual holds the `org.postgresql`
release key. Local releases are then impossible by design, which is the
point.

## Phase 5: first release

15. Set the version with `./mvnw versions:set -DnewVersion=0.1.0`, commit, tag
`v0.1.0`. (Or publish before tagging, as pgjdbc does; either way the tag
must not exist before the upload succeeds.)
16. `./mvnw -ntp -s .mvn/settings.xml -Prelease deploy` with
`MAVEN_GPG_PASSPHRASE` set (and the key imported, for 14a). `waitUntil`
defaults to `validated`, so the build returns once the Portal accepts the
bundle.
17. In the Portal, inspect the VALIDATED deployment and press Publish. Central
releases are immutable: a bad `0.1.0` can only be followed by `0.1.1`.
18. Bump to `0.2.0-SNAPSHOT`, commit, and confirm the step 11 deploy (no
`-Prelease`) still lands snapshots.

## Phase 6: CI (optional for the fork, required upstream)

19. Done: `publish-snapshot.yml`, run by hand (`workflow_dispatch`) on the
selected branch. It refuses a non-SNAPSHOT version and missing secrets,
then runs `./mvnw -B -ntp -s .mvn/settings.xml deploy`, which tests before
it uploads. The token comes from the `MAVEN_CENTRAL_USERNAME` and
`MAVEN_CENTRAL_PASSWORD` repository secrets. A push trigger after the `ci`
workflow passes can come later; manual is enough while releases are
deferred.
20. `release.yml`: `workflow_dispatch` with a version input, guard the branch
and the tag as pgjdbc does, run step 16 with the key from secrets, then
tag and create the GitHub release only after the upload succeeded. Leave
`autoPublish` off so the Portal's Publish button remains the gate; flip it
once the workflow has run clean several times, if the manual dispatch is
judged gate enough. `actions/attest` can be added for provenance at no
cost, but nothing in the Maven ecosystem consumes it.

## Phase 7: merge back

21. Done: the step 6c commit was dropped rather than reverted, so the branch
carries steps 7 through 10 and 19 plus the doclint fixes, under
`org.postgresql`.
22. Upstream needs its own `central` token with rights on `org.postgresql` and
its own signing key (14b). Everything else carries over unchanged.
23. Tick N7.1 in `overall.md`. Wire the revapi/japicmp gate next, as N7.1 says:
the first published artifact is what makes it possible.
Loading
Loading