Skip to content

Update scripts-testing.yml #105

Update scripts-testing.yml

Update scripts-testing.yml #105

---
# 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: [macos-latest]
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'
# 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' 'yash'; fi
if command 1> /dev/null -v 'choco'; then choco 1> /dev/null install 'busybox' -y --no-progress; fi
echo '---'
command -v ksh || echo $?
brew 1> /dev/null install --quiet --HEAD 'ksh93'
echo '---'
command -v ksh || echo $?
command -v ksh93 || echo $?
echo '---'
brew 2> /dev/null info 'ksh' | head -n 1 && echo " - 1" || echo " - $?"
brew 2> /dev/null info 'ksh93' | head -n 1 && echo " - 1" || echo " - $?"
brew 2> /dev/null info 'ksh93' | head -n 1 | grep -m 1 -F -e 'ksh93' | cut -d ':' -f '2-' -s && echo " - 1" || echo " - $?"
echo '---'
#
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
if test "${SH_IS_BASH:?}" = 'true'; then
case "${2:?}" in
bash) return 0 ;; # Skip
sh) return 1 ;; # Execute
*) ;;
esac
fi
if test "${2?}" = 'osh' || test "${2?}" = 'bosh'; then
_s_shell="${2?}"
else
_s_shell="$(basename "${3:?}")" || _s_shell="${3?}"
fi
if test "${1:?}" = 'cmdline.sh'; then
case "${_s_shell?}" in
sh | dash | busybox | mksh | zsh | bosh | pbosh | yash | posh) 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 mksh ksh zsh yash posh osh bosh hush; do
if ! _shell_cmd="$(command -v "${_shell:?}")" || skip "${1:?}" "${_shell:?}" "$(realpath ${_shell_cmd:?} || :)" || ! 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 $?