diff --git a/shared.sh b/shared.sh index d9f529f..714587a 100644 --- a/shared.sh +++ b/shared.sh @@ -49,17 +49,35 @@ if [[ "${use_api}" == 'true' ]] ; then fi ##==---------------------------------------------------------------------------- -## MacOS compatibility - for local testing +## MacOS compatibility -export grep="grep" -if [[ "$(uname)" == "Darwin" ]] ; then - export grep="ggrep" - if ! grep --version 1>/dev/null ; then +export use_perl="false" +export use_gnugrep="false" +if [[ "${GITHUB_ACTIONS:-}" == 'true' && "$(uname)" == 'Darwin' ]] ; then + export use_perl="true" +elif [[ "$(uname)" == 'Darwin' ]] ; then + if perl --version 1>/dev/null ; then + export use_perl="true" + elif ! ggrep --version 1>/dev/null ; then echo "🛑 GNU grep not installed, try brew install coreutils" 1>&2 exit 9 + else + export use_gnugrep="true" fi fi +function grep_p() { + if [[ "${use_perl}" == 'true' ]] ; then + perl -ne "print if /${1}/" + elif [[ "${use_gnugrep}" == 'true' ]] ; then + # shellcheck disable=SC2086 + ggrep -P "${1}" + else + # shellcheck disable=SC2086 + command grep -P "${1}" + fi +} + ##==---------------------------------------------------------------------------- ## Non GitHub compatibility - for testing both locally and in BATS diff --git a/version-increment.sh b/version-increment.sh index e76c091..9fef875 100755 --- a/version-increment.sh +++ b/version-increment.sh @@ -15,7 +15,7 @@ fi if [[ -z "${current_version:-}" ]] ; then echo "🛑 Environment variable 'current_version' is unset or empty" 1>&2 input_errors='true' -elif [[ -z "$(echo "${current_version}" | ${grep} -P "${pcre_master_ver}")" ]] ; then +elif [[ -z "$(echo "${current_version}" | grep_p "${pcre_master_ver}")" ]] ; then echo "🛑 Environment variable 'current_version' is not a valid normal version (M.m.p)" 1>&2 input_errors='true' fi @@ -43,7 +43,7 @@ elif [[ -z "${BATS_VERSION:-}" ]] ; then | jq -r '.default_branch' )" else - default_branch="$(git remote show origin | ${grep} 'HEAD branch' | cut -d ' ' -f 5)" + default_branch="$(git remote show origin | grep 'HEAD branch' | cut -d ' ' -f 5)" fi fi @@ -67,13 +67,13 @@ if [[ "${scheme}" == 'conventional_commits' ]] ; then # Check commit message header found_match='false' - if [[ -n "$(echo "${commit_message}" | ${grep} -P "${pcre_conventional_commit_breaking}")" ]] ; then + 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 + 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 + elif [[ -n "$(echo "${commit_message}" | grep_p "${pcre_conventional_commit_patch}")" ]] ; then increment='patch' found_match='true' fi @@ -128,7 +128,7 @@ if [[ "${current_ref}" != "refs/heads/${default_branch}" ]] ; then echo "PRE_RELEASE_LABEL=${pre_release}" >> "${GITHUB_OUTPUT}" fi -if [[ -z "$(echo "${new_version}" | ${grep} -P "${pcre_semver}")" ]] ; then +if [[ -z "$(echo "${new_version}" | grep_p "${pcre_semver}")" ]] ; then echo "🛑 Version incrementing has failed to produce a semver compliant version" 1>&2 echo "â„šī¸ See: https://semver.org/spec/v2.0.0.html" 1>&2 echo "â„šī¸ Failed version string: '${new_version}'" 1>&2 diff --git a/version-lookup.sh b/version-lookup.sh index 3957688..1780cc9 100755 --- a/version-lookup.sh +++ b/version-lookup.sh @@ -32,12 +32,12 @@ if [[ "${use_api:-}" == 'true' ]] ; then -H "X-GitHub-Api-Version: 2022-11-28" \ "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \ | jq -r '.[].ref' | sed 's|refs/tags/||g' \ - | { ${grep} -P "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1 + | { grep_p "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1 )" else current_version="$( git tag -l \ - | { ${grep} -P "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1 + | { grep_p "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1 )" fi