From d2559f7876f40f72ce28ce4a988e55b6650ed97d Mon Sep 17 00:00:00 2001 From: Andy Sadler Date: Wed, 4 Oct 2023 15:56:28 -0500 Subject: [PATCH] ci: add shellcheck differential checks Enables linting the various shell scripts using shellcheck. Signed-off-by: Andy Sadler --- .github/workflows/pr-checks.yaml | 4 ++++ run_tests.sh | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index d335841..cb38618 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -82,6 +82,10 @@ jobs: architecture: "x64" - name: Checkout code uses: actions/checkout@v4 + - name: Shellcheck + uses: redhat-plumbers-in-action/differential-shellcheck@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} - name: Run linting checks run: | ./setup.sh diff --git a/run_tests.sh b/run_tests.sh index d078e49..23740b8 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,50 +1,53 @@ -#!/usr/bin/env bash +#!/bin/bash + +set -o pipefail usage() { echo "$0 usage:" - grep " .)\ #" $0 | sed -e "s/^\s\+\([a-z]\).*)\ # \(.*\)$/\t-\1: \2/g" + grep " .)\ #" "$0" | sed -e "s/^\s\+\([a-z]\).*)\ # \(.*\)$/\t-\1: \2/g" exit 0 } while getopts ":j:n:h" arg; do - case $arg in + case ${arg} in j) # set number of jobs to use to run tests (may cause test instability!) jobs=${OPTARG} ;; n) # set the namespace to run tests in - TEST_NAMESPACE=${OPTARG} + TEST_NAMESPACE="${OPTARG}" ;; h) # display help usage - exit 0 + ;; + *) + usage ;; esac done OUTPUT_DIR=test-output -if [ -f test-tmp-dir ]; then - OUTPUT_DIR=$(cat test-tmp-dir) +if [[ -f test-tmp-dir ]]; then + OUTPUT_DIR="$(cat test-tmp-dir)" fi -[ -d "${OUTPUT_DIR}" ] || mkdir -p "${OUTPUT_DIR}" +[[ -d "${OUTPUT_DIR}" ]] || mkdir -p "${OUTPUT_DIR}" PYTHON_VENV_DIR="${OUTPUT_DIR}/venv" mkdir -p "${OUTPUT_DIR}" -if [ -z $TEST_NAMESPACE ]; then +if [[ -z "${TEST_NAMESPACE}" ]]; then TEST_NAMESPACE="servicebindings-cts" fi TEST_ACCEPTANCE_OUTPUT_DIR="${OUTPUT_DIR}"/results -if [ $(kubectl get namespace ${TEST_NAMESPACE} > /dev/null; echo $?) -eq '0' ]; then - kubectl delete namespace ${TEST_NAMESPACE} -fi +# shellcheck disable=SC2261 +kubectl get namespace "${TEST_NAMESPACE}" 2&>/dev/null > /dev/null || kubectl delete namespace "${TEST_NAMESPACE}" -if [ -z $jobs ]; then +if [[ -z "${jobs}" ]]; then jobs=1 fi echo "Running acceptance tests" -FEATURES_PATH=features TEST_NAMESPACE=${TEST_NAMESPACE} "${PYTHON_VENV_DIR}/bin/behavex" -o ${TEST_ACCEPTANCE_OUTPUT_DIR} --capture --capture-stderr --parallel-processes ${jobs} --parallel-scheme scenario +FEATURES_PATH=features TEST_NAMESPACE="${TEST_NAMESPACE}" "${PYTHON_VENV_DIR}/bin/behavex" -o "${TEST_ACCEPTANCE_OUTPUT_DIR}" --capture --capture-stderr --parallel-processes "${jobs}" --parallel-scheme scenario