mirror of
https://github.com/reecetech/version-increment.git
synced 2025-12-21 06:25: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
|
- lint
|
||||||
- test
|
- test
|
||||||
- test-api-mode
|
- 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:
|
steps:
|
||||||
- name: Checkout code # have to checkout to have the source code available
|
- name: Checkout code # have to checkout to have the source code available
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Remove .git directory # remove the git directory to make the testing valid
|
- name: Remove .git directory # remove the git directory to make the testing valid
|
||||||
|
shell: bash
|
||||||
run: rm -rf .git/
|
run: rm -rf .git/
|
||||||
|
|
||||||
- name: Get next version via API
|
- name: Get next version via API
|
||||||
|
|||||||
28
shared.sh
28
shared.sh
@@ -49,17 +49,35 @@ if [[ "${use_api}" == 'true' ]] ; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
##==----------------------------------------------------------------------------
|
##==----------------------------------------------------------------------------
|
||||||
## MacOS compatibility - for local testing
|
## MacOS compatibility
|
||||||
|
|
||||||
export grep="grep"
|
export use_perl="false"
|
||||||
if [[ "$(uname)" == "Darwin" ]] ; then
|
export use_gnugrep="false"
|
||||||
export grep="ggrep"
|
if [[ "${GITHUB_ACTIONS:-}" == 'true' && "$(uname)" == 'Darwin' ]] ; then
|
||||||
if ! grep --version 1>/dev/null ; 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
|
echo "🛑 GNU grep not installed, try brew install coreutils" 1>&2
|
||||||
exit 9
|
exit 9
|
||||||
|
else
|
||||||
|
export use_gnugrep="true"
|
||||||
fi
|
fi
|
||||||
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
|
## Non GitHub compatibility - for testing both locally and in BATS
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ fi
|
|||||||
if [[ -z "${current_version:-}" ]] ; then
|
if [[ -z "${current_version:-}" ]] ; then
|
||||||
echo "🛑 Environment variable 'current_version' is unset or empty" 1>&2
|
echo "🛑 Environment variable 'current_version' is unset or empty" 1>&2
|
||||||
input_errors='true'
|
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
|
echo "🛑 Environment variable 'current_version' is not a valid normal version (M.m.p)" 1>&2
|
||||||
input_errors='true'
|
input_errors='true'
|
||||||
fi
|
fi
|
||||||
@@ -43,7 +43,7 @@ elif [[ -z "${BATS_VERSION:-}" ]] ; then
|
|||||||
| jq -r '.default_branch'
|
| jq -r '.default_branch'
|
||||||
)"
|
)"
|
||||||
else
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -67,13 +67,13 @@ if [[ "${scheme}" == 'conventional_commits' ]] ; then
|
|||||||
|
|
||||||
# Check commit message header
|
# Check commit message header
|
||||||
found_match='false'
|
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'
|
increment='major'
|
||||||
found_match='true'
|
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'
|
increment='minor'
|
||||||
found_match='true'
|
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'
|
increment='patch'
|
||||||
found_match='true'
|
found_match='true'
|
||||||
fi
|
fi
|
||||||
@@ -128,7 +128,7 @@ if [[ "${current_ref}" != "refs/heads/${default_branch}" ]] ; then
|
|||||||
echo "PRE_RELEASE_LABEL=${pre_release}" >> "${GITHUB_OUTPUT}"
|
echo "PRE_RELEASE_LABEL=${pre_release}" >> "${GITHUB_OUTPUT}"
|
||||||
fi
|
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 "🛑 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 "ℹ️ See: https://semver.org/spec/v2.0.0.html" 1>&2
|
||||||
echo "ℹ️ Failed version string: '${new_version}'" 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" \
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \
|
||||||
| jq -r '.[].ref' | sed 's|refs/tags/||g' \
|
| 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
|
else
|
||||||
current_version="$(
|
current_version="$(
|
||||||
git tag -l \
|
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
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user