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
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '/<artifactId>ipdata-java-client<\/artifactId>/{f=1} f&&/<version>/{sub(/.*<version>/,"");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
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -232,5 +233,10 @@ You can as well get multiple responses at once by using the ``bulk`` api:
List<IpdataModel> 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 `<version>` 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.
Loading