Skip to content

Commit

Permalink
Merge pull request #32 from ps-jay/matrix
Browse files Browse the repository at this point in the history
Add multi-OS testing (`ubuntu` & `macos` for now); Rework MacOS support to use `perl`
  • Loading branch information
ps-jay authored Apr 24, 2024
2 parents ae1ae19 + ed7b98e commit acb0193
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions version-increment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions version-lookup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit acb0193

Please sign in to comment.