2021-10-20 11:18:23 +11:00
|
|
|
#!/bin/bash
|
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
2021-10-21 23:38:24 +11:00
|
|
|
##==----------------------------------------------------------------------------
|
|
|
|
|
## SemVer regexes
|
|
|
|
|
## see: https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
|
|
|
|
|
2021-10-20 11:18:23 +11:00
|
|
|
pcre_semver='^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
|
|
|
|
|
pcre_master_ver='^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)$'
|
|
|
|
|
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*)$'
|
|
|
|
|
|
2021-10-21 23:38:24 +11:00
|
|
|
##==----------------------------------------------------------------------------
|
|
|
|
|
## Input validation
|
|
|
|
|
|
|
|
|
|
input_errors='false'
|
2021-10-22 11:49:04 +11:00
|
|
|
scheme="${scheme:-semver}"
|
2023-04-26 15:18:48 +10:00
|
|
|
if [[ "${scheme}" != 'semver' && "${scheme}" != 'calver' && "${scheme}" != 'pep440' ]] ; then
|
|
|
|
|
echo "🛑 Value of 'scheme' is not valid, choose from 'semver', 'calver', or 'pep440'" 1>&2
|
2021-10-21 23:38:24 +11:00
|
|
|
input_errors='true'
|
|
|
|
|
fi
|
|
|
|
|
|
2021-10-20 11:18:23 +11:00
|
|
|
##==----------------------------------------------------------------------------
|
|
|
|
|
## MacOS compatibility - for local testing
|
|
|
|
|
|
|
|
|
|
export grep="grep"
|
|
|
|
|
if [[ "$(uname)" == "Darwin" ]] ; then
|
|
|
|
|
export grep="ggrep"
|
|
|
|
|
if ! grep --version 1>/dev/null ; then
|
|
|
|
|
echo "🛑 GNU grep not installed, try brew install coreutils" 1>&2
|
|
|
|
|
exit 9
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2022-10-19 08:51:07 +11:00
|
|
|
|
|
|
|
|
##==----------------------------------------------------------------------------
|
|
|
|
|
## Non GitHub compatibility - for testing both locally and in BATS
|
|
|
|
|
|
|
|
|
|
if [[ -z "${GITHUB_OUTPUT:-}" || -n "${BATS_VERSION:-}" ]] ; then
|
|
|
|
|
export GITHUB_OUTPUT="/dev/stdout"
|
|
|
|
|
fi
|