Skip to content

Update scripts-testing.yml #28

Update scripts-testing.yml

Update scripts-testing.yml #28

---
# 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
name: "${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
steps:
- name: "Checkout sources"
uses: actions/checkout@v4
- name: "Test scripts"
shell: bash
run: |
# Testing scripts...
# shellcheck disable=SC2016 # Intended: Expressions don't expand in single quotes
readonly current_os='${{ matrix.os }}'; readonly workspace_dir='${{ github.workspace }}'
if test "${current_os?}" = 'macos-latest'; then brew 1> /dev/null install --quiet oils-for-unix; 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 "${1:?}" = 'cmdline.sh'; then
case "${2:?}" in
'sh' | 'dash' | 'zsh') return 0 ;;
*) ;;
esac
fi
return 1
}
test_on_all_shells()
{
local _shell
EXECUTED_LIST=''
for _shell in sh bash dash ksh zsh osh; do
if skip "${1:?}" "${_shell:?}" || ! _shell="$(command -v "${_shell:?}")" || ! not_already_excuted "${_shell:?}"; then continue; fi
printf 'SHELL: %s - SCRIPT: %s\n\n' "${_shell:?}" "${1:?}"
"${_shell:?}" "${workspace_dir:?}/${1:?}"
printf '\nRETURN CODE:%s\n\n' "${?}"
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