Skip to content

Commit 8af96b9

Browse files
committed
Add shellcheck
1 parent 4aab0e7 commit 8af96b9

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ jobs:
131131
with:
132132
dockerfile: ./image/Dockerfile
133133

134-
- name: Lint Dockerfile
134+
- name: Lint Dockerfile-base
135135
uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
136136
with:
137137
dockerfile: ./image/Dockerfile-base
138+
139+
- name: Run ShellCheck
140+
run: |
141+
cd image/entrypoints
142+
shellcheck ../actions.sh ../workflow_commands.sh *.sh --enable add-default-case,avoid-nullary-conditional,require-double-brackets,deprecate-which

image/actions.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function repair_environment() {
1818
# HOME doesn't exist... is it near GITHUB_EVENT_PATH?
1919

2020
local ACTUAL_HOME
21-
ACTUAL_HOME=$(realpath "$(dirname $GITHUB_EVENT_PATH)/../_github_home")
21+
ACTUAL_HOME=$(realpath "$(dirname "$GITHUB_EVENT_PATH")/../_github_home")
2222

2323
if [[ -d "$ACTUAL_HOME" ]]; then
2424
HOME="$ACTUAL_HOME"
@@ -42,7 +42,7 @@ function debug() {
4242

4343
function detect-terraform-version() {
4444
TERRAFORM_BIN_CACHE_DIR="/var/terraform:$JOB_TMP_DIR/terraform-bin-dir" TERRAFORM_BIN_CHECKSUM_DIR="/var/terraform" terraform-version
45-
debug_cmd ls -la "$(which terraform)"
45+
debug_cmd ls -la "$(command -v terraform)"
4646

4747
local TF_VERSION
4848
TF_VERSION=$(terraform version -json | jq -r '.terraform_version' 2>/dev/null || terraform version | grep 'Terraform v' | sed 's/Terraform v//')
@@ -140,7 +140,8 @@ function setup() {
140140

141141
detect-terraform-version
142142

143-
readonly TERRAFORM_BACKEND_TYPE=$(terraform-backend)
143+
TERRAFORM_BACKEND_TYPE=$(terraform-backend)
144+
readonly TERRAFORM_BACKEND_TYPE
144145
if [[ "$TERRAFORM_BACKEND_TYPE" != "" ]]; then
145146
echo "Detected $TERRAFORM_BACKEND_TYPE backend"
146147
fi
@@ -170,7 +171,7 @@ function init() {
170171
start_group "Initializing $TOOL_PRODUCT_NAME"
171172

172173
rm -rf "$TF_DATA_DIR"
173-
debug_log $TOOL_COMMAND_NAME init -input=false -backend=false
174+
debug_log "$TOOL_COMMAND_NAME" init -input=false -backend=false
174175
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME init -input=false -backend=false)
175176

176177
end_group
@@ -186,10 +187,10 @@ function init-test() {
186187
rm -rf "$TF_DATA_DIR"
187188

188189
if [[ -n "$INPUT_TEST_DIRECTORY" ]]; then
189-
debug_log $TOOL_COMMAND_NAME init -input=false -backend=false -test-directory "$INPUT_TEST_DIRECTORY"
190-
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME init -input=false -backend=false -test-directory $INPUT_TEST_DIRECTORY)
190+
debug_log "$TOOL_COMMAND_NAME" init -input=false -backend=false -test-directory "$INPUT_TEST_DIRECTORY"
191+
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME init -input=false -backend=false -test-directory "$INPUT_TEST_DIRECTORY")
191192
else
192-
debug_log $TOOL_COMMAND_NAME init -input=false -backend=false
193+
debug_log "$TOOL_COMMAND_NAME" init -input=false -backend=false
193194
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME init -input=false -backend=false)
194195
fi
195196

@@ -231,7 +232,8 @@ function init-backend-workspace() {
231232

232233
rm -rf "$TF_DATA_DIR"
233234

234-
debug_log TF_WORKSPACE=$INPUT_WORKSPACE $TOOL_COMMAND_NAME init -input=false '$INIT_ARGS' # don't expand INIT_ARGS
235+
# shellcheck disable=SC2016
236+
debug_log TF_WORKSPACE="$INPUT_WORKSPACE" "$TOOL_COMMAND_NAME" init -input=false '$INIT_ARGS' # don't expand INIT_ARGS
235237

236238
set +e
237239
# shellcheck disable=SC2086
@@ -271,7 +273,8 @@ function init-backend-default-workspace() {
271273

272274
rm -rf "$TF_DATA_DIR"
273275

274-
debug_log $TOOL_COMMAND_NAME init -input=false '$INIT_ARGS' # don't expand INIT_ARGS
276+
# shellcheck disable=SC2016
277+
debug_log "$TOOL_COMMAND_NAME" init -input=false '$INIT_ARGS' # don't expand INIT_ARGS
275278
set +e
276279
# shellcheck disable=SC2086
277280
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME init -input=false $INIT_ARGS \
@@ -299,7 +302,7 @@ function init-backend-default-workspace() {
299302
function select-workspace() {
300303
local WORKSPACE_EXIT
301304

302-
debug_log $TOOL_COMMAND_NAME workspace select "$INPUT_WORKSPACE"
305+
debug_log "$TOOL_COMMAND_NAME" workspace select "$INPUT_WORKSPACE"
303306
set +e
304307
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME workspace select "$INPUT_WORKSPACE") >"$STEP_TMP_DIR/workspace_select" 2>&1
305308
WORKSPACE_EXIT=$?
@@ -429,7 +432,7 @@ function set-remote-plan-args() {
429432
}
430433

431434
function output() {
432-
debug_log $TOOL_COMMAND_NAME output -json
435+
debug_log "$TOOL_COMMAND_NAME" output -json
433436
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME output -json | tee "$STEP_TMP_DIR/terraform_output.json" | convert_output)
434437
}
435438

@@ -526,8 +529,8 @@ function destroy() {
526529

527530
function force_unlock() {
528531
echo "Unlocking state with ID: $INPUT_LOCK_ID"
529-
debug_log $TOOL_COMMAND_NAME force-unlock -force $INPUT_LOCK_ID
530-
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME force-unlock -force $INPUT_LOCK_ID)
532+
debug_log "$TOOL_COMMAND_NAME" force-unlock -force "$INPUT_LOCK_ID"
533+
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME force-unlock -force "$INPUT_LOCK_ID")
531534
}
532535

533536
# Every file written to disk should use one of these directories

image/entrypoints/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function set-test-args() {
3434

3535
function test() {
3636

37-
debug_log $TOOL_COMMAND_NAME test -no-color $TEST_ARGS $VARIABLE_ARGS
37+
debug_log $TOOL_COMMAND_NAME test -no-color "$TEST_ARGS" "$VARIABLE_ARGS"
3838

3939
set +e
4040
# shellcheck disable=SC2086

0 commit comments

Comments
 (0)