From a1032dd738305b56bd2df5b654dd8c5296408848 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 09:05:12 +0800 Subject: Improvements to formatting bot (#5421) * Use github token for formatting command dispatch * Open PR instead of committing directly when formatting * Add --no-version-check option to formatting script * Colorful diff output for cmake formatting --- extras/formatting.sh | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'extras') diff --git a/extras/formatting.sh b/extras/formatting.sh index dc3bbc7ca..a53930eaf 100755 --- a/extras/formatting.sh +++ b/extras/formatting.sh @@ -2,15 +2,21 @@ set -e -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -cd "$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel)" || exit 1 +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +source_dir="$(dirname "$script_dir")" check_only=0 +no_version_check=0 while [[ "$#" -gt 0 ]]; do case $1 in -h | --help) help=1 ;; --check-only) check_only=1 ;; + --no-version-check) no_version_check=1 ;; + --source) + source_dir="$2" + shift + ;; esac shift done @@ -20,14 +26,18 @@ if [ "$help" ]; then cat <] Options: - --check-only Check formatting without modifying files + --check-only Check formatting without modifying files + --no-version-check Skip version compatibility checks + --source Path to source directory to format (defaults to parent of script directory) EOF exit 0 fi +cd "$source_dir" || exit 1 + require_bin() { local name="$1" local required="$2" @@ -39,19 +49,17 @@ require_bin() { return fi - version=$("$name" --version | grep -oP "$name(?:\s+version)?\s+\K\d+\.\d+\.?\d*") - if ! printf '%s\n%s\n' "$required" "$version" | sort -V -C; then - echo "$name version $version is too old. Version $required or newer is required." - missing_bin=1 + if [ "$no_version_check" -eq 0 ]; then + version=$("$name" --version | grep -oP "$name(?:\s+version)?\s+\K\d+\.\d+\.?\d*") + if ! printf '%s\n%s\n' "$required" "$version" | sort -V -C; then + echo "$name version $version is too old. Version $required or newer is required." + missing_bin=1 + fi fi } require_bin "git" "1.8" -require_bin "gersemi" "0.16.2" - -if [ "${missing_bin:-}" = "1" ]; then - exit 1 -fi +require_bin "gersemi" "0.17" if [ "$missing_bin" ]; then exit 1 @@ -79,3 +87,4 @@ cmake_formatting() { cmake_formatting exit $exit_code + -- cgit v1.2.3