Skip to content

Generate a New Tag for Release #14

Generate a New Tag for Release

Generate a New Tag for Release #14

Workflow file for this run

name: Generate a New Tag for Release
on:
push:
branches:
- main
permissions:
contents: write
jobs:
build:
name: Release to GitHub releases
runs-on: ubuntu-latest
env:
BUG_OR_FEAT: ${{ endsWith(github.event.head_commit.message, '[tag-bug]') && 5 || 6 }}
if: ${{ endsWith(github.event.head_commit.message, '[tag-bug]') || endsWith(github.event.head_commit.message, '[tag-feat]') }}
steps:
- name: Set the Git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Generate tag
run: |
echo $BUG_OR_FEAT
VERSION_MAJOR="1"
VERSION_MINOR=$(git tag --list "${VERSION_MAJOR}.[0-9]*.[0-9]*" --sort=-version:refname | head -n 1 | grep -oE '[0-9]+\.[0-9]+$' | grep -oE '^[0-9]+')
VERSION_PATCH=$(git tag --list "${VERSION_MAJOR}.[0-9]*.[0-9]*" --sort=-version:refname | head -n 1 | grep -oE '[0-9]+$')
if [ $BUG_OR_FEAT -eq 5 ]; then
echo "BUG"
NEW_VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.$((VERSION_PATCH + 1))"
elif [ $BUG_OR_FEAT -eq 6 ]; then
NEW_VERSION="${VERSION_MAJOR}.$((VERSION_MINOR + 1)).0"
echo "FEAT"
else
echo "Critical error..! [1]"
exit 1
fi
echo "Generated version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Push Git Tag
run: |
git tag $NEW_TAG
git tag -a $NEW_VERSION -m "v$NEW_VERSION"
git push origin $NEW_VERSION
- name: Update the v1 tag with the latest code
run: |
git tag -fa v1 -m "Update the v1 tag with the latest code"
git push origin v1 --force