-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support tagging to automatically release version to Maven Central (#3)
- Loading branch information
1 parent
2079846
commit 2ec3ced
Showing
3 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Build and publish artifacts | ||
on: | ||
push: | ||
tags: | ||
# Run on all tags (but not branches); releases artifact to Maven Central | ||
# Note this is NOT REGEX - see https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet | ||
- v[0-9]+.[0-9]+.[0-9]+ | ||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-22.04 # LTS EoL Apr 2025 | ||
|
||
env: | ||
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_PUBLISH_USERNAME }} | ||
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PUBLISH_PASSWORD }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
java-version: '8.x' | ||
java-package: jdk | ||
architecture: x64 | ||
distribution: temurin | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: ~/.gradle | ||
key: ${{ runner.OS }}-gradle-${{ hashFiles('**/build.gradle') }} | ||
restore-keys: | | ||
${{ runner.OS }}-gradle- | ||
${{ runner.OS }} | ||
- name: Install Dependencies | ||
run: | | ||
./gradlew dependencies | ||
- name: Show Versions | ||
run: | | ||
echo "java: $(java -version)" | ||
- name: Extract branch name | ||
shell: bash | ||
run: echo "BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV | ||
|
||
- name: Close/release Nexus staging repository | ||
run: ./gradlew closeAndReleaseRepository -PisTag="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') | ||
if [ "$BRANCH" != "main" ]; then | ||
echo "Must be on main branch to tag" | ||
exit 1 | ||
fi | ||
|
||
# Extract the version from build.gradle, and use it as the tag: | ||
VERSION_RE="^.*baseVersion = '([0-9]+\.[0-9]+\.[0-9]+)'.*" | ||
VERSION_STRING="$(grep 'baseVersion =' build.gradle)" | ||
if [[ ${VERSION_STRING} =~ ${VERSION_RE} ]]; then | ||
VERSION=${BASH_REMATCH[1]} | ||
fi | ||
|
||
if [ -z "${VERSION}" ]; then | ||
echo "Invalid version found in [${VERSION_STRING}]" | ||
exit 1 | ||
fi | ||
|
||
TAG="v${VERSION}" | ||
HASH=$(git rev-parse HEAD) | ||
git tag -a -m "${HASH}" "${TAG}" | ||
git push origin "${TAG}" |