From d981c01620b47e256c1c6d6ae821a49e056c3664 Mon Sep 17 00:00:00 2001 From: Sven Tennie Date: Mon, 16 Dec 2024 19:13:09 +0100 Subject: [PATCH 1/3] Format submodule with existing Ormolu script The wrapper calls the renamed old script to also format the wire-server-enterprise submodule. --- tools/ormolu.sh | 108 +++---------------------------------------- tools/ormolu1.sh | 118 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 101 deletions(-) create mode 100755 tools/ormolu1.sh diff --git a/tools/ormolu.sh b/tools/ormolu.sh index 7058e51517b..d063fa77361 100755 --- a/tools/ormolu.sh +++ b/tools/ormolu.sh @@ -1,106 +1,12 @@ #!/usr/bin/env bash +# This is a wrapper script to call tools/ormolu1.sh It calls that script for +# both, wire-server and the services/wire-server-enterprise submodule. It should +# be compatible to the old behaviour, with the only addition, that the submodule +# is visited as well. set -e -cd "$( dirname "${BASH_SOURCE[0]}" )/.." +cd "$(dirname "${BASH_SOURCE[0]}")" -ALLOW_DIRTY_WC="0" -ARG_ORMOLU_MODE="inplace" -PR_BASE=${PR_BASE:-"origin/develop"} - -USAGE=" -This bash script can either - -* apply ormolu formatting in-place (the default) - -* check all modules for formatting and fail if ormolu needs to be applied (-c flag). This can be run in CI to make sure no branches with non-ormolu formatting make get merged. - -USAGE: $0 - -h : show this help. - -f pr : run even if working copy is dirty. Check only on files changed by branch. - -f all : run even if working copy is dirty. Check all files. - -c : set ormolu mode to 'check'. default: 'inplace' -" - -usage() { echo "$USAGE" 1>&2; exit 1; } - -# Option parsing: -# https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/ -while getopts ":f:ch" opt; do - case ${opt} in - f ) f=${OPTARG} - if [ "$f" = "pr" ]; then - ALLOW_DIRTY_WC=1 - elif [ "$f" = "all" ]; then - ALLOW_DIRTY_WC=1 - else - usage - fi - ;; - c ) ARG_ORMOLU_MODE="check" - ;; - h ) echo "$USAGE" 1>&2 - exit 0 - ;; - *) usage;; - esac -done -shift $((OPTIND -1)) - -if [ "$#" -ne 0 ]; then - echo "$USAGE" 1>&2 - exit 1 -fi - -if [ "$(git status -s | grep -v \?\?)" != "" ]; then - if [ "$ALLOW_DIRTY_WC" == "1" ]; then - : - else - echo "Working copy is not clean." - echo "Run with -f pr or -f all if you want to run ormolu anyway" - exit 1 - fi -fi - -echo "ormolu mode: $ARG_ORMOLU_MODE" -echo "language extensions are taken from the resp. cabal files" - -FAILURES=0 - -if [ -t 1 ]; then - : "${ORMOLU_CONDENSE_OUTPUT:=1}" -fi - -if [ "$f" = "all" ] || [ "$f" = "" ]; then - files=$(git ls-files | grep '\.hsc\?$') -elif [ "$f" = "pr" ]; then - files=$(git diff --diff-filter=ACMR --name-only "$PR_BASE"... | { grep '\.hsc\?$' || true; }; git diff --diff-filter=ACMR --name-only HEAD | { grep \.hs\$ || true ; }) -fi - -count=$( echo "$files" | sed '/^\s*$/d' | wc -l ) -echo "Checking $count file(s)…" - -for hsfile in $files; do - # run in background so that we can detect Ctrl-C properly - ormolu --mode $ARG_ORMOLU_MODE --check-idempotence "$hsfile" & - wait $! && err=0 || err=$? - - if [ "$err" == "100" ]; then - ((++FAILURES)) - echo "$hsfile... *** FAILED" - clear="" - elif [ "$err" == "0" ]; then - echo -e "$clear$hsfile... ok" - [ "$ORMOLU_CONDENSE_OUTPUT" == "1" ] && clear="\033[A\r\033[K" - else - exit "$err" - fi -done - -if [ "$FAILURES" != 0 ]; then - echo "ormolu failed on $FAILURES files." - if [ "$ARG_ORMOLU_MODE" == "check" ]; then - echo -en "\n\nyou can fix this by running 'make format' from the git repo root.\n\n" - fi - exit 1 -fi +REL_PATH=services/wire-server-enterprise PR_BASE=origin/main ./ormolu1.sh "$@" +PR_BASE=origin/develop ./ormolu1.sh "$@" diff --git a/tools/ormolu1.sh b/tools/ormolu1.sh new file mode 100755 index 00000000000..1210c58672a --- /dev/null +++ b/tools/ormolu1.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash + +set -e + +REL_PATH=${REL_PATH:-"."} +cd "$(dirname "${BASH_SOURCE[0]}")/../$REL_PATH" + +echo Formatting branch "$PR_BASE" in "${REL_PATH}" + +ALLOW_DIRTY_WC="0" +ARG_ORMOLU_MODE="inplace" +PR_BASE=${PR_BASE:-"origin/develop"} + +USAGE=" +This bash script can either + +* apply ormolu formatting in-place (the default) + +* check all modules for formatting and fail if ormolu needs to be applied (-c flag). This can be run in CI to make sure no branches with non-ormolu formatting make get merged. + +USAGE: $0 + -h : show this help. + -f pr : run even if working copy is dirty. Check only on files changed by branch. + -f all : run even if working copy is dirty. Check all files. + -c : set ormolu mode to 'check'. default: 'inplace' +" + +usage() { + echo "$USAGE" 1>&2 + exit 1 +} + +# Option parsing: +# https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/ +while getopts ":f:ch" opt; do + case ${opt} in + f) + f=${OPTARG} + if [ "$f" = "pr" ]; then + ALLOW_DIRTY_WC=1 + elif [ "$f" = "all" ]; then + ALLOW_DIRTY_WC=1 + else + usage + fi + ;; + c) + ARG_ORMOLU_MODE="check" + ;; + h) + echo "$USAGE" 1>&2 + exit 0 + ;; + *) usage ;; + esac +done +shift $((OPTIND - 1)) + +if [ "$#" -ne 0 ]; then + echo "$USAGE" 1>&2 + exit 1 +fi + +if [ "$(git status -s | grep -v \?\?)" != "" ]; then + if [ "$ALLOW_DIRTY_WC" == "1" ]; then + : + else + echo "Working copy is not clean." + echo "Run with -f pr or -f all if you want to run ormolu anyway" + exit 1 + fi +fi + +echo "ormolu mode: $ARG_ORMOLU_MODE" +echo "language extensions are taken from the resp. cabal files" + +FAILURES=0 + +if [ -t 1 ]; then + : "${ORMOLU_CONDENSE_OUTPUT:=1}" +fi + +if [ "$f" = "all" ] || [ "$f" = "" ]; then + files=$(git ls-files | grep '\.hsc\?$') +elif [ "$f" = "pr" ]; then + files=$( + git diff --diff-filter=ACMR --name-only "$PR_BASE"... | { grep '\.hsc\?$' || true; } + git diff --diff-filter=ACMR --name-only HEAD | { grep \.hs\$ || true; } + ) +fi + +count=$(echo "$files" | sed '/^\s*$/d' | wc -l) +echo "Checking $count file(s)…" + +for hsfile in $files; do + # run in background so that we can detect Ctrl-C properly + ormolu --mode $ARG_ORMOLU_MODE --check-idempotence "$hsfile" & + wait $! && err=0 || err=$? + + if [ "$err" == "100" ]; then + ((++FAILURES)) + echo "$hsfile... *** FAILED" + clear="" + elif [ "$err" == "0" ]; then + echo -e "$clear$hsfile... ok" + [ "$ORMOLU_CONDENSE_OUTPUT" == "1" ] && clear="\033[A\r\033[K" + else + exit "$err" + fi +done + +if [ "$FAILURES" != 0 ]; then + echo "ormolu failed on $FAILURES files." + if [ "$ARG_ORMOLU_MODE" == "check" ]; then + echo -en "\n\nyou can fix this by running 'make format' from the git repo root.\n\n" + fi + exit 1 +fi From e443aa50cf254ce836b09b5fadb46c431229efca Mon Sep 17 00:00:00 2001 From: Sven Tennie Date: Mon, 16 Dec 2024 19:16:00 +0100 Subject: [PATCH 2/3] Add changelog --- changelog.d/5-internal/submodule-formatting | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog.d/5-internal/submodule-formatting diff --git a/changelog.d/5-internal/submodule-formatting b/changelog.d/5-internal/submodule-formatting new file mode 100644 index 00000000000..31ab2d3697e --- /dev/null +++ b/changelog.d/5-internal/submodule-formatting @@ -0,0 +1,2 @@ +Adjust the existing Ormolu script to format the wire-server-enterprise submodule +as well. From 817d5f8a79e45c7c4480dedcf239bcff959f9f2b Mon Sep 17 00:00:00 2001 From: Sven Tennie Date: Tue, 17 Dec 2024 10:03:47 +0100 Subject: [PATCH 3/3] Upgrade wire-server-enterprise submodule To fix formatting issues. --- services/wire-server-enterprise | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/wire-server-enterprise b/services/wire-server-enterprise index 61560248714..126abff4608 160000 --- a/services/wire-server-enterprise +++ b/services/wire-server-enterprise @@ -1 +1 @@ -Subproject commit 615602487147e7ac4fae49e72b661ace437e8ce6 +Subproject commit 126abff46082573c958aed8e6a338a00c608c376