Skip to content

Commit

Permalink
Merge pull request #2 from tawanda-kembo/feat/automate-versioning
Browse files Browse the repository at this point in the history
chore: update GitHub Actions workflow and add contribution guidelines
  • Loading branch information
tawandakembo authored Jul 27, 2024
2 parents 7f79ce1 + d8711f0 commit 212cc5d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/tag-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ on:
jobs:
tag:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Git
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
- name: Bump version and push tag
id: tag
uses: anothrNick/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_prefix: "v"
release_branches: main
custom_tag: |
if [[ ${{ github.event.head_commit.message }} =~ ^(feat|fix|perf|refactor|BREAKING CHANGE|build|ci|chore|docs|style|test): ]]; then
echo "::set-output name=custom_tag::${{ steps.tag.outputs.tag_name }}"
fi
env:
DEFAULT_BUMP: minor
run: ./bump_version.sh

- name: Create Release
if: steps.tag.outputs.tag_name != ''
if: success()
uses: actions/create-release@v1
with:
tag_name: ${{ steps.tag.outputs.tag_name }}
release_name: Release ${{ steps.tag.outputs.tag_name }}
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
See [CHANGELOG](https://github.com/tawanda-kembo/code-collator/blob/main/CHANGELOG.md) for details.
draft: false
Expand Down
40 changes: 40 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
set -e

# Default bump type
DEFAULT_BUMP=${DEFAULT_BUMP:-minor}

# Get the current version
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")

# Split the version into parts
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"

# Bump the version
case $DEFAULT_BUMP in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
*)
echo "Unknown bump type: $DEFAULT_BUMP"
exit 1
;;
esac

NEW_VERSION="$MAJOR.$MINOR.$PATCH"

# Create a new tag
git tag "v$NEW_VERSION"
git push origin "v$NEW_VERSION"

0 comments on commit 212cc5d

Please sign in to comment.