]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
feat: add --check mode to sync-to-async script
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 15 Aug 2023 22:08:48 +0000 (23:08 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 11 Oct 2023 21:45:38 +0000 (23:45 +0200)
It will be useful to set up a pipeline to check for inconsistencies.

tools/convert_async_to_sync.sh

index 4e167a062d634ccf22c4e48f2def45fd544aa8de..76b0e07dff761f657ee18a1be4bed564d8492264 100755 (executable)
@@ -7,6 +7,16 @@ set -euo pipefail
 dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 cd "${dir}/.."
 
+check=
+
+# If --check is used, give an error if files are changed
+# (note: it's not a --dry-run)
+if [[ ${1:-} == '--check' ]]; then
+    check=1
+fi
+
+outputs=""
+
 for async in \
     tests/test_client_cursor_async.py \
     tests/test_connection_async.py \
@@ -24,4 +34,13 @@ do
     echo "converting '${async}' -> '${sync}'" >&2
     python "${dir}/async_to_sync.py" ${async} > ${sync}
     black -q ${sync}
+    outputs="$outputs ${sync}"
 done
+
+if [[ $check ]]; then
+    if ! git diff --exit-code $outputs; then
+        echo "
+ERROR: sync and async files out of sync!" >&2
+        exit 1
+    fi
+fi