Skip to content

Commit

Permalink
Merge branch 'develop' into feature/dev-wcoss2
Browse files Browse the repository at this point in the history
* develop:
  Add shell linter Github action for pull requests (NOAA-EMC#1007)
  Build updates for WCOSS2 (NOAA-EMC#1002)
  Update checkout.sh to remove git submodule update for upp checkout (NOAA-EMC#768)
  Add 06, 12, and 18 WCOSS2 operational GFS defs
  Add WCOSS2 operational GFS defs files
  Update repository name for EMC_post component to UPP
  • Loading branch information
KateFriedman-NOAA committed Sep 6, 2022
2 parents 7a23a10 + 4b517b6 commit c11966c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
name: linters
on:
pull_request:

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
with:
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
2 changes: 2 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Global settings for Spellcheck (https://github.com/koalaman/shellcheck)
enable=all
31 changes: 18 additions & 13 deletions ush/preamble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@ 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"}
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() {
Expand All @@ -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}

0 comments on commit c11966c

Please sign in to comment.