Skip to content

Release Aperture Python SDK #18

Release Aperture Python SDK

Release Aperture Python SDK #18

name: Release Aperture Python 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-py
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 from the tag
version=$(echo $latestTag | grep -oP '(?<=v)\d+\.\d+\.\d+')
# 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 in the pyproject.toml file
sed -i "s/^version = \".*\"/version = \"$newVersion\"/g" pyproject.toml
# 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-py/v${newVersion}" -m "Release v${newVersion}"
# Push the branch and tag to origin
git push origin "stable/v${newVersion}"
git push origin "releases/aperture-py/v${newVersion}"
# Create a new release
gh release create "releases/aperture-py/v${newVersion}" --title "Release v${newVersion}" --target "stable/v${newVersion}" --generate-notes --latest --verify-tag