Skip to content

Update scripts-testing.yml #83

Update scripts-testing.yml

Update scripts-testing.yml #83

---
# SPDX-FileCopyrightText: (c) 2024 ale5000
# SPDX-License-Identifier: GPL-3.0-or-later
name: "Scripts testing"
permissions: {}
on:
push:
paths:
- ".github/workflows/scripts-testing.yml"
- "tools/*.sh"
- "includes/*.sh"
- "cmdline.sh"
pull_request:
paths:
- ".github/workflows/scripts-testing.yml"
- "tools/*.sh"
- "includes/*.sh"
- "cmdline.sh"
workflow_dispatch:
jobs:
base:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
fail-fast: false
name: "${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
steps:
- name: "Checkout sources"
uses: actions/checkout@v4
- name: "abc"
shell: bash
run: |
echo '---'
echo "$PATH"
echo '---'
rm -f "${GITHUB_PATH:?}"
printf '%s\n' "${PATH?}:/abc" 1> "${GITHUB_PATH:?}"
echo '---'
- name: "Test scripts"
shell: bash
run: |
# Testing scripts...
echo "$PATH"
EXIT_CODE='0'
SH_IS_BASH='false'
# shellcheck disable=SC2016 # Intended: Expressions don't expand in single quotes
{
readonly current_os='${{ matrix.os }}'
readonly workspace_dir='${{ github.workspace }}'
}
if diff 1> /dev/null 2>&1 -- "$(command -v 'sh' || :)" "$(command -v 'bash' || :)"; then SH_IS_BASH='true'; fi
if command 1> /dev/null -v 'apt-get'; then sudo apt-get -y -qq install 'mksh' 'yash' 'posh' 1> /dev/null; fi
if command 1> /dev/null -v 'brew'; then brew 1> /dev/null install --quiet 'oils-for-unix' 'mksh' 'yash'; fi
if command 1> /dev/null -v 'choco'; then choco 1> /dev/null install 'busybox' -y --no-progress; fi
#
not_already_excuted()
{
local _shell
_shell="$(realpath "${1:?}")" || return 2
case "${EXECUTED_LIST?}|" in
*"|${_shell:?}|"*) return 1 ;; # Already executed
*) ;;
esac
EXECUTED_LIST="${EXECUTED_LIST?}|${_shell:?}"
return 0 # NOT already executed
}
skip()
{
if test "${SH_IS_BASH:?}" = 'true'; then
case "${2:?}" in
bash) return 0 ;;
sh) return 1 ;;
*) ;;
esac
fi
if test "${1:?}" = 'cmdline.sh'; then
case "${2:?}" in
sh | dash | busybox | ksh | mksh | zsh | yash | posh) return 0 ;;
*) ;;
esac
fi
return 1
}
test_on_all_shells()
{
local _shell _shell_cmd _status
EXECUTED_LIST=''
for _shell in sh dash bash busybox ksh mksh zsh osh bosh yash posh hush; do
if skip "${1:?}" "${_shell:?}" || ! _shell_cmd="$(command -v "${_shell:?}")" || ! not_already_excuted "${_shell_cmd:?}"; then continue; fi
printf 'SHELL: %s - SCRIPT: %s\n\n' "${_shell_cmd:?}" "${1:?}"
_status='0'
if test "${_shell:?}" = 'busybox'; then
"${_shell_cmd:?}" ash "${workspace_dir:?}/${1:?}" || _status="${?}"
else
"${_shell_cmd:?}" "${workspace_dir:?}/${1:?}" || _status="${?}"
fi
test "${_status:?}" = 0 || EXIT_CODE="${_status:?}"
printf '\nRETURN CODE:%s\n\n' "${_status:?}"
done
}
export ONLY_FOR_TESTING='true'
for _script in 'tools/bits-info.sh' 'cmdline.sh'; do
test_on_all_shells "${_script:?}"
printf '%s\n' "---"
done
exit "${EXIT_CODE:?}"