Tag and Release #9
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: Tag and Release | |
on: | |
workflow_dispatch: | |
branches: | |
- main | |
inputs: | |
default-bump: | |
description: 'Version change type' | |
type: choice | |
required: false | |
default: patch | |
options: | |
- major | |
- minor | |
- patch | |
create-release: | |
description: 'Create release for tag' | |
type: boolean | |
required: false | |
default: false | |
dry-run: | |
description: 'Do not commit or tag anything.' | |
type: boolean | |
required: false | |
default: false | |
tag-annotated: | |
description: 'Annotated tag (not lightweight)' | |
type: boolean | |
required: false | |
default: false | |
tag-prefix: | |
description: 'Tag version prefix' | |
type: string | |
required: false | |
default: 'v' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Git User | |
shell: bash | |
# language="shell script" | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
- name: Bump version and push tag | |
id: tag_latest | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
default_bump: ${{ inputs.default-bump }} | |
# custom_tag: ${{ inputs.custom-tag }} | |
create_annotated_tag: ${{ inputs.annotated-tag }} | |
tag_prefix: ${{ inputs.tag-prefix }} | |
- name: Create a GitHub release | |
id: create_release | |
if: ${{ ! inputs.dry-run && inputs.create-release }} | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ steps.tag_latest.outputs.new_tag }} | |
name: Release ${{ steps.tag_latest.outputs.new_tag }} | |
body: ${{ steps.tag_latest.outputs.changelog }} | |
- name: Move Major Version Tag | |
id: move_major | |
if: ${{ ! inputs.dry-run }} | |
shell: bash | |
env: | |
NEW_VERSION: ${{ steps.tag_latest.outputs.new_version }} | |
TAG_PREFIX: ${{ inputs.tag-prefix }} | |
# language="shell script" | |
run: | | |
MAJOR_TAG="" | |
MAJOR_VERSION="${NEW_VERSION%%.*}" | |
if [ -n "${MAJOR_VERSION}" ] ; then | |
MAJOR_TAG="${TAG_PREFIX}${MAJOR_VERSION}" | |
git tag -fa "${MAJOR_TAG}" -m 'Update major version tag' | |
git push origin "${MAJOR_TAG}" --force | |
fi | |
printf '%s\n' \ | |
"major-tag=${MAJOR_TAG}" \ | |
"major-version=${MAJOR_VERSION}" \ | |
>> $GITHUB_OUTPUT |