Skip to content

feat(gha): Configure publishing to Maven Central#63

Closed
krzema12 wants to merge 1 commit intoopen-constructs:mainfrom
krzema12:configure-publishing-to-Maven-Central
Closed

feat(gha): Configure publishing to Maven Central#63
krzema12 wants to merge 1 commit intoopen-constructs:mainfrom
krzema12:configure-publishing-to-Maven-Central

Conversation

@krzema12
Copy link
Copy Markdown
Contributor

@krzema12 krzema12 commented Mar 20, 2026

Related issue

Part of #13.

Description

This PR adds a new job for releasing Maven artifacts to Maven Central.

Why the current job that publishes to GitHub Packages isn't modified instead:

  • because some folks may still depend on the packages landing in GitHub Packages, and removing it should be done in a separate change. It's technically a breaking change
  • because merging this change right now likely won't make Maven Central publishing work - we need to set required secrets, and it may take some time. Merging this PR is vital to iteratively checking what's missing/misconfigured

These new parts are a blend of a copied job for GitHub Packages, and the Release step from before the renaming PR (https://raw.githubusercontent.com/open-constructs/cdk-terrain/a61d9aeef7d821756f8a2fa92f83127b45d01aa6/.github/workflows/release.yml and https://raw.githubusercontent.com/open-constructs/cdk-terrain/a61d9aeef7d821756f8a2fa92f83127b45d01aa6/.github/workflows/release_next.yml).

BTW, I'm struggling to understand why there are 2 workflows: release and release_next. I updated both.

Checklist

  • I have updated the PR title to match CDKTN's style guide
  • I have run the linter on my code locally
    • waiting for CI run
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if applicable
    • to be mentioned in the release notes
  • My changes generate no new warnings
    • waiting for CI run
  • I have added tests that prove my fix is effective or that my feature works if applicable
  • New and existing unit tests pass locally with my changes

@krzema12 krzema12 changed the title Configure publishing to Maven Central feat(gha): Configure publishing to Maven Central Mar 20, 2026
@krzema12 krzema12 marked this pull request as ready for review March 20, 2026 21:39
@krzema12 krzema12 requested a review from a team as a code owner March 20, 2026 21:39
@krzema12 krzema12 mentioned this pull request Mar 20, 2026
9 tasks
Copy link
Copy Markdown
Collaborator

@jsteinich jsteinich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The release workflow handles the actual release builds while release_next covers the pre-release. There's likely some restructuring we could do to remove some duplication; however, there are some differences in the two jobs.

Publishing to both is fine, though I'm not sure how necessary it is at this stage. I would generally expect users to allow maven central by default which would still pick up the new version.

Comment on lines +265 to +267
permissions:
contents: read
packages: write
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra permissions aren't needed for a release to maven central

Copy link
Copy Markdown
Contributor

@so0k so0k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will set secrets on the repo and push a commit with fixes for the review comments

env:
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_ENDPOINT: https://hashicorp.oss.sonatype.org
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MAVEN_ENDPOINT: https://hashicorp.oss.sonatype.org
MAVEN_ENDPOINT: https://central.sonatype.com

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but actually

Suggested change
MAVEN_ENDPOINT: https://hashicorp.oss.sonatype.org
MAVEN_ID: central-ossrh

as per cdklabs/publib#1667

MAVEN_ENDPOINT: https://hashicorp.oss.sonatype.org
MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
MAVEN_GPG_PRIVATE_KEY_PASSPHRASE: ${{ secrets.MAVEN_GPG_PRIVATE_KEY_PASSPHRASE }}
MAVEN_STAGING_PROFILE_ID: ${{ secrets.MAVEN_STAGING_PROFILE_ID }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MAVEN_STAGING_PROFILE_ID: ${{ secrets.MAVEN_STAGING_PROFILE_ID }}

MAVEN_STAGING_PROFILE_ID not needed for central-ossrh

@so0k
Copy link
Copy Markdown
Contributor

so0k commented Mar 22, 2026

Thanks for getting this started @krzema12! I've pushed a fix commit on top of yours and opened #64 which addresses the review feedback and consolidates the approach:

  • Replaces the GitHub Packages job instead of adding a second one (consistent with how NuGet.org was restored in chore: restore NuGet.org publishing #50)
  • Uses MAVEN_SERVER_ID=central-ossrh (publib #1667) instead of MAVEN_ENDPOINT — this is the recommended way to target the new Central Portal
  • Removes permissions: packages: write (per @jsteinich's review)
  • Removes MAVEN_STAGING_PROFILE_ID (not needed for central-ossrh)
  • Fixes the inconsistent MAVEN_ENDPOINT between the two workflow files (central.sonatype.com vs hashicorp.oss.sonatype.org)

All 4 required secrets (MAVEN_USERNAME, MAVEN_PASSWORD, MAVEN_GPG_PRIVATE_KEY, MAVEN_GPG_PRIVATE_KEY_PASSPHRASE) have been deployed. When #64 merges, this PR will also show as merged since it shares the same base commit.

so0k added a commit that referenced this pull request Mar 22, 2026
## Summary

Builds on #63 by @krzema12 — replaces the GitHub Packages Maven job with
Maven Central publishing instead of adding a second job alongside it
(consistent with the NuGet.org restoration in #50).

- **Replace** (not add alongside) the GitHub Packages Maven job
- Use `MAVEN_SERVER_ID=central-ossrh` ([publib
#1667](cdklabs/publib#1667)) instead of
`MAVEN_ENDPOINT`
- Remove unnecessary `permissions: packages: write`
- Remove `MAVEN_STAGING_PROFILE_ID` (not needed for `central-ossrh`)
- Fix inconsistent `MAVEN_ENDPOINT` between release.yml
(`central.sonatype.com`) and release_next.yml
(`hashicorp.oss.sonatype.org`)

### Required secrets

All 4 secrets have been deployed via IaC:

| Secret | Status |
|--------|--------|
| `MAVEN_USERNAME` | Deployed |
| `MAVEN_PASSWORD` | Deployed |
| `MAVEN_GPG_PRIVATE_KEY` | Deployed |
| `MAVEN_GPG_PRIVATE_KEY_PASSPHRASE` | Deployed |

Closes #13

## Test plan

- [x] Generate GPG key (RSA 4096), publish to `keyserver.ubuntu.com`
- [x] Deploy all 4 secrets via terraform apply
- [ ] Merge and verify first release publishes to
`https://central.sonatype.com/artifact/io.cdktn/cdktn`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Piotr Krzeminski <git@krzeminski.it>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@so0k so0k closed this Mar 22, 2026
@so0k
Copy link
Copy Markdown
Contributor

so0k commented Mar 22, 2026

don't know why the merged commits didn't auto tag this PR as merged :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants