From 74a6f3d52027c37c25b7d14ff76fe7206db9bee9 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Wed, 24 Apr 2024 10:07:52 +1000 Subject: [PATCH 1/3] Run tests on all runner types --- .github/workflows/test-and-release.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index a8758fa..e52fe2d 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -72,12 +72,20 @@ jobs: - lint - test - test-api-mode - runs-on: ubuntu-latest + strategy: + matrix: + os: + - macos-latest + - ubuntu-latest + - windows-latest + 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 From 13338be6d337da02aa84b29a02330a307690fbcd Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Wed, 24 Apr 2024 10:58:22 +1000 Subject: [PATCH 2/3] Rework MacOS support --- shared.sh | 28 +++++++++++++++++++++++----- version-increment.sh | 12 ++++++------ version-lookup.sh | 4 ++-- 3 files changed, 31 insertions(+), 13 deletions(-) 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 From ed7b98e336326f09abf22f4bc1a0bd00dc9fd2cb Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Wed, 24 Apr 2024 11:45:57 +1000 Subject: [PATCH 3/3] Disable Windows testing for now --- .github/workflows/test-and-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index e52fe2d..ad348a7 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -77,7 +77,7 @@ jobs: os: - macos-latest - ubuntu-latest - - windows-latest + # - windows-latest -- coming soon, https://github.com/reecetech/version-increment/pull/30 fail-fast: true runs-on: ${{ matrix.os }} steps: