diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c51680f0..60750130 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,6 +25,7 @@ repos: - id: destroyed-symlinks - id: detect-private-key - id: end-of-file-fixer + exclude: docs/LICENSE.txt - id: mixed-line-ending - id: no-commit-to-branch # protects `main` by default - id: trailing-whitespace @@ -54,6 +55,7 @@ repos: rev: v0.20.0 hooks: - id: yamlfmt + entry: python scripts/yamlfmt.py types_or: [yaml] exclude: ".*/vcr_cassettes/.*\\.yaml" diff --git a/scripts/yamlfmt.py b/scripts/yamlfmt.py new file mode 100644 index 00000000..56886adf --- /dev/null +++ b/scripts/yamlfmt.py @@ -0,0 +1,21 @@ +"""Helper script that automatically skips the yamlfmt pre-commit hook on Windows. + +This is not intended to be called directly. It is configured to be called by +pre-commit via the configuration in .pre-commit-config.yml for the yamlfmt hook. + +Due to https://github.com/google/yamlfmt/issues/263, comments in yaml files are +not handled properly under Windows, so any Windows user that causes yamlfmt to +format yaml files will cause CI build failure because we build under Linux, and +the resulting format will differ, causing file changes during the pre-commit +step, causing build failure. + +Therefore, this script avoids calling yamlfmt (via pre-commit) when running on +Windows. +""" + +import platform +import subprocess +import sys + +if platform.system() != "Windows": + sys.exit(subprocess.call(["yamlfmt", *sys.argv[1:]]))