Skip to content

Commit

Permalink
Refactor build workflow to calculate version number dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
rabilrbl committed Feb 4, 2024
1 parent d72c027 commit d93c011
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Build & Publish Release APK

on:
push:
branches:
- stable
tags:
- "*"
workflow_dispatch:
Expand Down Expand Up @@ -42,48 +40,6 @@ jobs:
if [[ ${{ github.ref_name }} == v* ]]; then
tag="${{ github.ref_name }}"
echo "prerelease=false" >> $GITHUB_OUTPUT
elif [[ ${{ github.ref_name }} == stable ]]; then
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
tag=$(git describe --tags --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=0)
echo "Latest tag: $tag"
if [[ $tag == "" ]]; then
echo "No semver tag found, use 0.0.0"
tag="v0.0.0"
fi
# Get the major, minor and patch parts from the tag.
major_minor_patch=$(echo $tag | grep -oE "[0-9]+\.[0-9]+\.[0-9]+")
echo "Major, minor and patch version: $major_minor_patch"
major=$(echo $major_minor_patch | grep -oE "^[0-9]+")
minor=$(echo $major_minor_patch | grep -oE "\.[0-9]+\." | grep -oE "[0-9]+")
patch=$(echo $major_minor_patch | grep -oE "[0-9]+$")
echo "Major version: $major"
echo "Minor version: $minor"
echo "Patch version: $patch"
commits=$(git rev-list $tag.. --count)
echo "Commits since last tag: $commits"
# If any of commit messages contains "BREAKING" string, increment major version.
breaking_changes=$(git log --pretty=%B $tag.. | grep -iE "BREAKING" | wc -l)
echo "Breaking changes: $breaking_changes"
if [[ $breaking_changes -gt 0 ]]; then
major=$((major + 1))
minor=0
patch=0
else
# Increment minor version.
features=$(git log --pretty=%B $tag.. | grep -iE "feat|compatibility|integration|upgrade" | wc -l)
echo "Features: $features"
if [[ $features -gt 0 ]]; then
minor=$((minor + 1))
patch=0
else
patch=$((patch + 1))
fi
fi
# Calculate the new version number.
tag="v${major}.${minor}.${patch}"
echo "New version: $tag"
echo "prerelease=false" >> $GITHUB_OUTPUT
else
tag="$(date +'vdev.%y.%m.%d.%H%M%S')"
echo "prerelease=true" >> $GITHUB_OUTPUT
Expand Down

0 comments on commit d93c011

Please sign in to comment.