Update bits-info.sh #208
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, 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: "Cache shells" | |
if: "${{ runner.os == 'Linux' }}" | |
uses: actions/cache@v4 | |
with: | |
path: "cache/shells" | |
key: "${{ runner.os }}-shells" | |
- name: "Prepare shells" | |
shell: bash | |
run: | | |
# Preparing shells... | |
# shellcheck disable=SC2016 # Intended: Expressions don't expand in single quotes | |
{ | |
readonly current_os='${{ runner.os }}' | |
readonly shells_dir='${{ github.workspace }}/cache/shells' | |
} | |
prepare_shell() | |
{ | |
if test ! -s "${shells_dir:?}/${1:?}.${2:?}"; then | |
printf '%s\n' "Downloading '${1?}'..." | |
mkdir -p -- "${shells_dir:?}" || return "${?}" | |
if wget -q -O "${shells_dir:?}/${1:?}.${2:?}" -- "${3:?}" && test -s "${shells_dir:?}/${1:?}.${2:?}"; then | |
: # OK | |
else | |
rm -f -- "${shells_dir:?}/${1:?}.${2:?}" || : | |
return 1 | |
fi | |
fi | |
mkdir -p -- "${shells_dir:?}/extracted/${1?}" || return "${?}" | |
tar -x -f "${shells_dir:?}/${1:?}.${2:?}" -C "${shells_dir:?}/extracted/${1:?}" || return "${?}" | |
} | |
if test "${current_os:?}" = 'Linux'; then | |
prepare_shell 'bosh' 'tar.xz' 'http://fuz.su/pub/schilytools/bin/schily-2024-03-21-x86_64-linux-gcc.tar.xz' || exit "${?}" | |
fi | |
- name: "Test scripts" | |
shell: bash | |
run: | | |
# Testing scripts... | |
EXIT_CODE='0' | |
SH_IS_BASH='false' | |
ORIGINAL_KSH="$(command -v 'ksh' || :)" | |
# shellcheck disable=SC2016 # Intended: Expressions don't expand in single quotes | |
{ | |
readonly current_os='${{ runner.os }}' | |
readonly workspace_dir='${{ github.workspace }}' | |
} | |
if test "${current_os:?}" = 'Linux'; then PATH="${PATH:-/usr/bin}:${workspace_dir:?}/cache/shells/extracted/bosh/opt/schily/bin" || exit "${?}"; fi | |
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' 'ksh93' 'yash'; fi | |
if command 1> /dev/null -v 'choco'; then choco 1> /dev/null install 'busybox' -y --no-progress; fi | |
# | |
resolve_base() | |
{ | |
local _rb_shell | |
_rb_shell="$(command -v "${1:?}")" || return "${?}" | |
_rb_shell="$(realpath "${_rb_shell:?}")" || return "${?}" | |
basename "${_rb_shell:?}" || return "${?}" | |
} | |
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() | |
{ | |
local _s_shell | |
_s_shell='' | |
if test "${SH_IS_BASH:?}" = 'true'; then | |
case "${2:?}" in | |
bash) return 0 ;; # Skip | |
sh) _s_shell='bash' ;; # Evaluate as bash | |
*) ;; | |
esac | |
fi | |
if test -n "${_s_shell?}"; then | |
: | |
elif test "${2:?}" = 'ksh93' || test "${2:?}" = 'osh' || test "${2:?}" = 'bosh'; then | |
_s_shell="${2:?}" | |
else | |
_s_shell="$(resolve_base "${2:?}")" || _s_shell="${2:?}" | |
fi | |
if test "${1:?}" = 'cmdline.sh'; then | |
case "${_s_shell?}" in | |
#ksh) return 0 ;; # Skip | |
obosh) return 0 ;; # Skip | |
*) ;; | |
esac | |
fi | |
return 1 # Execute | |
} | |
test_on_all_shells() | |
{ | |
local _shell _shell_cmd _status | |
EXECUTED_LIST='' | |
for _shell in sh dash bash busybox ash hush mksh ksh93 ksh zsh yash posh osh bosh pbosh obosh; do | |
if test "${_shell:?}" = 'ksh' && test -n "${ORIGINAL_KSH?}"; then _shell="${ORIGINAL_KSH:?}"; fi | |
if ! _shell_cmd="$(command -v "${_shell:?}")" || skip "${1:?}" "${_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:?}" | |
- name: "Clean extracted files" | |
if: "always()" | |
shell: bash | |
run: | | |
# Cleaning extracted files... | |
readonly shells_dir='${{ github.workspace }}/cache/shells' | |
rm -f -r -- "${shells_dir:?}/extracted" || exit $? |