Skip to content

Commit 5330d41

Browse files
CCM-17036: Fix Pre Commit Hook Args
1 parent 4e781d1 commit 5330d41

5 files changed

Lines changed: 98 additions & 2 deletions

File tree

.github/actions/check-english-usage/check-english-usage.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set -euo pipefail
2727
function main() {
2828

2929
cd "$(git rev-parse --show-toplevel)"
30+
apply-key-value-args "$@"
3031

3132
check=${check:-working-tree-changes}
3233
case $check in
@@ -115,6 +116,19 @@ function is-arg-true() {
115116
fi
116117
}
117118

119+
# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
120+
function apply-key-value-args() {
121+
122+
for arg in "$@"; do
123+
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
124+
export "$arg"
125+
else
126+
echo "Unknown argument format: $arg (expected key=value)" >&2
127+
exit 126
128+
fi
129+
done
130+
}
131+
118132
# ==============================================================================
119133

120134
is-arg-true "${VERBOSE:-false}" && set -x

.github/actions/check-file-format/check-file-format.sh

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ set -euo pipefail
1515
#
1616
# Options:
1717
# check={all,staged-changes,working-tree-changes,branch} # Check mode, default is 'working-tree-changes'
18+
# exclude=file1,file2 # Comma-separated file paths to skip
1819
# dry_run=true # Do not check, run dry run only, default is 'false'
1920
# BRANCH_NAME=other-branch-than-main # Branch to compare with, default is `origin/main`
2021
# FORCE_USE_DOCKER=true # If set to true the command is run in a Docker container, default is 'false'
@@ -43,6 +44,7 @@ set -euo pipefail
4344
function main() {
4445

4546
cd "$(git rev-parse --show-toplevel)"
47+
apply-key-value-args "$@"
4648

4749
# shellcheck disable=SC2154
4850
is-arg-true "${dry_run:-false}" && dry_run_opt="--dry-run"
@@ -82,7 +84,7 @@ function run-editorconfig-natively() {
8284
local files=()
8385
while IFS= read -r -d '' file; do
8486
files+=("$file")
85-
done < <($filter)
87+
done < <(get-filtered-files)
8688

8789
# If no files found, exit successfully
8890
[[ ${#files[@]} -eq 0 ]] && return 0
@@ -107,7 +109,7 @@ function run-editorconfig-in-docker() {
107109
local files=()
108110
while IFS= read -r -d '' file; do
109111
files+=("$file")
110-
done < <($filter)
112+
done < <(get-filtered-files)
111113

112114
# We use /dev/null here as a backstop in case there are no files in the state
113115
# we choose. If the filter comes back empty, adding `/dev/null` onto it has
@@ -123,6 +125,31 @@ function run-editorconfig-in-docker() {
123125
ec --exclude '.git/' $dry_run_opt "${files[@]}"
124126
}
125127

128+
# Run the selected filter and remove files listed in the optional `exclude` argument.
129+
function get-filtered-files() {
130+
131+
local excludes_csv="${exclude:-}"
132+
133+
if [[ -z "$excludes_csv" ]]; then
134+
$filter
135+
return 0
136+
fi
137+
138+
local excludes=()
139+
IFS=',' read -r -a excludes <<< "$excludes_csv"
140+
141+
while IFS= read -r -d '' file; do
142+
local skip=false
143+
for ex in "${excludes[@]}"; do
144+
ex="${ex#${ex%%[![:space:]]*}}"
145+
ex="${ex%${ex##*[![:space:]]}}"
146+
[[ "$file" == "$ex" ]] && skip=true && break
147+
done
148+
149+
[[ "$skip" == false ]] && printf '%s\0' "$file"
150+
done < <($filter)
151+
}
152+
126153
# ==============================================================================
127154

128155
function is-arg-true() {
@@ -134,6 +161,19 @@ function is-arg-true() {
134161
fi
135162
}
136163

164+
# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
165+
function apply-key-value-args() {
166+
167+
for arg in "$@"; do
168+
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
169+
export "$arg"
170+
else
171+
echo "Unknown argument format: $arg (expected key=value)" >&2
172+
exit 126
173+
fi
174+
done
175+
}
176+
137177
# ==============================================================================
138178

139179
is-arg-true "${VERBOSE:-false}" && set -x

.github/actions/check-markdown-format/check-markdown-format.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set -euo pipefail
3434
function main() {
3535

3636
cd "$(git rev-parse --show-toplevel)"
37+
apply-key-value-args "$@"
3738

3839
check=${check:-working-tree-changes}
3940
case $check in
@@ -100,6 +101,19 @@ function is-arg-true() {
100101
fi
101102
}
102103

104+
# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
105+
function apply-key-value-args() {
106+
107+
for arg in "$@"; do
108+
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
109+
export "$arg"
110+
else
111+
echo "Unknown argument format: $arg (expected key=value)" >&2
112+
exit 126
113+
fi
114+
done
115+
}
116+
103117
# ==============================================================================
104118

105119
is-arg-true "${VERBOSE:-false}" && set -x

.github/actions/check-todo-usage/check-todos.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ function print_output() {
214214

215215
function main() {
216216
cd "$(git rev-parse --show-toplevel)"
217+
apply-key-value-args "$@"
217218

218219
# Load exclusions from config file
219220
load_exclusions_from_config "$CONFIG_FILE"
@@ -244,6 +245,19 @@ function is-arg-true() {
244245
fi
245246
}
246247

248+
# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
249+
function apply-key-value-args() {
250+
251+
for arg in "$@"; do
252+
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
253+
export "$arg"
254+
else
255+
echo "Unknown argument format: $arg (expected key=value)" >&2
256+
exit 126
257+
fi
258+
done
259+
}
260+
247261
# ==============================================================================
248262

249263
is-arg-true "${VERBOSE:-false}" && set -x

.github/actions/scan-secrets/scan-secrets.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set -euo pipefail
2626
function main() {
2727

2828
cd "$(git rev-parse --show-toplevel)"
29+
apply-key-value-args "$@"
2930

3031
if command -v gitleaks > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
3132
dir="$PWD"
@@ -102,6 +103,19 @@ function is-arg-true() {
102103
fi
103104
}
104105

106+
# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
107+
function apply-key-value-args() {
108+
109+
for arg in "$@"; do
110+
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
111+
export "$arg"
112+
else
113+
echo "Unknown argument format: $arg (expected key=value)" >&2
114+
exit 126
115+
fi
116+
done
117+
}
118+
105119
# ==============================================================================
106120

107121
is-arg-true "${VERBOSE:-false}" && set -x

0 commit comments

Comments
 (0)