Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,6 +55,7 @@ repos:
rev: v0.20.0
hooks:
- id: yamlfmt
entry: python scripts/yamlfmt.py
types_or: [yaml]
exclude: ".*/vcr_cassettes/.*\\.yaml"

Expand Down
21 changes: 21 additions & 0 deletions scripts/yamlfmt.py
Original file line number Diff line number Diff line change
@@ -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:]]))