From a8b164f5b36853dd71b22ef6789eb25fff47e444 Mon Sep 17 00:00:00 2001 From: "Walter.Kolczynski" Date: Wed, 27 Jul 2022 20:30:07 +0000 Subject: [PATCH 1/5] Adds shellint GitHub action --- .github/workflows/linters.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/linters.yaml diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml new file mode 100644 index 0000000000..7fb03bc928 --- /dev/null +++ b/.github/workflows/linters.yaml @@ -0,0 +1,17 @@ +name: linters +on: + pull_request: + types: [opened, reopened, edited] +defaults: + run: + shell: bash -o pipefail {0} +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Run Shellcheck + uses: azohra/shell-linter@latest + with: + exclude-paths: "sorc/*.fd" From 278e6d13345e85e93fb48ed0f5e548f55a020fee Mon Sep 17 00:00:00 2001 From: "Walter.Kolczynski" Date: Tue, 30 Aug 2022 23:19:09 +0000 Subject: [PATCH 2/5] Update shell linter to diff linter Updates the github action to use a differential linter that will annotate PRs with the warnings and errors. Also restricts the scan to just the preamble file for now, to prevent a crippling number of errors from being displayed. Refs: #397 --- .github/workflows/linters.yaml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 7fb03bc928..c4ef5c5f46 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -1,17 +1,32 @@ +# name: linters on: pull_request: types: [opened, reopened, edited] + +permissions: + contents: read + defaults: run: shell: bash -o pipefail {0} + jobs: lint: runs-on: ubuntu-latest + + permissions: + security-events: write + pull-requests: write + steps: - name: Checkout code uses: actions/checkout@v1 - - name: Run Shellcheck - uses: azohra/shell-linter@latest with: - exclude-paths: "sorc/*.fd" + fetch-depth: 0 + + - name: Lint shell scripts + uses: redhat-plumbers-in-action/differential-shellcheck@latest + with: + token: ${{ secrets.GITHUB_TOKEN }} + shell-scripts: ush/preamble.sh From e0de360fb07271f9b5b327dc7f8ef3afb24f7062 Mon Sep 17 00:00:00 2001 From: "Walter.Kolczynski" Date: Tue, 30 Aug 2022 23:44:40 +0000 Subject: [PATCH 3/5] Add shellcheck settings file Refs: #397 --- .shellcheckrc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .shellcheckrc diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000000..1c80a97072 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,2 @@ +# Global settings for Spellcheck (https://github.com/koalaman/shellcheck) +enable=all From f8cb9ab1c1b9e0fd4b28eb4e49dfe63831df4e22 Mon Sep 17 00:00:00 2001 From: "Walter.Kolczynski" Date: Tue, 30 Aug 2022 23:48:13 +0000 Subject: [PATCH 4/5] Run linter on all PR activity Refs: #397 --- .github/workflows/linters.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index c4ef5c5f46..61b8a23229 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -2,7 +2,6 @@ name: linters on: pull_request: - types: [opened, reopened, edited] permissions: contents: read From ee1676df85f1740b7068f56f6ca7e6ff14841d6c Mon Sep 17 00:00:00 2001 From: "Walter.Kolczynski" Date: Wed, 31 Aug 2022 00:00:15 +0000 Subject: [PATCH 5/5] Make preamble comply with g-style Refs: #397 --- ush/preamble.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ush/preamble.sh b/ush/preamble.sh index 3effebb41f..dbd5f69004 100644 --- a/ush/preamble.sh +++ b/ush/preamble.sh @@ -29,10 +29,11 @@ fi start_time=$(date +%s) # Get the base name of the calling script -_calling_script=$(basename ${BASH_SOURCE[1]}) +_calling_script=$(basename "${BASH_SOURCE[1]}") # Announce the script has begun -echo "Begin ${_calling_script} at $(date -u)" +start_time_human=$(date -d"@${start_time}" -u) +echo "Begin ${_calling_script} at ${start_time_human}" # Stage our variables export STRICT=${STRICT:-"YES"} @@ -40,14 +41,14 @@ export TRACE=${TRACE:-"YES"} export ERR_EXIT_ON="" export TRACE_ON="" -if [[ $STRICT == "YES" ]]; then +if [[ ${STRICT} == "YES" ]]; then # Exit on error and undefined variable export ERR_EXIT_ON="set -eu" fi -if [[ $TRACE == "YES" ]]; then +if [[ ${TRACE} == "YES" ]]; then export TRACE_ON="set -x" # Print the script name and line number of each command as it is executed - export PS4='+ $(basename $BASH_SOURCE)[$LINENO]'"$id: " + export PS4='+ $(basename ${BASH_SOURCE})[${LINENO}]'"${id}: " fi postamble() { @@ -64,23 +65,27 @@ postamble() { # set +x - script=${1} - start_time=${2} - rc=${3} + script="${1}" + start_time="${2}" + rc="${3}" # Calculate the elapsed time end_time=$(date +%s) + end_time_human=$(date -d@"${end_time}" -u +%H:%M:%S) elapsed_sec=$((end_time - start_time)) - elapsed=$(date -d@${elapsed_sec} -u +%H:%M:%S) + elapsed=$(date -d@"${elapsed_sec}" -u +%H:%M:%S) # Announce the script has ended, then pass the error code up - echo "End ${script} at $(date -u) with error code ${rc:-0} (time elapsed: ${elapsed})" - exit ${rc} + echo "End ${script} at ${end_time_human} with error code ${rc:-0} (time elapsed: ${elapsed})" + exit "${rc}" } # Place the postamble in a trap so it is always called no matter how the script exits +# Shellcheck: Turn off warning about substitions at runtime instead of signal time +# shellcheck disable=SC2064 trap "postamble ${_calling_script} ${start_time} \$?" EXIT +# shellcheck disable= # Turn on our settings -$ERR_EXIT_ON -$TRACE_ON +${ERR_EXIT_ON} +${TRACE_ON}