From d22bb3df2d7ec266966a6943b4627d0f1eedf492 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 8 Mar 2025 16:23:27 +0100 Subject: [PATCH 1/7] fix(github): More Tolerance in GNU-Compat Test ASSUME_GNU may now be "true" or "yes". This aligns with the CI call. Also, I output the value of ASSUME_GNU when executing the script. --- demo/gnucompat-demo.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/demo/gnucompat-demo.sh b/demo/gnucompat-demo.sh index 79ffe6f..b1836e2 100755 --- a/demo/gnucompat-demo.sh +++ b/demo/gnucompat-demo.sh @@ -66,7 +66,7 @@ function demo_sed() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) local -r sed_script='s/World/GNU/g' # This command will fail if the GNU version of `sed` is not available. echo "${input}" | "${SED}" --regexp-extended "${sed_script}" @@ -84,7 +84,7 @@ function demo_awk() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # shellcheck disable=SC2016 local -r awk_script='{ print "Hello, GNU!" }' # This command will fail if the GNU version of `sed` is not available. @@ -104,7 +104,7 @@ function demo_grep() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) local -r grep_pattern="World" # This command will fail if the GNU version of `grep` is not available. echo "${input}" | "${GREP}" --only-matching "${grep_pattern}" @@ -122,7 +122,7 @@ function demo_sort() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `sort` is not available. echo "${input}" | "${SORT}" --ignore-leading-blanks ;; @@ -136,7 +136,7 @@ function demo_date() { echo "DATE Demo:" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `date` is not available. "${DATE}" --utc ;; @@ -151,7 +151,7 @@ function demo_xargs() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `xargs` is not available. echo "${input}" | "${XARGS}" --no-run-if-empty echo ;; @@ -167,7 +167,7 @@ function demo_cut() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `cut` is not available. echo "${input}" | "${CUT}" --characters=3 ;; @@ -183,7 +183,7 @@ function demo_head() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `head` is not available. echo "${input}" | "${HEAD}" --lines=1 ;; @@ -199,7 +199,7 @@ function demo_tail() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `tail` is not available. echo "${input}" | "${TAIL}" --lines=1 ;; @@ -215,7 +215,7 @@ function demo_tr() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `tr` is not available. echo "${input}" | "${TR}" --delete ' ' ;; @@ -231,7 +231,7 @@ function demo_uniq() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `uniq` is not available. echo "${input}" | "${UNIQ}" --count ;; @@ -247,7 +247,7 @@ function demo_wc() { local -r input=" Hello, World!" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `wc` is not available. echo "${input}" | "${WC}" --words ;; @@ -269,7 +269,7 @@ function demo_diff() { echo "${input2}" >"${file2}" case "${ASSUME_GNU}" in - yes) + yes | true) # This command will fail if the GNU version of `diff` is not available. "${DIFF}" --brief "${file1}" "${file2}" ;; @@ -280,6 +280,7 @@ function demo_diff() { } function demo_all() { + echo "Running all demos, assuming GNU available: ${ASSUME_GNU}." demo_sed demo_awk demo_grep From 8bcf0992915baa2d8b1ca87a7ad6fdaa6c099e1a Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 8 Mar 2025 18:33:47 +0100 Subject: [PATCH 2/7] fix(demo): Try Error Analysis (sed) As first sketch, let's evaluate a way to deal with a possible error raised by `sed` (as first command). --- demo/gnucompat-demo.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/demo/gnucompat-demo.sh b/demo/gnucompat-demo.sh index b1836e2..088b544 100755 --- a/demo/gnucompat-demo.sh +++ b/demo/gnucompat-demo.sh @@ -64,18 +64,34 @@ function demo_sed() { echo "SED Demo:" local -r input=" Hello, World!" + local result case "${ASSUME_GNU}" in yes | true) local -r sed_script='s/World/GNU/g' # This command will fail if the GNU version of `sed` is not available. - echo "${input}" | "${SED}" --regexp-extended "${sed_script}" + if echo "${input}" | "${SED}" --regexp-extended "${sed_script}"; then + result=$? + else + result=$? + fi ;; *) local -r sed_script='s/World/Non-GNU/g' - echo "${input}" | "${SED}" -r "${sed_script}" + if echo "${input}" | "${SED}" -r "${sed_script}"; then + result=$? + else + result=$? + fi ;; esac + + if [ "${result}" -eq 0 ]; then + echo "Success!" + else + echo "Failure!" + exit 1 + fi } function demo_awk() { From ca43d8cb369a364767a2453a8f4b82a6d1f62dfb Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 8 Mar 2025 20:05:42 +0100 Subject: [PATCH 3/7] fix(demo): Debug Demo Run Trying to identify, why the Job does not fail, if a command executed in the GNU compat demo fails. --- .github/workflows/system-tests-demo.yml | 4 +++- demo/all-demos.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/system-tests-demo.yml b/.github/workflows/system-tests-demo.yml index e66e682..2bba6f0 100644 --- a/.github/workflows/system-tests-demo.yml +++ b/.github/workflows/system-tests-demo.yml @@ -30,4 +30,6 @@ jobs: run: echo "ASSUME_GNU=${{ matrix.install_gnu_tools }}" >> $GITHUB_ENV - name: Run all demos - run: demo/all-demos.sh + run: | + demo/all-demos.sh + echo "Success: ${?}" diff --git a/demo/all-demos.sh b/demo/all-demos.sh index bea70b6..2070040 100755 --- a/demo/all-demos.sh +++ b/demo/all-demos.sh @@ -5,12 +5,14 @@ SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" declare -r SCRIPT_DIR +# shellcheck source=/dev/null +source "${SCRIPT_DIR}/../lib_init.sh" # Find all -demo.sh files in the demo directory and run them. for demo_script in "${SCRIPT_DIR}"/*-demo.sh; do if [[ -f "${demo_script}" ]]; then echo "Running demo: ${demo_script}" "${demo_script}" - echo + echo "Result of demo: ${demo_script}: ${?}" fi done From 0037850f7259aad2d0119ee697e2db84f079acd4 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 8 Mar 2025 20:51:58 +0100 Subject: [PATCH 4/7] fix(demo): Fix Accidental Diff "Failure" Diff exits with 1 on difference, which would trigger a failure due to errexit. To keep it simple, we just don't add any difference, as the actual diff is not important. Also, simplifying `sed` demo to the original state with less code. --- demo/gnucompat-demo.sh | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/demo/gnucompat-demo.sh b/demo/gnucompat-demo.sh index 088b544..74f34f3 100755 --- a/demo/gnucompat-demo.sh +++ b/demo/gnucompat-demo.sh @@ -64,34 +64,18 @@ function demo_sed() { echo "SED Demo:" local -r input=" Hello, World!" - local result case "${ASSUME_GNU}" in yes | true) local -r sed_script='s/World/GNU/g' # This command will fail if the GNU version of `sed` is not available. - if echo "${input}" | "${SED}" --regexp-extended "${sed_script}"; then - result=$? - else - result=$? - fi + echo "${input}" | "${SED}" --regexp-extended "${sed_script}" ;; *) local -r sed_script='s/World/Non-GNU/g' - if echo "${input}" | "${SED}" -r "${sed_script}"; then - result=$? - else - result=$? - fi + echo "${input}" | "${SED}" -r "${sed_script}" ;; esac - - if [ "${result}" -eq 0 ]; then - echo "Success!" - else - echo "Failure!" - exit 1 - fi } function demo_awk() { @@ -277,20 +261,20 @@ function demo_diff() { echo "DIFF Demo:" local -r input1="Hello, World!" - local -r input2="Hello, Universe!" local -r file1="/tmp/file1.txt" - local -r file2="/tmp/file2.txt" + # We just need one file, as the test is just about the command execution, + # not the actual diff output. This spares us the need to handle different + # exit codes (0 for no difference, 1 for difference, 2 for error). echo "${input1}" >"${file1}" - echo "${input2}" >"${file2}" case "${ASSUME_GNU}" in yes | true) # This command will fail if the GNU version of `diff` is not available. - "${DIFF}" --brief "${file1}" "${file2}" + "${DIFF}" --normal "${file1}" "${file1}" ;; *) - "${DIFF}" "${file1}" "${file2}" + "${DIFF}" "${file1}" "${file1}" ;; esac } From 3f1eda655a37920e9f79dc235aecd60fabf5a6c6 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 8 Mar 2025 21:08:48 +0100 Subject: [PATCH 5/7] fix(github): Trying to Fix Match install_gnu_tools --- .github/workflows/system-tests-demo.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/system-tests-demo.yml b/.github/workflows/system-tests-demo.yml index 2bba6f0..d588885 100644 --- a/.github/workflows/system-tests-demo.yml +++ b/.github/workflows/system-tests-demo.yml @@ -22,7 +22,7 @@ jobs: submodules: recursive - name: Install GNU tools on macOS - if: matrix.os == 'macos-latest' && matrix.install_gnu_tools == 'true' + if: ${{ matrix.os == 'macos-latest' && matrix.install_gnu_tools == 'true' }} run: | bin/gnu-install.sh @@ -32,4 +32,3 @@ jobs: - name: Run all demos run: | demo/all-demos.sh - echo "Success: ${?}" From 60e2b7b4e923cfd0b4263b8694c8f5173fc3e879 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 8 Mar 2025 21:15:30 +0100 Subject: [PATCH 6/7] fix(github): Trying to Fix Match install_gnu_tools --- .github/workflows/system-tests-demo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/system-tests-demo.yml b/.github/workflows/system-tests-demo.yml index d588885..2fc384b 100644 --- a/.github/workflows/system-tests-demo.yml +++ b/.github/workflows/system-tests-demo.yml @@ -22,7 +22,7 @@ jobs: submodules: recursive - name: Install GNU tools on macOS - if: ${{ matrix.os == 'macos-latest' && matrix.install_gnu_tools == 'true' }} + if: ${{ matrix.os == 'macos-latest' && matrix.install_gnu_tools }} run: | bin/gnu-install.sh From b2b0ad97cb4834a76b9aefe0b8053d9a4ea736a8 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 8 Mar 2025 22:34:20 +0100 Subject: [PATCH 7/7] ci(github): Fine-Tune Triggers Also makes the "system-tests" part of the regular QA. --- .github/workflows/bats.yml | 14 +++++++++++++- .github/workflows/shellcheck.yml | 10 +++++++++- .github/workflows/shfmt.yml | 8 +++++++- .github/workflows/system-tests-demo.yml | 12 +++++++++++- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bats.yml b/.github/workflows/bats.yml index 014dfc2..97a9697 100644 --- a/.github/workflows/bats.yml +++ b/.github/workflows/bats.yml @@ -4,8 +4,20 @@ on: push: branches: - main + paths: + - "**/*.sh" + - "tests/**" + - ".gitmodules" + - "!demo/**" + - ".github/workflows/bats.yml" pull_request: - types: [opened, synchronize, reopened, ready_for_review] + types: [ready_for_review, synchronize] + paths: + - "**/*.sh" + - "tests/**" + - ".gitmodules" + - "!demo/**" + - ".github/workflows/bats.yml" workflow_dispatch: permissions: diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 50856ce..9faa96d 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -4,8 +4,16 @@ on: push: branches: - main + paths: + - "**/*.sh" + - ".shellcheckrc" + - ".github/workflows/shellcheck.yml" pull_request: - types: [opened, synchronize, reopened, ready_for_review] + types: [ready_for_review, synchronize] + paths: + - "**/*.sh" + - ".shellcheckrc" + - ".github/workflows/shellcheck.yml" workflow_dispatch: permissions: {} diff --git a/.github/workflows/shfmt.yml b/.github/workflows/shfmt.yml index 0f6b95b..53920fd 100644 --- a/.github/workflows/shfmt.yml +++ b/.github/workflows/shfmt.yml @@ -4,8 +4,14 @@ on: push: branches: - main + paths: + - "**/*.sh" + - ".github/workflows/shfmt.yml" pull_request: - types: [opened, synchronize, reopened, ready_for_review] + types: [ready_for_review, synchronize] + paths: + - "**/*.sh" + - ".github/workflows/shfmt.yml" workflow_dispatch: permissions: {} diff --git a/.github/workflows/system-tests-demo.yml b/.github/workflows/system-tests-demo.yml index 2fc384b..4dde1df 100644 --- a/.github/workflows/system-tests-demo.yml +++ b/.github/workflows/system-tests-demo.yml @@ -1,6 +1,17 @@ name: System Tests Demo on: + push: + branches: + - main + paths: + - "**/*.sh" + - ".github/workflows/system-tests-demo.yml" + pull_request: + types: [ready_for_review, synchronize] + paths: + - "**/*.sh" + - ".github/workflows/system-tests-demo.yml" workflow_dispatch: jobs: @@ -19,7 +30,6 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 1 - submodules: recursive - name: Install GNU tools on macOS if: ${{ matrix.os == 'macos-latest' && matrix.install_gnu_tools }}