Skip to content

Commit acb0193

Browse files
authored
Merge pull request #32 from ps-jay/matrix
Add multi-OS testing (`ubuntu` & `macos` for now); Rework MacOS support to use `perl`
2 parents ae1ae19 + ed7b98e commit acb0193

4 files changed

Lines changed: 40 additions & 14 deletions

File tree

.github/workflows/test-and-release.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,20 @@ jobs:
7272
- lint
7373
- test
7474
- test-api-mode
75-
runs-on: ubuntu-latest
75+
strategy:
76+
matrix:
77+
os:
78+
- macos-latest
79+
- ubuntu-latest
80+
# - windows-latest -- coming soon, https://github.com/reecetech/version-increment/pull/30
81+
fail-fast: true
82+
runs-on: ${{ matrix.os }}
7683
steps:
7784
- name: Checkout code # have to checkout to have the source code available
7885
uses: actions/checkout@v4
7986

8087
- name: Remove .git directory # remove the git directory to make the testing valid
88+
shell: bash
8189
run: rm -rf .git/
8290

8391
- name: Get next version via API

shared.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,35 @@ if [[ "${use_api}" == 'true' ]] ; then
4949
fi
5050

5151
##==----------------------------------------------------------------------------
52-
## MacOS compatibility - for local testing
52+
## MacOS compatibility
5353

54-
export grep="grep"
55-
if [[ "$(uname)" == "Darwin" ]] ; then
56-
export grep="ggrep"
57-
if ! grep --version 1>/dev/null ; then
54+
export use_perl="false"
55+
export use_gnugrep="false"
56+
if [[ "${GITHUB_ACTIONS:-}" == 'true' && "$(uname)" == 'Darwin' ]] ; then
57+
export use_perl="true"
58+
elif [[ "$(uname)" == 'Darwin' ]] ; then
59+
if perl --version 1>/dev/null ; then
60+
export use_perl="true"
61+
elif ! ggrep --version 1>/dev/null ; then
5862
echo "🛑 GNU grep not installed, try brew install coreutils" 1>&2
5963
exit 9
64+
else
65+
export use_gnugrep="true"
6066
fi
6167
fi
6268

69+
function grep_p() {
70+
if [[ "${use_perl}" == 'true' ]] ; then
71+
perl -ne "print if /${1}/"
72+
elif [[ "${use_gnugrep}" == 'true' ]] ; then
73+
# shellcheck disable=SC2086
74+
ggrep -P "${1}"
75+
else
76+
# shellcheck disable=SC2086
77+
command grep -P "${1}"
78+
fi
79+
}
80+
6381
##==----------------------------------------------------------------------------
6482
## Non GitHub compatibility - for testing both locally and in BATS
6583

version-increment.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515
if [[ -z "${current_version:-}" ]] ; then
1616
echo "🛑 Environment variable 'current_version' is unset or empty" 1>&2
1717
input_errors='true'
18-
elif [[ -z "$(echo "${current_version}" | ${grep} -P "${pcre_master_ver}")" ]] ; then
18+
elif [[ -z "$(echo "${current_version}" | grep_p "${pcre_master_ver}")" ]] ; then
1919
echo "🛑 Environment variable 'current_version' is not a valid normal version (M.m.p)" 1>&2
2020
input_errors='true'
2121
fi
@@ -43,7 +43,7 @@ elif [[ -z "${BATS_VERSION:-}" ]] ; then
4343
| jq -r '.default_branch'
4444
)"
4545
else
46-
default_branch="$(git remote show origin | ${grep} 'HEAD branch' | cut -d ' ' -f 5)"
46+
default_branch="$(git remote show origin | grep 'HEAD branch' | cut -d ' ' -f 5)"
4747
fi
4848
fi
4949

@@ -67,13 +67,13 @@ if [[ "${scheme}" == 'conventional_commits' ]] ; then
6767

6868
# Check commit message header
6969
found_match='false'
70-
if [[ -n "$(echo "${commit_message}" | ${grep} -P "${pcre_conventional_commit_breaking}")" ]] ; then
70+
if [[ -n "$(echo "${commit_message}" | grep_p "${pcre_conventional_commit_breaking}")" ]] ; then
7171
increment='major'
7272
found_match='true'
73-
elif [[ -n "$(echo "${commit_message}" | ${grep} -P "${pcre_conventional_commit_minor}")" ]] ; then
73+
elif [[ -n "$(echo "${commit_message}" | grep_p "${pcre_conventional_commit_minor}")" ]] ; then
7474
increment='minor'
7575
found_match='true'
76-
elif [[ -n "$(echo "${commit_message}" | ${grep} -P "${pcre_conventional_commit_patch}")" ]] ; then
76+
elif [[ -n "$(echo "${commit_message}" | grep_p "${pcre_conventional_commit_patch}")" ]] ; then
7777
increment='patch'
7878
found_match='true'
7979
fi
@@ -128,7 +128,7 @@ if [[ "${current_ref}" != "refs/heads/${default_branch}" ]] ; then
128128
echo "PRE_RELEASE_LABEL=${pre_release}" >> "${GITHUB_OUTPUT}"
129129
fi
130130

131-
if [[ -z "$(echo "${new_version}" | ${grep} -P "${pcre_semver}")" ]] ; then
131+
if [[ -z "$(echo "${new_version}" | grep_p "${pcre_semver}")" ]] ; then
132132
echo "🛑 Version incrementing has failed to produce a semver compliant version" 1>&2
133133
echo "ℹ️ See: https://semver.org/spec/v2.0.0.html" 1>&2
134134
echo "ℹ️ Failed version string: '${new_version}'" 1>&2

version-lookup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ if [[ "${use_api:-}" == 'true' ]] ; then
3232
-H "X-GitHub-Api-Version: 2022-11-28" \
3333
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \
3434
| jq -r '.[].ref' | sed 's|refs/tags/||g' \
35-
| { ${grep} -P "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1
35+
| { grep_p "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1
3636
)"
3737
else
3838
current_version="$(
3939
git tag -l \
40-
| { ${grep} -P "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1
40+
| { grep_p "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1
4141
)"
4242
fi
4343

0 commit comments

Comments
 (0)