release #15
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
name: release | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Next release version' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Setups the environment | |
- name: Checkout | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3 | |
with: | |
java-version: '17' | |
distribution: 'oracle' | |
- name: Download next-semver | |
run: wget https://repo1.maven.org/maven2/io/github/algomaster99/semver/1.0.3/semver-1.0.3-jar-with-dependencies.jar | |
# Get current version from pom and remove snapshot if present. | |
- name: Get current version from pom and remove snapshot if present | |
run: echo "CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//')" >> $GITHUB_ENV | |
- name: Get version with snapshot | |
run: echo "CURRENT_VERSION_WITH_SNAPSHOT=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | |
# Calculate next version: | |
# - if version is patch, we just increment the patch version | |
# - if version is minor or major, we increment the minor or major version and set the patch version to 0 | |
# As we are using a snapshot version, we need to run semver next twice to get the next version for mahor and minor releases. Reason: Any X.Y.Z-SNAPSHOT version will be released as X.Y.Z if we run semver next major X.Y.Z-SNAPSHOT | |
- name: Set next version | |
if: ${{ github.event.inputs.version == 'patch' }} | |
run: echo "NEXT_VERSION=$(java -jar semver-1.0.3-jar-with-dependencies.jar --release-type=${{ github.event.inputs.version }} $CURRENT_VERSION_WITH_SNAPSHOT)" >> $GITHUB_ENV | |
- name: Set next version | |
# semver next for a snapshot only releases the snapshot version, so we need to run it 2 times | |
if: ${{ github.event.inputs.version == 'major' || github.event.inputs.version == 'minor' }} | |
run: echo "NEXT_VERSION=$(java -jar semver-1.0.3-jar-with-dependencies.jar --release-type=${{ github.event.inputs.version }} $CURRENT_VERSION)" >> $GITHUB_ENV | |
- name: Set release version | |
run: mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules -DgenerateBackupPoms=false | |
- name: Commit & Push changes | |
uses: actions-js/push@master | |
with: | |
github_token: ${{ secrets.JRELEASER_GITHUB_TOKEN }} | |
message: 'chore: releasing version ${{ env.NEXT_VERSION }}' | |
# Now we can run the release | |
- name: Stage release | |
run: mvn --no-transfer-progress --batch-mode -Prelease -DskipTests | |
- name: Print next version | |
run: mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//' | |
- name: Run JReleaser | |
uses: jreleaser/release-action@v2 | |
with: | |
setup-java: false | |
arguments: release | |
env: | |
JRELEASER_PROJECT_VERSION: ${{ env.NEXT_VERSION }} | |
JRELEASER_GITHUB_TOKEN: ${{ secrets.JRELEASER_GITHUB_TOKEN }} | |
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }} | |
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }} | |
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }} | |
JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME: ${{ secrets.JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME }} | |
JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD: ${{ secrets.JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD }} | |
# Now we can update the changelog | |
- name: Prepend changelog from out/jreleaser/CHANGELOG.md to CHANGELOG.md with version as header | |
run: | | |
echo "" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md | |
cat out/jreleaser/release/CHANGELOG.md | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md | |
echo "" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md | |
echo -n "# ${{ env.NEXT_VERSION }}" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md | |
echo "" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md | |
# Time to set the next version: The next version of any Release is a snapshot version of the next patch version | |
- name : Set next version (patch of release version) with -SNAPSHOT suffix | |
run: | | |
echo "NEXT_RELEASE_VERSION=$(java -jar semver-1.0.3-jar-with-dependencies.jar --release-type=patch $NEXT_VERSION)-SNAPSHOT" >> $GITHUB_ENV | |
echo "NEXT_RELEASE_VERSION_WITHOUT_SNAPSHOT=$(java -jar semver-1.0.3-jar-with-dependencies.jar --release-type=patch $NEXT_VERSION)" >> $GITHUB_ENV | |
- name: Set release version | |
run: mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules -DgenerateBackupPoms=false | |
# Time to update some files with the new version | |
# Commit and push changes | |
- name: Commit & Push changes | |
uses: actions-js/[email protected] | |
with: | |
github_token: ${{ secrets.JRELEASER_GITHUB_TOKEN }} | |
message: 'chore: setting SNAPSHOT version ${{ env.NEXT_RELEASE_VERSION }}' | |
# Log failure: | |
- name: JReleaser release output | |
if: always() | |
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 | |
with: | |
name: jreleaser-release | |
path: | | |
out/jreleaser/trace.log | |
out/jreleaser/output.properties |