From 508d39c879184ffff6431d18bf16dc75ba2218c8 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 09:34:17 +0200 Subject: [PATCH 1/3] Add a soundness --fix flag --- scripts/run-swift-format.sh | 11 +++++++++-- scripts/soundness.sh | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) mode change 100644 => 100755 scripts/run-swift-format.sh diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh old mode 100644 new mode 100755 index 023d426d..478a1a29 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -21,12 +21,19 @@ fatal() { error "$@"; exit 1; } CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" +FORMAT_COMMAND="lint --strict" +for arg in "$@"; do + if [ "$arg" == "--fix" ]; then + FORMAT_COMMAND="format --in-place" + fi +done + SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" git -C "${REPO_ROOT}" ls-files -z '*.swift' \ | grep -z -v -e 'Tests/OpenAPIGeneratorReferenceTests/Resources' \ -e 'Sources/swift-openapi-generator/Documentation.docc' \ - | xargs -0 "${SWIFTFORMAT_BIN}" lint --parallel --strict \ + | xargs -0 "${SWIFTFORMAT_BIN}" ${FORMAT_COMMAND} --parallel \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then @@ -34,7 +41,7 @@ if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then To fix, run the following command: - % git ls-files -z '*.swift' | grep -z -v -e 'Tests/OpenAPIGeneratorReferenceTests/Resources' -e 'Sources/swift-openapi-generator/Documentation.docc' | xargs -0 swift-format --in-place --parallel + % ./scripts/run-swift-format.sh --fix " exit "${SWIFT_FORMAT_RC}" fi diff --git a/scripts/soundness.sh b/scripts/soundness.sh index f8ae7050..9f4867a8 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -21,11 +21,17 @@ fatal() { error "$@"; exit 1; } CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" NUM_CHECKS_FAILED=0 +FIX_FORMAT="" +for arg in "$@"; do + if [ "$arg" == "--fix" ]; then + FIX_FORMAT="--fix" + fi +done + SCRIPT_PATHS=( "${CURRENT_SCRIPT_DIR}/check-for-broken-symlinks.sh" "${CURRENT_SCRIPT_DIR}/check-for-unacceptable-language.sh" "${CURRENT_SCRIPT_DIR}/check-license-headers.sh" - "${CURRENT_SCRIPT_DIR}/run-swift-format.sh" ) for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do @@ -35,6 +41,13 @@ for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do fi done +log "Running swift-format..." +bash ${CURRENT_SCRIPT_DIR}/run-swift-format.sh $FIX_FORMAT > /dev/null +FORMAT_EXIT_CODE=$? +if [ $FORMAT_EXIT_CODE -ne 0 ]; then + ((NUM_CHECKS_FAILED+=1)) +fi + if [ "${NUM_CHECKS_FAILED}" -gt 0 ]; then fatal "❌ ${NUM_CHECKS_FAILED} soundness check(s) failed." fi From 7561e4da6f7bedbcb0e1fc23bf4ae859461c7e4e Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 12:04:04 +0200 Subject: [PATCH 2/3] PR feedback --- scripts/run-swift-format.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh index 478a1a29..13b5bcad 100755 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -21,10 +21,10 @@ fatal() { error "$@"; exit 1; } CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" -FORMAT_COMMAND="lint --strict" +FORMAT_COMMAND=(lint --strict) for arg in "$@"; do if [ "$arg" == "--fix" ]; then - FORMAT_COMMAND="format --in-place" + FORMAT_COMMAND=(format --in-place) fi done @@ -33,7 +33,7 @@ SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWI git -C "${REPO_ROOT}" ls-files -z '*.swift' \ | grep -z -v -e 'Tests/OpenAPIGeneratorReferenceTests/Resources' \ -e 'Sources/swift-openapi-generator/Documentation.docc' \ - | xargs -0 "${SWIFTFORMAT_BIN}" ${FORMAT_COMMAND} --parallel \ + | xargs -0 "${SWIFTFORMAT_BIN}" "${FORMAT_COMMAND[@]}" --parallel \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then From 0dd1a4a146881d09eba22c1dc900b619e5543663 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 12:08:17 +0200 Subject: [PATCH 3/3] Update scripts/soundness.sh Co-authored-by: George Barnett --- scripts/soundness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 9f4867a8..45ee0f30 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -42,7 +42,7 @@ for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do done log "Running swift-format..." -bash ${CURRENT_SCRIPT_DIR}/run-swift-format.sh $FIX_FORMAT > /dev/null +bash "${CURRENT_SCRIPT_DIR}"/run-swift-format.sh $FIX_FORMAT > /dev/null FORMAT_EXIT_CODE=$? if [ $FORMAT_EXIT_CODE -ne 0 ]; then ((NUM_CHECKS_FAILED+=1))