From 5961b2756be416c40a1a4e219d3f36a9d165fac7 Mon Sep 17 00:00:00 2001 From: Jack Green Date: Fri, 16 Aug 2024 15:25:35 +0100 Subject: [PATCH] Fix `grep: invalid option -- P` error on Mac (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/hazelcast/backport/issues/7#issuecomment-2293395013 --------- Co-authored-by: Ɓukasz Dziedziul <1242724+ldziedziul@users.noreply.github.com> --- .github/workflows/test-pr.yml | 9 +++++++-- backport.functions | 2 +- backport.functions_tests | 10 +++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 8e75806..b74b9ad 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -5,8 +5,13 @@ on: jobs: test: - runs-on: ubuntu-latest - + strategy: + matrix: + runs-on: + - ubuntu-latest + - macos-latest + name: Test (${{matrix.runs-on}}) + runs-on: ${{matrix.runs-on}} steps: - uses: actions/checkout@v4 - run: ./backport.functions_tests diff --git a/backport.functions b/backport.functions index 373108b..2fd3a14 100755 --- a/backport.functions +++ b/backport.functions @@ -5,5 +5,5 @@ set -e function get_pr_number() { local commit_msg=$1 - echo "$commit_msg" | grep -oP '#(\d+)' | tail -n1 | cut -c2- + echo "$commit_msg" | grep --extended-regexp --only-matching '#[0-9]+' | tail -n1 | cut -c2- } diff --git a/backport.functions_tests b/backport.functions_tests index 03cba9c..af3e1a4 100755 --- a/backport.functions_tests +++ b/backport.functions_tests @@ -4,9 +4,13 @@ set -eu SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" # Source the latest version of assert.sh unit testing library and include in current shell -assert_script_content=$(curl --silent https://raw.githubusercontent.com/hazelcast/assert.sh/main/assert.sh) +curl --silent https://raw.githubusercontent.com/hazelcast/assert.sh/main/assert.sh --output assert.sh + # shellcheck source=/dev/null -. <(echo "${assert_script_content}") +# You _should_ be able to avoid a temporary file with something like +# . <(echo "${assert_script_content}") +# But this doesn't work on the MacOS GitHub runner (but does on MacOS locally) +. assert.sh . "$SCRIPT_DIR"/backport.functions TESTS_RESULT=0 @@ -15,7 +19,7 @@ function test_get_pr_number { local commit_msg=$1 local expected_pr_number=$2 local actual_pr_number=$(get_pr_number "$commit_msg") - local MSG="Expected PR Number extracted from \"$commit_msg\"" + local MSG="Expected PR Number extracted from \"$commit_msg\" should be equal to \"$expected_pr_number\"" assert_eq "$expected_pr_number" "$actual_pr_number" "$MSG" && log_success "$MSG" || TESTS_RESULT=$? }