mirror of
https://github.com/reecetech/version-increment.git
synced 2025-12-21 14:35:44 +00:00
feat: add new scheme conventional_commits
This commit is contained in:
11
action.yml
11
action.yml
@@ -8,7 +8,14 @@ branding:
|
||||
|
||||
inputs:
|
||||
scheme:
|
||||
description: 'Versioning scheme - semver, or, calver (defaults to semver)'
|
||||
description: |
|
||||
Versioning scheme - semver, calver or conventional_commits (defaults to semver).
|
||||
|
||||
`conventional_commits` Will parse the last commit message to determine the increment type.
|
||||
Supports the following increment types:
|
||||
- patch (build, chore, ci, docs, fix, perf, refactor, revert, style, test)
|
||||
- minor (feat)
|
||||
- Major (any of the above types with an '!' or 'BREAKING CHANGE:' in commit body)
|
||||
required: false
|
||||
default: 'semver'
|
||||
pep440:
|
||||
@@ -36,7 +43,7 @@ outputs:
|
||||
description: 'Current normal version detected'
|
||||
value: ${{ steps.version-lookup.outputs.CURRENT_VERSION }}
|
||||
current-v-version:
|
||||
description: 'Current normal version detected, prefixed with a `v` charatcter'
|
||||
description: 'Current normal version detected, prefixed with a `v` character'
|
||||
value: ${{ steps.version-lookup.outputs.CURRENT_V_VERSION }}
|
||||
version:
|
||||
description: 'Incremented version calculated'
|
||||
|
||||
13
shared.sh
13
shared.sh
@@ -11,13 +11,21 @@ pcre_master_ver='^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9
|
||||
pcre_allow_vprefix="^v{0,1}${pcre_master_ver:1}"
|
||||
pcre_old_calver='^(?P<major>0|[1-9]\d*)-0{0,1}(?P<minor>0|[0-9]\d*)-R(?P<patch>0|[1-9]\d*)$'
|
||||
|
||||
##==----------------------------------------------------------------------------
|
||||
## Conventional commit regexes
|
||||
## see: https://www.conventionalcommits.org/en/v1.0.0/
|
||||
|
||||
pcre_conventional_commit_patch='^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\([a-zA-Z0-9-]+\))?:\s.*'
|
||||
pcre_conventional_commit_minor='^(feat)(\([a-zA-Z0-9-]+\))?:\s.*'
|
||||
pcre_conventional_commit_breaking='^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-zA-Z0-9-]+\))?!:.*|BREAKING CHANGE:'
|
||||
|
||||
##==----------------------------------------------------------------------------
|
||||
## Input validation
|
||||
|
||||
input_errors='false'
|
||||
scheme="${scheme:-semver}"
|
||||
if [[ "${scheme}" != 'semver' && "${scheme}" != 'calver' ]] ; then
|
||||
echo "🛑 Value of 'scheme' is not valid, choose from 'semver' or 'calver'" 1>&2
|
||||
if [[ "${scheme}" != 'semver' && "${scheme}" != 'calver' && "${scheme}" != 'conventional_commits' ]] ; then
|
||||
echo "🛑 Value of 'scheme' is not valid, choose from 'semver', 'calver' or 'conventional_commits" 1>&2
|
||||
input_errors='true'
|
||||
fi
|
||||
|
||||
@@ -40,7 +48,6 @@ if [[ "${use_api}" == 'true' ]] ; then
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
##==----------------------------------------------------------------------------
|
||||
## MacOS compatibility - for local testing
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ elif [[ -z "${BATS_VERSION:-}" ]] ; then
|
||||
fi
|
||||
|
||||
current_ref="${GITHUB_REF:-}"
|
||||
git_commit_sha=${GITHUB_SHA:-}
|
||||
|
||||
if [[ "${use_api:-}" == 'true' ]] ; then
|
||||
# because we cannot use `rev-parse` with the API, we'll take a punt that 9 characters is enough for uniqueness
|
||||
@@ -55,7 +56,33 @@ if [[ "${use_api:-}" == 'true' ]] ; then
|
||||
git_commit="$(echo "${GITHUB_SHA:0:9}" | sed 's/0*//')" # Also, trim leading zeros, because semver doesn't allow that in
|
||||
else # the 'pre-release version' part, but we can't use the + char
|
||||
git_commit="$(git rev-parse --short HEAD | sed 's/0*//')" # to make it 'build metadata' as that's not supported in K8s
|
||||
fi # labels
|
||||
git_commit_sha="$(git rev-parse --short HEAD)" # labels
|
||||
fi
|
||||
|
||||
##==----------------------------------------------------------------------------
|
||||
## Conventional commits
|
||||
# If calver is set, raise a warning
|
||||
if [[ "${scheme}" == 'conventional_commits' ]] ; then
|
||||
# Get message from given commit
|
||||
commit_message=$(git log -1 --pretty=format:%B "${git_commit_sha}")
|
||||
|
||||
# Check commit message header
|
||||
found_match='false'
|
||||
if [[ -n "$(echo "${commit_message}" | ${grep} -P "${pcre_conventional_commit_breaking}")" ]] ; then
|
||||
increment='major'
|
||||
found_match='true'
|
||||
elif [[ -n "$(echo "${commit_message}" | ${grep} -P "${pcre_conventional_commit_minor}")" ]] ; then
|
||||
increment='minor'
|
||||
found_match='true'
|
||||
elif [[ -n "$(echo "${commit_message}" | ${grep} -P "${pcre_conventional_commit_patch}")" ]] ; then
|
||||
increment='patch'
|
||||
found_match='true'
|
||||
fi
|
||||
|
||||
if [[ "${found_match}" == 'false' ]] ; then
|
||||
echo "⚠️ No conventional commit found, defaulting to ${increment} increment" 1>&2
|
||||
fi
|
||||
fi
|
||||
|
||||
##==----------------------------------------------------------------------------
|
||||
## Version increment
|
||||
|
||||
@@ -46,7 +46,7 @@ if [[ -z "${current_version:-}" ]] ; then
|
||||
echo "⚠️ No previous release version identified in git tags"
|
||||
# brand new repo! (probably)
|
||||
case "${scheme}" in
|
||||
semver)
|
||||
semver | conventional_commits)
|
||||
current_version="0.0.0"
|
||||
;;
|
||||
calver)
|
||||
|
||||
Reference in New Issue
Block a user