Skip to content

Manual Release

Manual Release #9

Workflow file for this run

name: Manual Release
on:
workflow_dispatch:
inputs:
release_type:
description: 'Type of release (major, minor, patch, or specific)'
required: true
type: choice
options:
- major
- minor
- patch
- specific
specific_version:
description: 'Specify version if release type is "specific" (e.g., 1.0.0)'
required: false
jobs:
release:
runs-on: ubuntu-latest
# Define outputs for this job
outputs:
new_release_version: ${{ steps.get_new_version.outputs.new_release_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest release version and calculate new version
id: get_new_version
run: |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $latest_tag"
current_version=${latest_tag#v}
IFS='.' read -r -a version_parts <<< "$current_version"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}
new_version=""
release_type="${{ github.event.inputs.release_type }}"
if [ "$release_type" == "specific" ]; then
if [ -z "${{ github.event.inputs.specific_version }}" ]; then
echo "Error: specific_version is required when release_type is specific."
exit 1
fi
new_version="${{ github.event.inputs.specific_version }}"
elif [ "$release_type" == "major" ]; then
new_version="$((major + 1)).0.0"
elif [ "$release_type" == "minor" ]; then
new_version="${major}.$((minor + 1)).0"
elif [ "$release_type" == "patch" ]; then
new_version="${major}.${minor}.$((patch + 1))"
else
echo "Error: Invalid release_type provided."
exit 1
fi
echo "New calculated version: v$new_version"
echo "new_release_version=v$new_version" >> "$GITHUB_OUTPUT"
# Also output the latest_tag for the changelog builder
echo "latest_existing_tag=$latest_tag" >> "$GITHUB_OUTPUT"
- name: Create Git Tag
id: create_git_tag
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git tag ${{ steps.get_new_version.outputs.new_release_version }}
git push origin ${{ steps.get_new_version.outputs.new_release_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Changelog
id: generate_changelog
uses: mikepenz/release-changelog-builder-action@v5
with:
fromTag: ${{ steps.get_new_version.outputs.latest_existing_tag == 'v0.0.0' && '' || steps.get_new_version.outputs.latest_existing_tag }}
toTag: ${{ steps.get_new_version.outputs.new_release_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_new_version.outputs.new_release_version }}
release_name: Release ${{ steps.get_new_version.outputs.new_release_version }}
body: ${{ steps.generate_changelog.outputs.changelog }}
draft: false
prerelease: false
cleanup_on_failure:
runs-on: ubuntu-latest
needs: release # This job depends on the 'release' job
if: ${{ always() && (needs.release.result == 'failure' || needs.release.result == 'cancelled') }} # Run if release job failed or was cancelled
steps:
- name: Checkout code (for tag deletion)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Delete Git Tag on Failure
run: |
# Access the output from the 'release' job using needs.release.outputs
TAG_TO_DELETE="${{ needs.release.outputs.new_release_version }}"
if [ -n "$TAG_TO_DELETE" ]; then
echo "Deleting tag: $TAG_TO_DELETE due to workflow failure/cancellation."
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git push origin --delete "$TAG_TO_DELETE" || true # Use || true to prevent the step from failing if tag doesn't exist
else
echo "No tag to delete or new_release_version not set from previous job."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}