feat: autotagging #3
Workflow file for this run
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 Version | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
jobs: | |
tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get current tag | |
id: current_tag | |
run: | | |
git fetch --tags | |
TAG=$(git describe --tags --abbrev=0 || echo "v0.0.0") | |
echo "Current tag: $TAG" | |
echo "::set-output name=TAG::$TAG" | |
- name: Bump version | |
id: bump_version | |
run: | | |
# Extract the current version | |
CURRENT_TAG="${{ steps.current_tag.outputs.TAG }}" | |
# Remove 'v' from the tag to work with numbers | |
VERSION=${CURRENT_TAG#v} | |
# Split version into major, minor, and patch parts | |
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION" | |
MAJOR=${VERSION_PARTS[0]} | |
MINOR=${VERSION_PARTS[1]} | |
PATCH=${VERSION_PARTS[2]} | |
# Increment the patch version | |
PATCH=$((PATCH + 1)) | |
# Generate a new version tag based on branch | |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
NEW_TAG="v$MAJOR.$MINOR.$PATCH" | |
elif [ "${{ github.ref }}" == "refs/heads/develop" ]; then | |
NEW_TAG="v$MAJOR.$MINOR.$PATCH-dev" | |
fi | |
echo "New tag: $NEW_TAG" | |
echo "::set-output name=NEW_TAG::$NEW_TAG" | |
- name: Create and push new tag | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
# Create new tag | |
git tag ${{ steps.bump_version.outputs.NEW_TAG }} | |
# Push the tag to the repository | |
git push origin ${{ steps.bump_version.outputs.NEW_TAG }} |