Update scripts-testing.yml #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# 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] | |
fail-fast: false | |
name: "${{ matrix.os }}" | |
runs-on: "${{ matrix.os }}" | |
steps: | |
- name: "Checkout sources" | |
uses: actions/checkout@v4 | |
- name: "Test scripts" | |
shell: bash | |
run: | | |
# Testing scripts... | |
EXIT_CODE='0' | |
SKIP_BASH='false' | |
if diff 1> /dev/null 2>&1 -- "$(command -v 'sh' || :)" "$(command -v 'bash' || :)"; then SKIP_BASH='true'; fi | |
# shellcheck disable=SC2016 # Intended: Expressions don't expand in single quotes | |
{ | |
readonly current_os='${{ matrix.os }}' | |
readonly workspace_dir='${{ github.workspace }}' | |
} | |
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 | |
printf '%s\n' '---' | |
sudo apt-get -y -qq install 'bosh' || echo $? | |
printf '%s\n' '---' | |
bosh --help || echo $? | |
printf '%s\n' '---' | |
#pkg install bosh || echo $? | |
printf '%s\n' '---' | |
# | |
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 "${SKIP_BASH:?}" = 'true' && test "${2:?}" = 'bash'; then return 0; fi | |
if test "${1:?}" = 'cmdline.sh'; then | |
case "${2:?}" in | |
sh | busybox | dash | 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 bash busybox dash 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:?}" |