Skip to content

Feat/add semver

Feat/add semver #1

Workflow file for this run

name: Tag on PR Merge
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
bump-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch full history to get tags
- name: Get the branch that triggered the workflow
id: vars
run: |
echo "MERGE_BRANCH=$(git log -1 --pretty=%B | grep -oP '(feat|fix|rel)/[^\s]+')" >> $GITHUB_OUTPUT
echo "MERGE_BRANCH=${MERGE_BRANCH:-unknown}" >> $GITHUB_OUTPUT
- name: Determine version bump type
id: bump
run: |
if [[ "${{ steps.vars.outputs.MERGE_BRANCH }}" == feat/* ]]; then
echo "BUMP=minor" >> $GITHUB_ENV
elif [[ "${{ steps.vars.outputs.MERGE_BRANCH }}" == fix/* ]]; then
echo "BUMP=patch" >> $GITHUB_ENV
elif [[ "${{ steps.vars.outputs.MERGE_BRANCH }}" == rel/* ]]; then
echo "BUMP=major" >> $GITHUB_ENV
else
echo "BUMP=patch" >> $GITHUB_ENV
fi
- name: Show current tags
run: git tag
- name: Get current version
id: current_version
run: echo "CURRENT_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
- name: Bump version using npm
id: bump_version
run: |
echo "Bumping version with type $BUMP"
npm version $BUMP --no-git-tag-version > new_version.txt
NEW_VERSION=$(cat new_version.txt)
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create git tag for new version
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag ${{ steps.bump_version.outputs.NEW_VERSION }}
git push origin ${{ steps.bump_version.outputs.NEW_VERSION }}