Skip to content

Commit 2949ddd

Browse files
authored
parametrise swift format binary (#285)
It can be useful to be able to control which binary is used for the formatting soundness checks. This is particularly useful if someone wanted to use this script locally to reproduce the formatting check before committing and where they may have more than one binary available.
1 parent c8aaa3d commit 2949ddd

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

.github/workflows/scripts/check-swift-format.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@ log() { printf -- "** %s\n" "$*" >&2; }
1717
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
1818
fatal() { error "$@"; exit 1; }
1919

20+
SWIFT_FORMAT_BIN="${SWIFT_FORMAT_BIN:-$(which swift-format 2> /dev/null)}"; test -n "$SWIFT_FORMAT_BIN" || fatal "SWIFT_FORMAT_BIN unset and no swift-format on PATH"
21+
2022

2123
if [[ -f .swiftformatignore ]]; then
2224
log "Found swiftformatignore file..."
2325

2426
log "Running swift-format format..."
25-
tr '\n' '\0' < .swiftformatignore| xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 swift-format format --parallel --in-place
27+
tr '\n' '\0' < .swiftformatignore| xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 "$SWIFT_FORMAT_BIN" format --parallel --in-place
2628

2729
log "Running swift-format lint..."
2830

29-
tr '\n' '\0' < .swiftformatignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 swift-format lint --strict --parallel
31+
tr '\n' '\0' < .swiftformatignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 "$SWIFT_FORMAT_BIN" lint --strict --parallel
3032
else
3133
log "Running swift-format format..."
32-
git ls-files -z '*.swift' | xargs -0 swift-format format --parallel --in-place
34+
git ls-files -z '*.swift' | xargs -0 "$SWIFT_FORMAT_BIN" format --parallel --in-place
3335

3436
log "Running swift-format lint..."
3537

36-
git ls-files -z '*.swift' | xargs -0 swift-format lint --strict --parallel
38+
git ls-files -z '*.swift' | xargs -0 "$SWIFT_FORMAT_BIN" lint --strict --parallel
3739
fi
3840

3941

0 commit comments

Comments
 (0)