summaryrefslogtreecommitdiffstats
path: root/extras/formatting.sh
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 09:05:12 +0800
committerGitHub <noreply@github.com>2024-10-29 09:05:12 +0800
commita1032dd738305b56bd2df5b654dd8c5296408848 (patch)
tree9f29d9d5eec525ad49703fc3eb84ddb297b0b51d /extras/formatting.sh
parentb7a619b45b0745f166d2dcc5985b994fb1d85d13 (diff)
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
Diffstat (limited to 'extras/formatting.sh')
-rwxr-xr-xextras/formatting.sh35
1 files changed, 22 insertions, 13 deletions
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 <<EOF
$me: Format or check formatting of files in this repo
-Usage: $me [--check-only]
+Usage: $me [--check-only] [--no-version-check] [--source <path>]
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
+