Skip to content

Commit

Permalink
dev: fix pre-commit passing filenames incorrectly (#12304)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored Jan 9, 2025
1 parent ea4d40e commit 42b2cd3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
16 changes: 15 additions & 1 deletion .github/scripts/generate_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dataclasses import dataclass
from enum import Enum, auto
from pathlib import Path
import datetime

import yaml

Expand Down Expand Up @@ -188,6 +189,7 @@ def _generate_lint_fix_hook(self, project: Project) -> dict:
"entry": f"./gradlew {project.gradle_path}:lintFix",
"language": "system",
"files": f"^{project.path}/.*\\.py$",
"pass_filenames": False,
}

def _generate_spotless_hook(self, project: Project) -> dict:
Expand All @@ -198,6 +200,7 @@ def _generate_spotless_hook(self, project: Project) -> dict:
"entry": f"./gradlew {project.gradle_path}:spotlessApply",
"language": "system",
"files": f"^{project.path}/.*\\.java$",
"pass_filenames": False,
}


Expand All @@ -209,8 +212,19 @@ def increase_indent(self, flow=False, *args, **kwargs):


def write_yaml_with_spaces(file_path: str, data: dict):
"""Write YAML file with extra spacing between hooks."""
"""Write YAML file with extra spacing between hooks and a timestamp header."""
with open(file_path, "w") as f:
# Add timestamp header
current_time = datetime.datetime.now(datetime.timezone.utc)
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S %Z")
header = f"# Auto-generated by .github/scripts/generate_pre_commit.py at {formatted_time}\n"
f.write(header)
header = f"# Do not edit this file directly. Run the script to regenerate.\n"
f.write(header)
header = f"# Add additional hooks in .github/scripts/pre-commit-override.yaml\n"
f.write(header)

# Write the YAML content
yaml_str = yaml.dump(
data, Dumper=PrecommitDumper, sort_keys=False, default_flow_style=False
)
Expand Down
3 changes: 2 additions & 1 deletion .github/scripts/pre-commit-override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ repos:
name: smoke-test cypress Lint Fix
entry: ./gradlew :smoke-test:cypressLintFix
language: system
files: ^smoke-test/tests/cypress/.*$
files: ^smoke-test/tests/cypress/.*$
pass_filenames: false
Loading

0 comments on commit 42b2cd3

Please sign in to comment.