From 42b2cd3e7d95a84cbd1b078e2fa81a5ecc8b9fa8 Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Thu, 9 Jan 2025 18:28:19 +0530 Subject: [PATCH] dev: fix pre-commit passing filenames incorrectly (#12304) --- .github/scripts/generate_pre_commit.py | 16 +++++- .github/scripts/pre-commit-override.yaml | 3 +- .pre-commit-config.yaml | 65 ++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/.github/scripts/generate_pre_commit.py b/.github/scripts/generate_pre_commit.py index 740d3c20d263b0..2db73fd357ff5f 100755 --- a/.github/scripts/generate_pre_commit.py +++ b/.github/scripts/generate_pre_commit.py @@ -9,6 +9,7 @@ from dataclasses import dataclass from enum import Enum, auto from pathlib import Path +import datetime import yaml @@ -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: @@ -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, } @@ -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 ) diff --git a/.github/scripts/pre-commit-override.yaml b/.github/scripts/pre-commit-override.yaml index a085d9ea3ee93b..961134bebe2c98 100644 --- a/.github/scripts/pre-commit-override.yaml +++ b/.github/scripts/pre-commit-override.yaml @@ -5,4 +5,5 @@ repos: name: smoke-test cypress Lint Fix entry: ./gradlew :smoke-test:cypressLintFix language: system - files: ^smoke-test/tests/cypress/.*$ \ No newline at end of file + files: ^smoke-test/tests/cypress/.*$ + pass_filenames: false \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c4edc2cc176355..3697efa37770e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,6 @@ +# Auto-generated by .github/scripts/generate_pre_commit.py at 2025-01-09 10:08:09 UTC +# Do not edit this file directly. Run the script to regenerate. +# Add additional hooks in .github/scripts/pre-commit-override.yaml repos: - repo: local hooks: @@ -6,372 +9,434 @@ repos: entry: ./gradlew :datahub-graphql-core:spotlessApply language: system files: ^datahub-graphql-core/.*\.java$ + pass_filenames: false - id: datahub-upgrade-spotless name: datahub-upgrade Spotless Apply entry: ./gradlew :datahub-upgrade:spotlessApply language: system files: ^datahub-upgrade/.*\.java$ + pass_filenames: false - id: entity-registry-spotless name: entity-registry Spotless Apply entry: ./gradlew :entity-registry:spotlessApply language: system files: ^entity-registry/.*\.java$ + pass_filenames: false - id: ingestion-scheduler-spotless name: ingestion-scheduler Spotless Apply entry: ./gradlew :ingestion-scheduler:spotlessApply language: system files: ^ingestion-scheduler/.*\.java$ + pass_filenames: false - id: li-utils-spotless name: li-utils Spotless Apply entry: ./gradlew :li-utils:spotlessApply language: system files: ^li-utils/.*\.java$ + pass_filenames: false - id: metadata-auth-auth-api-spotless name: metadata-auth/auth-api Spotless Apply entry: ./gradlew :metadata-auth:auth-api:spotlessApply language: system files: ^metadata-auth/auth-api/.*\.java$ + pass_filenames: false - id: metadata-dao-impl-kafka-producer-spotless name: metadata-dao-impl/kafka-producer Spotless Apply entry: ./gradlew :metadata-dao-impl:kafka-producer:spotlessApply language: system files: ^metadata-dao-impl/kafka-producer/.*\.java$ + pass_filenames: false - id: metadata-events-mxe-avro-spotless name: metadata-events/mxe-avro Spotless Apply entry: ./gradlew :metadata-events:mxe-avro:spotlessApply language: system files: ^metadata-events/mxe-avro/.*\.java$ + pass_filenames: false - id: metadata-events-mxe-registration-spotless name: metadata-events/mxe-registration Spotless Apply entry: ./gradlew :metadata-events:mxe-registration:spotlessApply language: system files: ^metadata-events/mxe-registration/.*\.java$ + pass_filenames: false - id: metadata-events-mxe-schemas-spotless name: metadata-events/mxe-schemas Spotless Apply entry: ./gradlew :metadata-events:mxe-schemas:spotlessApply language: system files: ^metadata-events/mxe-schemas/.*\.java$ + pass_filenames: false - id: metadata-events-mxe-utils-avro-spotless name: metadata-events/mxe-utils-avro Spotless Apply entry: ./gradlew :metadata-events:mxe-utils-avro:spotlessApply language: system files: ^metadata-events/mxe-utils-avro/.*\.java$ + pass_filenames: false - id: metadata-ingestion-lint-fix name: metadata-ingestion Lint Fix entry: ./gradlew :metadata-ingestion:lintFix language: system files: ^metadata-ingestion/.*\.py$ + pass_filenames: false - id: metadata-ingestion-modules-airflow-plugin-lint-fix name: metadata-ingestion-modules/airflow-plugin Lint Fix entry: ./gradlew :metadata-ingestion-modules:airflow-plugin:lintFix language: system files: ^metadata-ingestion-modules/airflow-plugin/.*\.py$ + pass_filenames: false - id: metadata-ingestion-modules-dagster-plugin-lint-fix name: metadata-ingestion-modules/dagster-plugin Lint Fix entry: ./gradlew :metadata-ingestion-modules:dagster-plugin:lintFix language: system files: ^metadata-ingestion-modules/dagster-plugin/.*\.py$ + pass_filenames: false - id: metadata-ingestion-modules-gx-plugin-lint-fix name: metadata-ingestion-modules/gx-plugin Lint Fix entry: ./gradlew :metadata-ingestion-modules:gx-plugin:lintFix language: system files: ^metadata-ingestion-modules/gx-plugin/.*\.py$ + pass_filenames: false - id: metadata-ingestion-modules-prefect-plugin-lint-fix name: metadata-ingestion-modules/prefect-plugin Lint Fix entry: ./gradlew :metadata-ingestion-modules:prefect-plugin:lintFix language: system files: ^metadata-ingestion-modules/prefect-plugin/.*\.py$ + pass_filenames: false - id: metadata-integration-java-acryl-spark-lineage-spotless name: metadata-integration/java/acryl-spark-lineage Spotless Apply entry: ./gradlew :metadata-integration:java:acryl-spark-lineage:spotlessApply language: system files: ^metadata-integration/java/acryl-spark-lineage/.*\.java$ + pass_filenames: false - id: metadata-integration-java-datahub-client-spotless name: metadata-integration/java/datahub-client Spotless Apply entry: ./gradlew :metadata-integration:java:datahub-client:spotlessApply language: system files: ^metadata-integration/java/datahub-client/.*\.java$ + pass_filenames: false - id: metadata-integration-java-datahub-event-spotless name: metadata-integration/java/datahub-event Spotless Apply entry: ./gradlew :metadata-integration:java:datahub-event:spotlessApply language: system files: ^metadata-integration/java/datahub-event/.*\.java$ + pass_filenames: false - id: metadata-integration-java-datahub-protobuf-spotless name: metadata-integration/java/datahub-protobuf Spotless Apply entry: ./gradlew :metadata-integration:java:datahub-protobuf:spotlessApply language: system files: ^metadata-integration/java/datahub-protobuf/.*\.java$ + pass_filenames: false - id: metadata-integration-java-datahub-schematron-cli-spotless name: metadata-integration/java/datahub-schematron/cli Spotless Apply entry: ./gradlew :metadata-integration:java:datahub-schematron:cli:spotlessApply language: system files: ^metadata-integration/java/datahub-schematron/cli/.*\.java$ + pass_filenames: false - id: metadata-integration-java-datahub-schematron-lib-spotless name: metadata-integration/java/datahub-schematron/lib Spotless Apply entry: ./gradlew :metadata-integration:java:datahub-schematron:lib:spotlessApply language: system files: ^metadata-integration/java/datahub-schematron/lib/.*\.java$ + pass_filenames: false - id: metadata-integration-java-examples-spotless name: metadata-integration/java/examples Spotless Apply entry: ./gradlew :metadata-integration:java:examples:spotlessApply language: system files: ^metadata-integration/java/examples/.*\.java$ + pass_filenames: false - id: metadata-integration-java-openlineage-converter-spotless name: metadata-integration/java/openlineage-converter Spotless Apply entry: ./gradlew :metadata-integration:java:openlineage-converter:spotlessApply language: system files: ^metadata-integration/java/openlineage-converter/.*\.java$ + pass_filenames: false - id: metadata-integration-java-spark-lineage-legacy-spotless name: metadata-integration/java/spark-lineage-legacy Spotless Apply entry: ./gradlew :metadata-integration:java:spark-lineage-legacy:spotlessApply language: system files: ^metadata-integration/java/spark-lineage-legacy/.*\.java$ + pass_filenames: false - id: metadata-io-spotless name: metadata-io Spotless Apply entry: ./gradlew :metadata-io:spotlessApply language: system files: ^metadata-io/.*\.java$ + pass_filenames: false - id: metadata-io-metadata-io-api-spotless name: metadata-io/metadata-io-api Spotless Apply entry: ./gradlew :metadata-io:metadata-io-api:spotlessApply language: system files: ^metadata-io/metadata-io-api/.*\.java$ + pass_filenames: false - id: metadata-jobs-common-spotless name: metadata-jobs/common Spotless Apply entry: ./gradlew :metadata-jobs:common:spotlessApply language: system files: ^metadata-jobs/common/.*\.java$ + pass_filenames: false - id: metadata-jobs-mae-consumer-spotless name: metadata-jobs/mae-consumer Spotless Apply entry: ./gradlew :metadata-jobs:mae-consumer:spotlessApply language: system files: ^metadata-jobs/mae-consumer/.*\.java$ + pass_filenames: false - id: metadata-jobs-mae-consumer-job-spotless name: metadata-jobs/mae-consumer-job Spotless Apply entry: ./gradlew :metadata-jobs:mae-consumer-job:spotlessApply language: system files: ^metadata-jobs/mae-consumer-job/.*\.java$ + pass_filenames: false - id: metadata-jobs-mce-consumer-spotless name: metadata-jobs/mce-consumer Spotless Apply entry: ./gradlew :metadata-jobs:mce-consumer:spotlessApply language: system files: ^metadata-jobs/mce-consumer/.*\.java$ + pass_filenames: false - id: metadata-jobs-mce-consumer-job-spotless name: metadata-jobs/mce-consumer-job Spotless Apply entry: ./gradlew :metadata-jobs:mce-consumer-job:spotlessApply language: system files: ^metadata-jobs/mce-consumer-job/.*\.java$ + pass_filenames: false - id: metadata-jobs-pe-consumer-spotless name: metadata-jobs/pe-consumer Spotless Apply entry: ./gradlew :metadata-jobs:pe-consumer:spotlessApply language: system files: ^metadata-jobs/pe-consumer/.*\.java$ + pass_filenames: false - id: metadata-models-spotless name: metadata-models Spotless Apply entry: ./gradlew :metadata-models:spotlessApply language: system files: ^metadata-models/.*\.java$ + pass_filenames: false - id: metadata-models-custom-spotless name: metadata-models-custom Spotless Apply entry: ./gradlew :metadata-models-custom:spotlessApply language: system files: ^metadata-models-custom/.*\.java$ + pass_filenames: false - id: metadata-models-validator-spotless name: metadata-models-validator Spotless Apply entry: ./gradlew :metadata-models-validator:spotlessApply language: system files: ^metadata-models-validator/.*\.java$ + pass_filenames: false - id: metadata-operation-context-spotless name: metadata-operation-context Spotless Apply entry: ./gradlew :metadata-operation-context:spotlessApply language: system files: ^metadata-operation-context/.*\.java$ + pass_filenames: false - id: metadata-service-auth-config-spotless name: metadata-service/auth-config Spotless Apply entry: ./gradlew :metadata-service:auth-config:spotlessApply language: system files: ^metadata-service/auth-config/.*\.java$ + pass_filenames: false - id: metadata-service-auth-filter-spotless name: metadata-service/auth-filter Spotless Apply entry: ./gradlew :metadata-service:auth-filter:spotlessApply language: system files: ^metadata-service/auth-filter/.*\.java$ + pass_filenames: false - id: metadata-service-auth-impl-spotless name: metadata-service/auth-impl Spotless Apply entry: ./gradlew :metadata-service:auth-impl:spotlessApply language: system files: ^metadata-service/auth-impl/.*\.java$ + pass_filenames: false - id: metadata-service-auth-servlet-impl-spotless name: metadata-service/auth-servlet-impl Spotless Apply entry: ./gradlew :metadata-service:auth-servlet-impl:spotlessApply language: system files: ^metadata-service/auth-servlet-impl/.*\.java$ + pass_filenames: false - id: metadata-service-configuration-spotless name: metadata-service/configuration Spotless Apply entry: ./gradlew :metadata-service:configuration:spotlessApply language: system files: ^metadata-service/configuration/.*\.java$ + pass_filenames: false - id: metadata-service-factories-spotless name: metadata-service/factories Spotless Apply entry: ./gradlew :metadata-service:factories:spotlessApply language: system files: ^metadata-service/factories/.*\.java$ + pass_filenames: false - id: metadata-service-graphql-servlet-impl-spotless name: metadata-service/graphql-servlet-impl Spotless Apply entry: ./gradlew :metadata-service:graphql-servlet-impl:spotlessApply language: system files: ^metadata-service/graphql-servlet-impl/.*\.java$ + pass_filenames: false - id: metadata-service-openapi-analytics-servlet-spotless name: metadata-service/openapi-analytics-servlet Spotless Apply entry: ./gradlew :metadata-service:openapi-analytics-servlet:spotlessApply language: system files: ^metadata-service/openapi-analytics-servlet/.*\.java$ + pass_filenames: false - id: metadata-service-openapi-entity-servlet-spotless name: metadata-service/openapi-entity-servlet Spotless Apply entry: ./gradlew :metadata-service:openapi-entity-servlet:spotlessApply language: system files: ^metadata-service/openapi-entity-servlet/.*\.java$ + pass_filenames: false - id: metadata-service-openapi-entity-servlet-generators-spotless name: metadata-service/openapi-entity-servlet/generators Spotless Apply entry: ./gradlew :metadata-service:openapi-entity-servlet:generators:spotlessApply language: system files: ^metadata-service/openapi-entity-servlet/generators/.*\.java$ + pass_filenames: false - id: metadata-service-openapi-servlet-spotless name: metadata-service/openapi-servlet Spotless Apply entry: ./gradlew :metadata-service:openapi-servlet:spotlessApply language: system files: ^metadata-service/openapi-servlet/.*\.java$ + pass_filenames: false - id: metadata-service-openapi-servlet-models-spotless name: metadata-service/openapi-servlet/models Spotless Apply entry: ./gradlew :metadata-service:openapi-servlet:models:spotlessApply language: system files: ^metadata-service/openapi-servlet/models/.*\.java$ + pass_filenames: false - id: metadata-service-plugin-spotless name: metadata-service/plugin Spotless Apply entry: ./gradlew :metadata-service:plugin:spotlessApply language: system files: ^metadata-service/plugin/.*\.java$ + pass_filenames: false - id: metadata-service-plugin-src-test-sample-test-plugins-spotless name: metadata-service/plugin/src/test/sample-test-plugins Spotless Apply entry: ./gradlew :metadata-service:plugin:src:test:sample-test-plugins:spotlessApply language: system files: ^metadata-service/plugin/src/test/sample-test-plugins/.*\.java$ + pass_filenames: false - id: metadata-service-restli-client-spotless name: metadata-service/restli-client Spotless Apply entry: ./gradlew :metadata-service:restli-client:spotlessApply language: system files: ^metadata-service/restli-client/.*\.java$ + pass_filenames: false - id: metadata-service-restli-client-api-spotless name: metadata-service/restli-client-api Spotless Apply entry: ./gradlew :metadata-service:restli-client-api:spotlessApply language: system files: ^metadata-service/restli-client-api/.*\.java$ + pass_filenames: false - id: metadata-service-restli-servlet-impl-spotless name: metadata-service/restli-servlet-impl Spotless Apply entry: ./gradlew :metadata-service:restli-servlet-impl:spotlessApply language: system files: ^metadata-service/restli-servlet-impl/.*\.java$ + pass_filenames: false - id: metadata-service-schema-registry-api-spotless name: metadata-service/schema-registry-api Spotless Apply entry: ./gradlew :metadata-service:schema-registry-api:spotlessApply language: system files: ^metadata-service/schema-registry-api/.*\.java$ + pass_filenames: false - id: metadata-service-schema-registry-servlet-spotless name: metadata-service/schema-registry-servlet Spotless Apply entry: ./gradlew :metadata-service:schema-registry-servlet:spotlessApply language: system files: ^metadata-service/schema-registry-servlet/.*\.java$ + pass_filenames: false - id: metadata-service-services-spotless name: metadata-service/services Spotless Apply entry: ./gradlew :metadata-service:services:spotlessApply language: system files: ^metadata-service/services/.*\.java$ + pass_filenames: false - id: metadata-service-servlet-spotless name: metadata-service/servlet Spotless Apply entry: ./gradlew :metadata-service:servlet:spotlessApply language: system files: ^metadata-service/servlet/.*\.java$ + pass_filenames: false - id: metadata-utils-spotless name: metadata-utils Spotless Apply entry: ./gradlew :metadata-utils:spotlessApply language: system files: ^metadata-utils/.*\.java$ + pass_filenames: false - id: mock-entity-registry-spotless name: mock-entity-registry Spotless Apply entry: ./gradlew :mock-entity-registry:spotlessApply language: system files: ^mock-entity-registry/.*\.java$ + pass_filenames: false - id: smoke-test-lint-fix name: smoke-test Lint Fix entry: ./gradlew :smoke-test:lintFix language: system files: ^smoke-test/.*\.py$ + pass_filenames: false - id: test-models-spotless name: test-models Spotless Apply entry: ./gradlew :test-models:spotlessApply language: system files: ^test-models/.*\.java$ + pass_filenames: false - id: smoke-test-cypress-lint-fix name: smoke-test cypress Lint Fix