Skip to content

Release Aperture Java SDK #4

Release Aperture Java SDK

Release Aperture Java SDK #4

name: Release Aperture Java SDK
on:
workflow_dispatch:
inputs:
version_type:
type: choice
description: 'Version Type'
required: true
options:
- major
- minor
- patch
default: minor
concurrency:
cancel-in-progress: false
group: ${{ github.repository }}-release-aperture-java
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git Name and Email
run: |
git config --global user.name "FluxNinja Ops"
git config --global user.email [email protected]
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Install GitHub CLI
run: |
brew install gh
- name: Check diff and Create Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# Fetch all tags
git fetch --tags
# Get the latest tag name
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
# Get diff between latest tag and current commit
diff=$(git log $latestTag..HEAD --oneline)
# If there is no diff, exit
if [ -z "$diff" ]; then
echo "No changes since $latestTag."
exit 0
fi
# Fetch the version
version=$(echo $latestTag | grep -oP '(?<=v)\d+\.\d+\.\d+')
if [ -z "$version" ]; then
echo "No version found."
exit 1
fi
# Get the version type
versionType="${{ github.event.inputs.version_type }}"
if [ "$versionType" = "major" ]; then
newVersion=$(echo $version | awk -F. '{$1 = $1 + 1; $2 = 0; $3 = 0} 1' | sed 's/ /./g')
elif [ "$versionType" = "minor" ]; then
newVersion=$(echo $version | awk -F. '{$2 = $2 + 1; $3 = 0} 1' | sed 's/ /./g')
elif [ "$versionType" = "patch" ]; then
newVersion=$(echo $version | awk -F. '{$3 = $3 + 1;} 1' | sed 's/ /./g')
else
echo "Invalid version type."
exit 1
fi
# Replace the version
sed -i "s/ver = \".*\"/ver = \"$newVersion\"/g" version.gradle.kts
sed -i "s/snapshot = .*/snapshot = false/g" version.gradle.kts
sed -i "s/LIBRARY_VERSION = \".*\"/LIBRARY_VERSION = \"$newVersion\"/g" lib/core/src/main/java/com/fluxninja/aperture/sdk/Constants.java
# Create a new stable branch
git checkout -b "stable/v${newVersion}"
git commit --allow-empty -am "Bump version to ${newVersion}"
# Create a new tag and push it to origin
git tag -a "releases/aperture-java/v${newVersion}" -m "Release v${newVersion}"
# Push the branch and tag to origin
git push origin "stable/v${newVersion}"
git push origin "releases/aperture-java/v${newVersion}"
# Create a new release
gh release create "releases/aperture-java/v${newVersion}" --title "Release v${newVersion}" --target "stable/v${newVersion}" --generate-notes --latest --verify-tag