Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/actions/check-english-usage/check-english-usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set -euo pipefail
function main() {

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

check=${check:-working-tree-changes}
case $check in
Expand Down Expand Up @@ -115,6 +116,19 @@ function is-arg-true() {
fi
}

# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
function apply-key-value-args() {

for arg in "$@"; do
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
export "$arg"
else
echo "Unknown argument format: $arg (expected key=value)" >&2
exit 126
fi
done
}

# ==============================================================================

is-arg-true "${VERBOSE:-false}" && set -x
Expand Down
44 changes: 42 additions & 2 deletions .github/actions/check-file-format/check-file-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set -euo pipefail
#
# Options:
# check={all,staged-changes,working-tree-changes,branch} # Check mode, default is 'working-tree-changes'
# exclude=file1,file2 # Comma-separated file paths to skip
# dry_run=true # Do not check, run dry run only, default is 'false'
# BRANCH_NAME=other-branch-than-main # Branch to compare with, default is `origin/main`
# FORCE_USE_DOCKER=true # If set to true the command is run in a Docker container, default is 'false'
Expand Down Expand Up @@ -43,6 +44,7 @@ set -euo pipefail
function main() {

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

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

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

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

# Run the selected filter and remove files listed in the optional `exclude` argument.
function get-filtered-files() {

local excludes_csv="${exclude:-}"

if [[ -z "$excludes_csv" ]]; then
$filter
return 0
fi

local excludes=()
IFS=',' read -r -a excludes <<< "$excludes_csv"
Comment thread
jamesthompson26-nhs marked this conversation as resolved.

while IFS= read -r -d '' file; do
local skip=false
for ex in "${excludes[@]}"; do
ex="${ex#${ex%%[![:space:]]*}}"
ex="${ex%${ex##*[![:space:]]}}"
[[ "$file" == "$ex" ]] && skip=true && break
done

[[ "$skip" == false ]] && printf '%s\0' "$file"
done < <($filter)
}

# ==============================================================================

function is-arg-true() {
Expand All @@ -134,6 +161,19 @@ function is-arg-true() {
fi
}

# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
function apply-key-value-args() {

for arg in "$@"; do
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
export "$arg"
else
echo "Unknown argument format: $arg (expected key=value)" >&2
exit 126
fi
done
}

# ==============================================================================

is-arg-true "${VERBOSE:-false}" && set -x
Expand Down
14 changes: 14 additions & 0 deletions .github/actions/check-markdown-format/check-markdown-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set -euo pipefail
function main() {

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

check=${check:-working-tree-changes}
case $check in
Expand Down Expand Up @@ -100,6 +101,19 @@ function is-arg-true() {
fi
}

# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
function apply-key-value-args() {

for arg in "$@"; do
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
export "$arg"
else
echo "Unknown argument format: $arg (expected key=value)" >&2
exit 126
fi
done
}

# ==============================================================================

is-arg-true "${VERBOSE:-false}" && set -x
Expand Down
14 changes: 14 additions & 0 deletions .github/actions/check-todo-usage/check-todos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ function print_output() {

function main() {
cd "$(git rev-parse --show-toplevel)"
apply-key-value-args "$@"

# Load exclusions from config file
load_exclusions_from_config "$CONFIG_FILE"
Expand Down Expand Up @@ -244,6 +245,19 @@ function is-arg-true() {
fi
}

# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
function apply-key-value-args() {

for arg in "$@"; do
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
export "$arg"
else
echo "Unknown argument format: $arg (expected key=value)" >&2
exit 126
fi
done
}

# ==============================================================================

is-arg-true "${VERBOSE:-false}" && set -x
Expand Down
14 changes: 14 additions & 0 deletions .github/actions/scan-secrets/scan-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set -euo pipefail
function main() {

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

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

# Parse arguments passed by pre-commit as KEY=VALUE and expose them as env vars.
function apply-key-value-args() {

for arg in "$@"; do
if [[ "$arg" =~ ^[A-Za-z_][A-Za-z0-9_]*=.+$ ]]; then
export "$arg"
else
echo "Unknown argument format: $arg (expected key=value)" >&2
exit 126
fi
done
}

# ==============================================================================

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