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
32 changes: 24 additions & 8 deletions .github/actions/check-english-usage/check-english-usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ function main() {
check=${check:-working-tree-changes}
case $check in
"all")
filter="git ls-files"
filter="git ls-files -z"
;;
"staged-changes")
filter="git diff --diff-filter=ACMRT --name-only --cached"
filter="git diff --diff-filter=ACMRT --name-only --cached -z"
;;
"working-tree-changes")
filter="git diff --diff-filter=ACMRT --name-only"
filter="git diff --diff-filter=ACMRT --name-only -z"
;;
"branch")
filter="git diff --diff-filter=ACMRT --name-only ${BRANCH_NAME:-origin/main}"
filter="git diff --diff-filter=ACMRT --name-only -z ${BRANCH_NAME:-origin/main}"
;;
*)
echo "Unrecognised check mode: $check" >&2 && exit 1
Expand All @@ -59,10 +59,17 @@ function main() {
# filter=[git command to filter the files to check]
function run-vale-natively() {

# shellcheck disable=SC2046
local files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <($filter)

# If no files found, exit successfully
[[ ${#files[@]} -eq 0 ]] && return 0

vale \
--config "$PWD/scripts/config/vale/vale.ini" \
$($filter)
"${files[@]}"
}

# Run Vale in a Docker container.
Expand All @@ -75,17 +82,26 @@ function run-vale-in-docker() {

# shellcheck disable=SC2155
local image=$(name=jdkato/vale docker-get-image-version-and-pull)

local files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <($filter)

# We use /dev/null here to stop `vale` from complaining that it's
# not been called correctly if the $filter happens to return an
# empty list. As long as there's a filename, even if it's one that
# will be ignored, `vale` is happy.
# shellcheck disable=SC2046,SC2086
if [[ ${#files[@]} -eq 0 ]]; then
files=(/dev/null)
fi

docker run --rm --platform linux/amd64 \
--volume "$PWD:/workdir" \
--workdir /workdir \
"$image" \
--config /workdir/scripts/config/vale/vale.ini \
$($filter) /dev/null
"${files[@]}"
}

# ==============================================================================
Expand Down
33 changes: 26 additions & 7 deletions .github/actions/check-file-format/check-file-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ function main() {
check=${check:-working-tree-changes}
case $check in
"all")
filter="git ls-files"
filter="git ls-files -z"
;;
"staged-changes")
filter="git diff --diff-filter=ACMRT --name-only --cached"
filter="git diff --diff-filter=ACMRT --name-only --cached -z"
;;
"working-tree-changes")
filter="git diff --diff-filter=ACMRT --name-only"
filter="git diff --diff-filter=ACMRT --name-only -z"
;;
"branch")
filter="git diff --diff-filter=ACMRT --name-only ${BRANCH_NAME:-origin/main}"
filter="git diff --diff-filter=ACMRT --name-only -z ${BRANCH_NAME:-origin/main}"
;;
*)
echo "Unrecognised check mode: $check" >&2 && exit 1
Expand All @@ -79,9 +79,17 @@ function main() {
# filter=[git command to filter the files to check]
function run-editorconfig-natively() {

# shellcheck disable=SC2046,SC2086
local files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <($filter)

# If no files found, exit successfully
[[ ${#files[@]} -eq 0 ]] && return 0

# shellcheck disable=SC2086
editorconfig \
--exclude '.git/' $dry_run_opt $($filter)
--exclude '.git/' $dry_run_opt "${files[@]}"
}

# Run editorconfig in a Docker container.
Expand All @@ -95,13 +103,24 @@ function run-editorconfig-in-docker() {

# shellcheck disable=SC2155
local image=$(name=mstruebing/editorconfig-checker docker-get-image-version-and-pull)

local files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <($filter)

# 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
# the effect of preventing `ec` from treating "no files" as "all the files".
if [[ ${#files[@]} -eq 0 ]]; then
files=(/dev/null)
fi

# shellcheck disable=SC2086
docker run --rm --platform linux/amd64 \
--volume "$PWD":/check \
"$image" \
sh -c "ec --exclude '.git/' $dry_run_opt \$($filter) /dev/null"
ec --exclude '.git/' $dry_run_opt "${files[@]}"
}

# ==============================================================================
Expand Down
Loading