From 48233558bf2266da47863c90d830e94fcb628eaa Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Tue, 7 May 2024 13:26:02 +0200 Subject: [PATCH 1/2] add `is_github_actions()` function to check if the current environment is GitHub Actions --- src/functions.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/functions.sh b/src/functions.sh index 28b04cf9..4adb615a 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -299,6 +299,15 @@ is_debug () { return ${result} } +# Function to check if the script is run in GitHub Actions environment +is_github_actions () { + if [[ -z "${GITHUB_ACTIONS}" ]]; then + return 1 + fi + + return 0 +} + # Function to upload the SARIF report to GitHub # Source: https://github.com/github/codeql-action/blob/dbe6f211e66b3aa5e9a5c4731145ed310ed54e28/lib/upload-lib.js#L104-L106 # Parameters: https://github.com/github/codeql-action/blob/69e09909dc219ed3374913e41c167490fc57202a/lib/upload-lib.js#L211-L224 From 5b1f542e268d25375dd29dab2c0f8850625a2e98 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Tue, 7 May 2024 14:04:21 +0200 Subject: [PATCH 2/2] feat: add setup step --- src/functions.sh | 2 ++ src/index.sh | 2 ++ src/setup.sh | 12 ++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 src/setup.sh diff --git a/src/functions.sh b/src/functions.sh index 4adb615a..e8f04297 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -300,6 +300,8 @@ is_debug () { } # Function to check if the script is run in GitHub Actions environment +# GITHUB_ACTIONS is set when Differential ShellCheck is running in GitHub Actions +# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables is_github_actions () { if [[ -z "${GITHUB_ACTIONS}" ]]; then return 1 diff --git a/src/index.sh b/src/index.sh index 7d5db3d6..307f4dfa 100755 --- a/src/index.sh +++ b/src/index.sh @@ -5,6 +5,8 @@ CURRENT_DIR="$(dirname "$(readlink -f "$0")")" # shellcheck source=functions.sh . "${SCRIPT_DIR="${CURRENT_DIR}/"}functions.sh" +# shellcheck source=setup.sh +. "${SCRIPT_DIR=}setup.sh" WORK_DIR="${WORK_DIR-../}" diff --git a/src/setup.sh b/src/setup.sh new file mode 100644 index 00000000..6ce062f3 --- /dev/null +++ b/src/setup.sh @@ -0,0 +1,12 @@ +# shellcheck shell=bash + +# TODO set up required variables + +# Set required variables based on the environment +if is_github_actions; then + is_debug && echo "Running in GitHub Actions" +else + is_debug && \ + echo "Running in non GitHub Actions environment" && \ + echo "Functionality is limited" +fi