From 51c7cee7d88d86680f983dfb45998febb50be5a9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 18:26:20 +0000 Subject: [PATCH] Release automatically when the version in pom.xml changes Add a release job to the CI workflow that runs after the tests on every push to the default branch: it reads the project version from pom.xml and, when tag v does not exist yet, creates the tag and the GitHub release with gh, then publishes to Maven Central by calling the Release workflow in the same run, because a tag created with the workflow token does not trigger other workflows. A merge whose version is already tagged publishes nothing. Make the Release workflow callable with a tag input, keeping its tag push trigger, and document the procedure in the README. Co-Authored-By: Claude Fable 5.1 --- .github/workflows/ci.yml | 58 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 8 +++++ README.md | 6 ++++ 3 files changed, 72 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29c65d9..89ccccf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,3 +28,61 @@ jobs: - name: Build and Test run: mvn clean test post-integration-test + + # Tags and releases the version declared in pom.xml once it reaches the + # default branch. A version that is already tagged is left alone. + release: + needs: test + if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) + runs-on: ubuntu-latest + permissions: + contents: write + concurrency: + group: release + cancel-in-progress: false + outputs: + tag: ${{ steps.version.outputs.tag }} + created: ${{ steps.release.outputs.created }} + steps: + - uses: actions/checkout@v4 + + - name: Read the version from pom.xml + id: version + run: | + VERSION=$(awk '/ipdata-java-client<\/artifactId>/{f=1} f&&//{sub(/.*/,"");sub(/<\/version>.*/,"");print;exit}' pom.xml) + if [ -z "$VERSION" ]; then + echo "::error file=pom.xml::Could not read the project version" + exit 1 + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" + + - name: Create the tag and the GitHub release + id: release + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ steps.version.outputs.tag }} + run: | + status=0 + git ls-remote --exit-code --tags origin "refs/tags/$TAG" > /dev/null || status=$? + if [ "$status" -eq 0 ]; then + echo "Tag $TAG already exists; nothing to release." + echo "created=false" >> "$GITHUB_OUTPUT" + exit 0 + elif [ "$status" -ne 2 ]; then + echo "::error::git ls-remote failed with status $status" + exit "$status" + fi + gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notes + echo "Created tag and release $TAG." + echo "created=true" >> "$GITHUB_OUTPUT" + + # A tag created with the workflow token does not trigger the Release + # workflow on its own, so the Maven Central deploy runs in this run. + publish: + needs: release + if: needs.release.outputs.created == 'true' + uses: ./.github/workflows/release.yml + with: + tag: ${{ needs.release.outputs.tag }} + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d0f98e9..12ccdcc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,12 +3,20 @@ name: Release on: push: tags: [ 'v*' ] + workflow_call: + inputs: + tag: + description: The tag to publish to Maven Central, for example v0.3.0 + required: true + type: string jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: refs/tags/${{ inputs.tag || github.ref_name }} - name: Set up JDK 11 uses: actions/setup-java@v4 diff --git a/README.md b/README.md index 7c1176b..ecdbbb4 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ An 100% compliant [ipdata.co](https://ipdata.co) API java client. - [Single Field Selection](#single-field-selection) - [Multiple Field Selection](#multiple-field-selection) - [Bulk data](#bulk-data) +- [Releasing](#releasing) ## Install @@ -232,5 +233,10 @@ You can as well get multiple responses at once by using the ``bulk`` api: List models = ipdataService.bulk(Arrays.asList("1.1.1.1", "8.8.8.8")); ``` +## Releasing +Releases are cut by CI from the version declared in `pom.xml`; there is no need to push a tag by hand: +1. Bump the `` of the project in `pom.xml` (and the install snippet above) in a pull request and merge it. +2. CI tags the merge commit `vx.y.z`, creates the GitHub release with generated notes and publishes the artifacts to Maven Central. +A merge whose version is already tagged publishes nothing. Pushing a `v*` tag by hand still publishes that tag's commit, as before.