Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/bats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/shfmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/system-tests-demo.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -19,15 +30,15 @@ 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

- name: Set ASSUME_GNU environment variable
run: echo "ASSUME_GNU=${{ matrix.install_gnu_tools }}" >> $GITHUB_ENV

- name: Run all demos
run: demo/all-demos.sh
run: |
demo/all-demos.sh
4 changes: 3 additions & 1 deletion demo/all-demos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 19 additions & 18 deletions demo/gnucompat-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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.
Expand All @@ -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}"
Expand All @@ -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
;;
Expand All @@ -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
;;
Expand All @@ -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
;;
Expand All @@ -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
;;
Expand All @@ -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
;;
Expand All @@ -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
;;
Expand All @@ -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 ' '
;;
Expand All @@ -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
;;
Expand All @@ -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
;;
Expand All @@ -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
Expand Down