Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,39 @@ jobs:
version_tag_numeric: ${{ steps.version_bumped_gitlog_major.outputs.version_tag_numeric }}
version_tag: ${{ steps.version_bumped_gitlog_major.outputs.version_tag }}

###########################################################################################

- name: merge a feat/ branch but with merge commit bump DISABLED
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git branch feat/no-bump-test
git switch feat/no-bump-test
touch no-bump-test
echo 'no-bump-test' > no-bump-test
git add no-bump-test
git commit -m "feat: no-bump-test"
git checkout main
git merge feat/no-bump-test --no-ff --commit --no-edit

- name: bump should be patch (1.0.1) NOT minor (1.1.0) because merge bump is disabled
id: version_no_merge_bump
run: ./version-bump.sh
env:
GHA_TAG: latest
GHA_ENABLE_MERGE_COMMIT_BUMP: "false"

- name: test that 1.0.0 has bumped to 1.0.1 (patch) and NOT 1.1.0 (minor)
run: |
if [[ "$version_tag_numeric" == '1.0.1' ]];then
echo "winning"
else
echo "Expected 1.0.1 but got $version_tag_numeric"
exit 1
fi
shell: bash
env:
version_tag_numeric: ${{ steps.version_no_merge_bump.outputs.version_tag_numeric }}

###########################################################################################

6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ inputs:
required: false
default: "second_merge"
type: string
enable_merge_commit_bump:
description: 'enable bumping based on merge commit messages'
required: false
default: "true"
type: string


outputs:
Expand Down Expand Up @@ -51,3 +56,4 @@ runs:
GHA_TAG: ${{ inputs.version_tag }}
GHA_BUMP: ${{ inputs.bump }}
GHA_GIT_LOG_FROM: ${{ inputs.git_log_from }}
GHA_ENABLE_MERGE_COMMIT_BUMP: ${{ inputs.enable_merge_commit_bump }}
45 changes: 30 additions & 15 deletions version-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ major=0
minor=0
patch=0
git_log_from=${GHA_GIT_LOG_FROM:-second_merge}
enable_merge_commit_bump=${GHA_ENABLE_MERGE_COMMIT_BUMP:-1}

#
# functions
Expand Down Expand Up @@ -59,6 +60,7 @@ I_USAGE="
-b | --bump ) bump either none patch|minor|major or ($bump) using the a #minor #major git commit message default patch
-l | --git_log_from ) where from the git log history to look from when considering in #minor #major messages ($git_log_from)
options are: numeric (number of lines) , last_tag , second_merge (github actions triggers after a merge)
-m | --enable_merge_commit_bump ) enable bumping based on merge commit messages ($enable_merge_commit_bump)
"
echo "$I_USAGE"
exit
Expand All @@ -82,12 +84,22 @@ do
-t | --tag ) tag=$2 ;shift 2 ;;
-b | --bump ) bump=$2 ;shift 2 ;;
-l | --git_log_from ) git_log_from=$2 ;shift 2 ;;
-m | --enable_merge_commit_bump ) enable_merge_commit_bump=$2 ;shift 2 ;;
--) shift ; break ;;
-*) echo "WARN: Unknown option (ignored): $1" >&2 ; shift ;;
*) break ;;
esac
done

# handle true/false for enable_merge_commit_bump
if [[ -z "$enable_merge_commit_bump" ]]; then
enable_merge_commit_bump=1
elif [[ "$enable_merge_commit_bump" == "true" ]]; then
enable_merge_commit_bump=1
elif [[ "$enable_merge_commit_bump" == "false" ]]; then
enable_merge_commit_bump=0
fi

# handle running locally
GITHUB_OUTPUT=${GITHUB_OUTPUT:-/tmp/$NAME.$USER}

Expand Down Expand Up @@ -172,27 +184,30 @@ if [[ "$git_log_from" = 'second_merge' ]];then
commits_for_bump=$(git log $second_merge_id..HEAD --oneline)
fi

# Allow git commit messages to override bump value
# Check for #major or #minor in commit message and increment the relevant version number

merge_commit=$(git log --merges -n 1)

echo "----------------------------------------------"
echo "commits_for_bump:"
echo "$commits_for_bump"
echo " "
echo "----------------------------------------------"
echo " "
echo "merge_commit:"
echo "$merge_commit"

if grep -qE 'feat' <<< $(echo $merge_commit);then
echo "feature git commit detected"
minor=1
fi
# Allow git commit messages to override bump value
# Check for #major or #minor in commit message and increment the relevant version number
if [[ "$enable_merge_commit_bump" -eq 1 ]]; then
merge_commit=$(git log --merges -n 1)
echo "----------------------------------------------"
echo "merge_commit:"
echo "$merge_commit"
echo "----------------------------------------------"

if grep -qE 'feat' <<< $(echo $merge_commit);then
echo "feature git commit detected"
minor=1
fi

if grep -qE 'fix|bug|patch|test' <<< $(echo $merge_commit);then
echo "fix|bug|patch|test git commit detected"
patch=1
if grep -qE 'fix|bug|patch|test' <<< $(echo $merge_commit);then
echo "fix|bug|patch|test git commit detected"
patch=1
fi
fi

if grep -q '#major' <<< $(echo $commits_for_bump) ;then
Expand Down
Loading