Create a new release #13
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: Create a new release | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
description: 'Type of release: patch, minor, or major' | |
required: true | |
jobs: | |
get-last-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get Last Release Tag | |
id: get_last_release | |
run: | | |
LAST_RELEASE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
IFS='.' read -r MAJOR MINOR PATCH <<< "${LAST_RELEASE_TAG:1}" | |
echo "Last Release Tag: v$MAJOR.$MINOR.$PATCH" | |
echo "::set-output name=major_version::$MAJOR" | |
echo "::set-output name=minor_version::$MINOR" | |
echo "::set-output name=patch_version::$PATCH" | |
bump-version: | |
needs: get-last-release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Bump Version | |
id: bump_version | |
run: | | |
release_type="${{ github.event.inputs.release_type }}" | |
major_version="${{ needs.get_last_release.outputs.major_version }}" | |
minor_version="${{ needs.get_last_release.outputs.minor_version }}" | |
patch_version="${{ needs.get_last_release.outputs.patch_version }}" | |
if [ "$release_type" == "patch" ]; then | |
NEW_PATCH=$((patch_version + 1)) | |
NEW_VERSION="$major_version.$minor_version.$NEW_PATCH" | |
elif [ "$release_type" == "minor" ]; then | |
NEW_MINOR=$((minor_version + 1)) | |
NEW_VERSION="$major_version.$NEW_MINOR.0" | |
elif [ "$release_type" == "major" ]; then | |
NEW_MAJOR=$((major_version + 1)) | |
NEW_VERSION="$NEW_MAJOR.0.0" | |
else | |
echo "Invalid release_type. Use 'patch', 'minor', or 'major'." | |
exit 1 | |
fi | |
echo "Bumping version from $major_version.$minor_version.$patch_version to $NEW_VERSION" | |
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
create-release: | |
needs: bump-version | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Create Tag and Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ needs.bump-version.outputs.new_version }} | |
release_name: v${{ needs.bump-version.outputs.new_version }} | |
draft: false | |
prerelease: false |