summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtools/clang-format-container.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/clang-format-container.sh b/tools/clang-format-container.sh
new file mode 100755
index 0000000..a9445e7
--- /dev/null
+++ b/tools/clang-format-container.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+set -e
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+DIR="$(realpath "$(dirname "$0")/../")"
+cd "$DIR"
+
+# The correct clang-format version is the one from the Fedora version used in our
+# github action pipeline. Parse it from ".github/workflows/ci.yml".
+FEDORA_VERSION="$(sed -n 's/^ image: fedora:\([0-9]\+\)$/\1/p' .github/workflows/ci.yml)"
+
+test -n "$FEDORA_VERSION" || die "Could not detect the Fedora version in .github/workflows/ci.yml"
+
+PODNAME="libnl-code-format-f$FEDORA_VERSION"
+
+RENEW=0
+for a; do
+ case "$a" in
+ -f)
+ RENEW=1
+ ;;
+ *)
+ die "invalid argument \"$a\""
+ ;;
+ esac
+done
+
+set -x
+
+if [ "$RENEW" == 1 ]; then
+ if podman container exists "$PODNAME" ; then
+ podman rm "$PODNAME"
+ fi
+fi
+
+if ! podman container exists "$PODNAME" ; then
+ podman run \
+ --name="$PODNAME" \
+ -v "$DIR:/tmp/libnl3:Z" \
+ -w /tmp/libnl3 \
+ "fedora:$FEDORA_VERSION" \
+ /bin/bash -c 'dnf upgrade -y && dnf install -y git /usr/bin/clang-format && tools/clang-format.sh -i'
+ exit 0
+fi
+
+podman start -a "$PODNAME"