gh actions: run formatters in parallel
We can run gofmt and prettier in parallel, so let's do that.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s8536e19843fdb5b6k
diff --git a/bin/run-formatters.sh b/bin/run-formatters.sh
index 0f740ee..5859931 100755
--- a/bin/run-formatters.sh
+++ b/bin/run-formatters.sh
@@ -13,42 +13,62 @@
echo "Running in fix mode (formatting will be modified)"
fi
-# Go formatting with gofumpt
-echo "Checking Go formatting..."
-if [ "$CHECK_MODE" = true ]; then
- # In check mode, we want to display the files that need formatting and exit with error if any
- FILES_TO_FORMAT=$(gofumpt -l .)
- if [ -n "$FILES_TO_FORMAT" ]; then
- echo "The following Go files need formatting:"
- echo "$FILES_TO_FORMAT"
- exit 1
- else
- echo "Go formatting check passed"
- fi
-else
- # In fix mode, we apply the formatting
- echo "Fixing Go formatting with gofumpt"
- gofumpt -w .
- echo "Go formatting complete"
-fi
+# Run both formatters in parallel
+echo "Running Go and webui formatters in parallel..."
-# Webui formatting with Prettier
-echo "Checking webui formatting..."
-if [ -d "./webui" ]; then
- cd webui
+# Run Go formatting in background
+(
+ echo "Checking Go formatting..."
if [ "$CHECK_MODE" = true ]; then
- echo "Checking webui formatting with Prettier"
- if ! npx prettier@3.5.3 --check .; then
- echo "Webui files need formatting"
+ # In check mode, we want to display the files that need formatting and exit with error if any
+ FILES_TO_FORMAT=$(gofumpt -l .)
+ if [ -n "$FILES_TO_FORMAT" ]; then
+ echo "The following Go files need formatting:"
+ echo "$FILES_TO_FORMAT"
exit 1
+ else
+ echo "Go formatting check passed"
fi
else
- echo "Fixing webui formatting with Prettier"
- npx prettier@3.5.3 --write .
- echo "Webui formatting complete"
+ # In fix mode, we apply the formatting
+ echo "Fixing Go formatting with gofumpt"
+ gofumpt -w .
+ echo "Go formatting complete"
fi
-else
- echo "No webui directory found, skipping Prettier check"
+) &
+GO_PID=$!
+
+# Run webui formatting in background
+(
+ echo "Checking webui formatting..."
+ if [ -d "./webui" ]; then
+ cd webui
+ if [ "$CHECK_MODE" = true ]; then
+ echo "Checking webui formatting with Prettier"
+ if ! npx prettier@3.5.3 --check .; then
+ echo "Webui files need formatting"
+ exit 1
+ fi
+ else
+ echo "Fixing webui formatting with Prettier"
+ npx prettier@3.5.3 --write .
+ echo "Webui formatting complete"
+ fi
+ else
+ echo "No webui directory found, skipping Prettier check"
+ fi
+) &
+WEBUI_PID=$!
+
+# Wait for both processes and capture exit codes
+wait $GO_PID
+GO_EXIT=$?
+wait $WEBUI_PID
+WEBUI_EXIT=$?
+
+# Exit with error if either formatter failed
+if [ $GO_EXIT -ne 0 ] || [ $WEBUI_EXIT -ne 0 ]; then
+ exit 1
fi
if [ "$CHECK_MODE" = true ]; then