Skip to content

Release

Release #31

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version to set. If not provided, the current version''s patch version will be incremented.'
required: false
type: string
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: "Set up JDK"
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
# disable reading from cache on re-runs to fix possible caching issues
cache-write-only: ${{ fromJSON(github.run_attempt) != 1 }}
- name: Calculate new version
id: calculate_new_version
run: |
latest_tag=$(git describe --tags --match "v*" --abbrev=0 $(git rev-list --tags --max-count=1))
if [[ -n "${{ github.event.inputs.version }}" ]]; then
version="${{ github.event.inputs.version }}"
if [[ ! $version == v* ]]; then
version="v$version"
fi
else
version=$(echo $latest_tag | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
fi
echo "previous_version=$latest_tag" >> "$GITHUB_OUTPUT"
echo "previous_release=${latest_tag#v}" >> "$GITHUB_OUTPUT"
echo "new_version=$version" >> "$GITHUB_OUTPUT"
echo "new_release=${version#v}" >> "$GITHUB_OUTPUT"
- name: Create tag
run: |
gh_actor_profile="$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${GITHUB_ACTOR}")"
git config --global user.name "$(printf '%s' "$gh_actor_profile" | jq -r .name)"
git config --global user.email "$(printf '%s' "$gh_actor_profile" | jq -r .email)"
git status
git tag "${{ steps.calculate_new_version.outputs.new_version }}"
- name: Build
env:
VERSIONING_GIT_REF: "refs/tags/${{ steps.calculate_new_version.outputs.new_version }}"
run: ./gradlew assemble --scan --console=plain --build-cache
- name: Test
env:
VERSIONING_GIT_REF: "refs/tags/${{ steps.calculate_new_version.outputs.new_version }}"
run: ./gradlew check --scan --console=plain --build-cache
- name: "Push Version Tag"
run: |
echo "Pushing tags to remote"
remote_repo="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git push "${remote_repo}" --tags
echo -e "\nPushed"
- name: Create changelog text
id: changelog
uses: loopwerk/tag-changelog@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.calculate_new_version.outputs.new_version }}
name: ${{ steps.calculate_new_version.outputs.new_release }}
body: ${{ steps.changelog.outputs.changes }}
draft: true
- name: Publish release
env:
VERSIONING_GIT_REF: "refs/tags/${{ steps.calculate_new_version.outputs.new_version }}"
ORG_GRADLE_PROJECT_ossrhSigningKey: "${{ secrets.ossrhSigningKey }}"
ORG_GRADLE_PROJECT_ossrhSigningPassword: "${{ secrets.ossrhSigningPassword }}"
ORG_GRADLE_PROJECT_ossrhPassword: "${{ secrets.ossrhPassword }}"
ORG_GRADLE_PROJECT_ossrhUser: "${{ secrets.ossrhUser }}"
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --scan --console=plain --build-cache
- name: Update README with new version
run: |
sed -i -e 's/${{ steps.calculate_new_version.outputs.previous_release }}/${{ steps.calculate_new_version.outputs.new_release }}/g' README.MD
- name: Create PR for post-release routines
id: post_release_pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.MASTER_TOKEN }}
commit-message: "chore: Post-release ${{ steps.calculate_new_version.outputs.new_release }}"
branch: "post-release/${{ steps.calculate_new_version.outputs.new_release }}"
title: "chore: Post-release ${{ steps.calculate_new_version.outputs.new_release }}"
body: "This is an automated PR to complete post-release ${{ steps.calculate_new_version.outputs.new_release }} routines."
base: master
- name: Enable post-release PR auto-merge
run: gh pr merge "${{ steps.post_release_pr.outputs.pull-request-number }}" --auto --rebase --delete-branch
env:
GH_TOKEN: ${{ secrets.MASTER_TOKEN }}