From 1722045c1a3ea5e6ea3cae9727e8b4cf81c8f988 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 3 Apr 2026 10:45:23 +0200 Subject: [PATCH] Tools: Raise Artistic Style errors in CI --- .github/workflows/test_scripts.yml | 3 ++- Tools/scripts/build_ci.sh | 3 --- Tools/scripts/run_astyle.py | 10 +++++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_scripts.yml b/.github/workflows/test_scripts.yml index 1da0c6e4244a7a..89991330348b10 100644 --- a/.github/workflows/test_scripts.yml +++ b/.github/workflows/test_scripts.yml @@ -34,10 +34,11 @@ jobs: pip-install: flake8 lxml pexpect - name: Install astyle + if: matrix.config == 'astyle-cleanliness' shell: bash run: | sudo apt-get update - sudo apt-get install -y astyle + sudo apt-get install --yes astyle - name: Install shellcheck if: matrix.config == 'shellcheck' diff --git a/Tools/scripts/build_ci.sh b/Tools/scripts/build_ci.sh index 1764c2edb38b0d..07ed0b666e72e8 100755 --- a/Tools/scripts/build_ci.sh +++ b/Tools/scripts/build_ci.sh @@ -518,9 +518,6 @@ for t in $CI_BUILD_TARGET; do echo "Checking AStyle code cleanliness" ./Tools/scripts/run_astyle.py --dry-run - if [ $? -ne 0 ]; then - echo The code failed astyle cleanliness checks. Please run ./Tools/scripts/run_astyle.py - fi continue fi diff --git a/Tools/scripts/run_astyle.py b/Tools/scripts/run_astyle.py index a279930057cda3..1ba91a7c805178 100755 --- a/Tools/scripts/run_astyle.py +++ b/Tools/scripts/run_astyle.py @@ -7,6 +7,7 @@ """ import argparse +import contextlib import os import pathlib import subprocess @@ -37,13 +38,16 @@ def __init__(self, *, dry_run=DRY_RUN_DEFAULT): self.dry_run = dry_run def progress(self, string): - print("****** %s" % (string,)) + print(f"****** {string}") def check(self): '''run astyle on all files in self.files_to_check''' # for path in self.files_to_check: # self.progress("Checking (%s)" % path) astyle_command = ["astyle"] + # Show the astyle version suppressing all exceptions + with contextlib.suppress(): + _ = subprocess.run(astyle_command + ["--version"]) if self.dry_run: astyle_command.append("--dry-run") @@ -56,7 +60,7 @@ def check(self): text=True ) if ret.returncode != 0: - self.progress("astyle check failed: (%s)" % (ret.stdout)) + self.progress(f"astyle check failed: ({ret.stdout})") self.retcode = 1 if "Formatted" in ret.stdout: self.progress("Files needing formatting found.") @@ -72,7 +76,7 @@ def run(self): if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Check all Python files for astyle cleanliness') + parser = argparse.ArgumentParser(description='Check C and C++ files for astyle cleanliness') parser.add_argument('--dry-run', action='store_true', default=DRY_RUN_DEFAULT,