Skip to content

Release and Publish

Release and Publish #8

Workflow file for this run

# Kicks off the release process:
#
# * Sets release version
# * Builds
# * Tests
# * Creates artifacts for binaries and sources
# * Signs artifacts
# * Uploads artifacts to Maven Central
# * Tags git with release number "v$version"
# * Keeps development version in the pom.xml to 0.0.0-main-SNAPSHOT
# * Pushes changes to git
name: Release and Publish
on:
workflow_dispatch:
inputs:
version:
description: '(Required) The version to release. Must be a real version, not a SNAPSHOT (ie. ending in "-SNAPSHOT"). For example "1.0.0", "1.0.0-alpha-1".'
required: true
jobs:
release-publish-maven-central:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
# https://cashapp.github.io/hermit/usage/ci/
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# Used in writing commits in the release process
- name: Set Git Config
run: |
git config user.name "block-release-manager[bot]"
git config user.email "block-release-manager[bot]@users.noreply.github.com"
# This will set versions, git tag, sign, and publish to Maven Central.
- name: Release and Publish to Maven Central
run: |
# Get the required provided version
version=${{ github.event.inputs.version }}
# Precondition check; do not allow this to proceed if a version ending in "-SNAPSHOT" was specified
if [[ $version =~ -SNAPSHOT$ ]]; then
echo "Error: The version for release must not end with \"-SNAPSHOT\": $version"
exit 1
fi
# Get the existing version from the POM and set it to the nextVersion, keeping the POM effectively versionless
nextVersion=$(grep -oPm1 "(?<=<version>)[^<]+" pom.xml)
if [[ -z $nextVersion ]]; then
echo "Error: Could not find a version in the pom.xml"
exit 1
fi
echo "Version to be released: $version"
echo "Setting next development version back to original in pom.xml: $nextVersion"
mvn -e \
release:prepare \
release:perform \
--batch-mode \
--settings .maven_settings.xml \
-DreleaseVersion=$version \
-DdevelopmentVersion=$nextVersion \
-P ossrh,sign-artifacts
env:
SIGN_KEY_PASS: ${{ secrets.GPG_SECRET_PASSPHRASE }}
SIGN_KEY: ${{ secrets.GPG_SECRET_KEY }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_USERNAME }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ github.event.inputs.version }}
draft: false
prerelease: false
generate_release_notes: true