Skip to content

Mark codebase version as unstable for upcoming changes #10

Mark codebase version as unstable for upcoming changes

Mark codebase version as unstable for upcoming changes #10

name: actions_on_github_servers
on:
# trigger the workflow upon request
workflow_dispatch:
# trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
jobs:
run_tests:
# we use jobs in a matrix
# the OS to be used for the test is taken from the current matrix element
runs-on: ${{ matrix.os }}
strategy:
# we want to avoid to stop all the tests the first time that one of them gets an error
fail-fast: false
matrix:
include:
#here we set up the various matrix elements
#the entries in each matrix element are just variables, not keywords, with (hopefully) self-explaining names
# 1st matrix element, current LTS Ubuntu distribution, default bash version
- os: ubuntu-22.04
bash_version: "default"
# 2st matrix element, current LTS Ubuntu distribution, bash 4.4
- os: ubuntu-22.04
bash_version: "bash-4.4"
steps:
# this is an action provided by GitHub to checkout the repository
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
cache: false
# taken from https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
# pick the latest minor release of Python 3
python-version: '3.x'
# print the picked Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
# this Action should follow steps to set up Python build environment
- name: Install codebase Python dependencies
uses: py-actions/py-dependency-install@v4
with:
path: "python/requirements.txt"
- name: Install further Python dependencies for tests
uses: py-actions/py-dependency-install@v4
with:
path: "tests/python_requirements.txt"
# now everything should be ready to setup bash and run codebase tests
- name: code_check
# we set some environment variables which depend on the specific matrix element
env:
OS_NAME: ${{ matrix.os }}
BASH_TESTED_VERSION: ${{matrix.bash_version}}
# we run the step
# we recall that in YAML the pipe symbol "|" means that the following lines, including newlines, are interpreted literally
run: |
# we save in a variable the path of the starting directory
export main_dir="${PWD}"
# we install the formatter
export PATH="${PATH}:$(go env GOPATH)/bin"
go install mvdan.cc/sh/v3/cmd/shfmt@latest
printf "\n$(pwd)\nInstalled shfmt at $(which shfmt): $(shfmt --version)\n\n"
# if we are not using the default bash version, we download and compile the desired one
if [ ${BASH_TESTED_VERSION} != "default" ]; then
cd ${HOME}
printf "Download and compile bash-${BASH_TESTED_VERSION} into ${HOME}...\n"
wget -nv https://ftp.gnu.org/gnu/bash/${BASH_TESTED_VERSION}.tar.gz
tar xf ${BASH_TESTED_VERSION}.tar.gz
output_file=configure_make.log
cd ${BASH_TESTED_VERSION}
./configure > "${output_file}" 2>&1 || { cat "${output_file}"; exit 1; }
make -j$(nproc) > "${output_file}" 2>&1 || { cat "${output_file}"; exit 1; }
BASH_EXE=$(pwd)/bash
# now we install yq in the minimum version supported by the handler (otherwise a more recent version is available in GitHub actions)
printf "Download yq-v4.24.2...\n"
wget -nv -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.24.2/yq_linux_amd64
chmod +x /usr/local/bin/yq
else
BASH_EXE=$(which bash)
fi
# we print the bash version to check that we used the desired one
printf "\n$(${BASH_EXE} --version)\n"
# we set the TERM environment variable (used by utilities exploited in the tests)
export TERM="xterm"
# now we enter into the tests directory and execute the tests with maximum detail (-r 3)
cd ${main_dir}/tests
${BASH_EXE} tests_runner unit -r 3 -k ||\
{ printf "\nDetailed output of unit tests for debugging purposes:\n"; cat run_tests/tests_runner.log; exit 1; }
rm -rf run_tests
${BASH_EXE} tests_runner functional -r 3 -k ||\
{ printf "\nDetailed output of functional tests for debugging purposes:\n"; cat run_tests/tests_runner.log; exit 1; }