mirror of
https://github.com/reecetech/version-increment.git
synced 2025-12-21 14:35:44 +00:00
Merge pull request #32 from ps-jay/matrix
Add multi-OS testing (`ubuntu` & `macos` for now); Rework MacOS support to use `perl`
This commit is contained in:
10
.github/workflows/test-and-release.yml
vendored
10
.github/workflows/test-and-release.yml
vendored
@@ -72,12 +72,20 @@ jobs:
|
||||
- lint
|
||||
- test
|
||||
- test-api-mode
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- macos-latest
|
||||
- ubuntu-latest
|
||||
# - windows-latest -- coming soon, https://github.com/reecetech/version-increment/pull/30
|
||||
fail-fast: true
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout code # have to checkout to have the source code available
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Remove .git directory # remove the git directory to make the testing valid
|
||||
shell: bash
|
||||
run: rm -rf .git/
|
||||
|
||||
- name: Get next version via API
|
||||
|
||||
28
shared.sh
28
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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user