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 e66e682..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,10 +30,9 @@ 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 == 'true' + if: ${{ matrix.os == 'macos-latest' && matrix.install_gnu_tools }} run: | bin/gnu-install.sh @@ -30,4 +40,5 @@ 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 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 diff --git a/demo/gnucompat-demo.sh b/demo/gnucompat-demo.sh index 79ffe6f..74f34f3 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 ;; @@ -261,25 +261,26 @@ 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) + 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 } function demo_all() { + echo "Running all demos, assuming GNU available: ${ASSUME_GNU}." demo_sed demo_awk demo_grep