Skip to content

Commit 3013f69

Browse files
fix: set default directory to current path and normalize input variables in entrypoint (#151)
Co-authored-by: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com>
1 parent 762812f commit 3013f69

4 files changed

Lines changed: 24 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This action supports three tag levels for flexible versioning:
6666
| `diff` | No | `false` | Display diffs of formatting changes. |
6767
| `check` | No | `false` | Check if files are malformatted. |
6868
| `recursive` | No | `true` | Also process files in subdirectories. |
69-
| `dir` | No | `""` | Path to be checked. Current dir as default. |
69+
| `dir` | No | `"."` | Path to be checked. Current dir as default. |
7070

7171

7272
### 📤 Output Parameters

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ inputs:
2929
dir:
3030
description: Path to be checked. Current dir as default.
3131
required: false
32-
default: ""
32+
default: "."
3333
outputs:
3434
files_changed:
3535
description: List of formatted files

entrypoint.sh

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ set -Eeuo pipefail
55
# Return code
66
RET_CODE=0
77

8+
# Normalize inputs with safe defaults
9+
INPUT_LIST="${INPUT_LIST:-false}"
10+
INPUT_WRITE="${INPUT_WRITE:-true}"
11+
INPUT_IGNORE="${INPUT_IGNORE:-}"
12+
INPUT_DIFF="${INPUT_DIFF:-false}"
13+
INPUT_CHECK="${INPUT_CHECK:-false}"
14+
INPUT_RECURSIVE="${INPUT_RECURSIVE:-true}"
15+
INPUT_DIR="${INPUT_DIR:-.}"
16+
817
# Print input variables
918
echo "Inputs:"
1019
echo " list: ${INPUT_LIST}"
@@ -17,42 +26,29 @@ echo " recursive: ${INPUT_RECURSIVE}"
1726
echo " dir: ${INPUT_DIR}"
1827

1928
# Remap input variables as parameters for format-hcl
20-
LIST="-list=${INPUT_LIST}"
21-
WRITE="-write=${INPUT_WRITE}"
29+
ARGS=("-list=${INPUT_LIST}" "-write=${INPUT_WRITE}")
2230

2331
if [[ -n "${INPUT_IGNORE}" ]]; then
24-
IGNORE="-ignore=${INPUT_IGNORE}"
25-
else
26-
IGNORE=""
32+
ARGS+=("-ignore=${INPUT_IGNORE}")
2733
fi
2834

2935
if [[ "${INPUT_DIFF}" == "true" ]]; then
30-
DIFF="-diff"
31-
else
32-
DIFF=""
36+
ARGS+=("-diff")
3337
fi
3438

3539
if [[ "${INPUT_CHECK}" == "true" ]]; then
36-
CHECK="-check"
37-
else
38-
CHECK=""
40+
ARGS+=("-check")
3941
fi
4042

4143
if [[ "${INPUT_RECURSIVE}" == "true" ]]; then
42-
RECURSIVE="-recursive"
43-
else
44-
RECURSIVE=""
44+
ARGS+=("-recursive")
4545
fi
4646

47-
if [[ -n "${INPUT_DIR}" ]]; then
48-
DIR="${INPUT_DIR}"
49-
else
50-
DIR=""
51-
fi
47+
ARGS+=("${INPUT_DIR}")
5248

5349
# Run main action
5450
touch /tmp/time_compare
55-
/usr/bin/format-hcl "${LIST}" "${WRITE}" "${IGNORE}" "${DIFF}" "${CHECK}" "${RECURSIVE}" "${DIR}"
51+
/usr/bin/format-hcl "${ARGS[@]}"
5652
RET_CODE=$?
5753

5854
# List of changed files

tests/docker/local-image.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ commandTests:
1212
- -lc
1313
- command -v bash >/dev/null 2>&1 && command -v terraform >/dev/null 2>&1 && command -v format-hcl >/dev/null 2>&1 && command -v fmt.sh >/dev/null 2>&1 && command -v terragrunt-fmt.sh >/dev/null 2>&1
1414

15+
- name: Entrypoint handles empty dir input
16+
command: bash
17+
args:
18+
- -lc
19+
- INPUT_LIST=false INPUT_WRITE=true INPUT_IGNORE='' INPUT_DIFF=false INPUT_CHECK=false INPUT_RECURSIVE=true INPUT_DIR='' /entrypoint.sh >/tmp/entrypoint.log 2>&1 || (cat /tmp/entrypoint.log && exit 1)
20+
1521
- name: Apt cache cleaned
1622
command: bash
1723
args:

0 commit comments

Comments
 (0)