From d63144387c4f2ade7394574fa9e8f6cbdb5d58e6 Mon Sep 17 00:00:00 2001 From: tomsht01 Date: Mon, 30 Jun 2025 14:41:16 +0300 Subject: [PATCH 1/5] feat: implement yamlfmt hook --- MODULE.bazel | 17 +++++++++++++++++ yamlfmt/BUILD | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 yamlfmt/BUILD diff --git a/MODULE.bazel b/MODULE.bazel index d33e962..86a5d6e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -77,3 +77,20 @@ download_file = use_repo_rule("@download_utils//download/file:defs.bzl", "downlo ("windows", ".exe", "sha256-UXCzva+NhYCQtnPGPSxuFuA8qg6LNx4aMSaEvP2l8oM="), ) ] + +# Yamlfmt binaries +[ + download_archive( + name = "yamlfmt-{}".format(name), + integrity = integrity, + urls = ["https://github.com/google/yamlfmt/releases/download/v0.17.2/yamlfmt_0.17.2_{}.tar.gz".format(actual)], + ) + for name, actual, integrity in ( + ("amd64-linux", "Linux_x86_64", "sha256-sRQRW2gEz9IDGV0iJVjk/rOOMR//tZDE4TZC+iG9Djc="), + ("arm64-linux", "Linux_arm64", "sha256-F4W5dRr53KEKij5R7i9vOqZFZGENzJlNmEIeKNArVrU="), + ("amd64-macos", "Darwin_x86_64", "sha256-6Ab+EBPmAXiOdi3H5UhYsLtL3IKMW0yVEl22fNmXrDA="), + ("arm64-macos", "Darwin_arm64", "sha256-lL0/s6LGa9q3e1jNkb7OnkqKKKM8tOD+JB5iIFSPad0="), + ("amd64-windows", "Windows_x86_64", "sha256-/G/ZMo9i14gMHtoYifnro59CxjF3YcI8J3cTSbpgFRM="), + ("arm64-windows", "Windows_arm64", "sha256-ZrPktLOsZOw7rmzOzTjLW1vzZXvhXCIgvomkyjGCX24="), + ) +] diff --git a/yamlfmt/BUILD b/yamlfmt/BUILD new file mode 100644 index 0000000..6bb9ae9 --- /dev/null +++ b/yamlfmt/BUILD @@ -0,0 +1,32 @@ +load("@pre-commit//pre-commit/hook:defs.bzl", "pre_commit_hook") +load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target") + +alias( + name = "exe", + actual = select( + { + "@toolchain_utils//toolchain/constraint:amd64-linux": "@yamlfmt-amd64-linux//:yamlfmt", + "@toolchain_utils//toolchain/constraint:arm64-linux": "@yamlfmt-arm64-linux//:yamlfmt", + "@toolchain_utils//toolchain/constraint:amd64-macos": "@yamlfmt-amd64-macos//:yamlfmt", + "@toolchain_utils//toolchain/constraint:arm64-macos": "@yamlfmt-arm64-macos//:yamlfmt", + "@toolchain_utils//toolchain/constraint:amd64-windows": "@yamlfmt-amd64-windows//:yamlfmt.exe", + "@toolchain_utils//toolchain/constraint:arm64-windows": "@yamlfmt-arm64-windows//:yamlfmt.exe", + }, + no_match_error = "No hermetic `yamlfmt` found for `//pre-commit/hook/yamlfmt:cli`. Please set it to a hermetic `yamlfmt` download in `MODULE.bazel` for the current host platform.", + ), +) + +toolchain_symlink_target( + name = "cli", + target = ":exe", +) + +pre_commit_hook( + name = "yamlfmt", + src = ":cli", + description = "Performs formatting with `yamlfmt` against yaml files.", + stages = ["@pre-commit//pre-commit/stage:pre-commit"], + summary = "Format yaml files with `yamlfmt`", + types = ["@pre-commit//pre-commit/tag:yaml"], + visibility = ["//visibility:public"], +) -- GitLab From 7bd976003d382e3fd06f0f3c42970eefdd6b0223 Mon Sep 17 00:00:00 2001 From: tomsht01 Date: Wed, 30 Jul 2025 10:33:46 +0300 Subject: [PATCH 2/5] chore: update 'pre-commit' to v1.0.8 --- .bazelrc | 2 +- MODULE.bazel | 2 +- MODULE.bazel.lock | 10 +++++----- e2e/.bazelrc | 2 +- e2e/MODULE.bazel.lock | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.bazelrc b/.bazelrc index 7047ec0..74fadee 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,6 +1,6 @@ # Use pre-release registry. Remove when available in BCR common --registry https://bcr.bazel.build -common --registry=https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads +common --registry=https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads # Enable hermetic `rules_python` common --@rules_python//python/config_settings:bootstrap_impl=script diff --git a/MODULE.bazel b/MODULE.bazel index 86a5d6e..8702aaf 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -3,7 +3,7 @@ module( ) bazel_dep(name = "rules_license", version = "1.0.0") -bazel_dep(name = "pre-commit", version = "1.0.7") +bazel_dep(name = "pre-commit", version = "1.0.8") bazel_dep(name = "buildifier_prebuilt", version = "8.0.0") bazel_dep(name = "download_utils", version = "1.0.1") bazel_dep(name = "toolchain_utils", version = "1.2.0") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 5574eee..89e79c2 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -61,7 +61,7 @@ "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", - "https://bcr.bazel.build/modules/pre-commit/1.0.7/MODULE.bazel": "not found", + "https://bcr.bazel.build/modules/pre-commit/1.0.8/MODULE.bazel": "not found", "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", @@ -160,9 +160,9 @@ "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79", "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d", "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198", - "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads/bazel_registry.json": "not found", - "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads/modules/pre-commit/1.0.7/MODULE.bazel": "635e5074e8716bb2ebab32001987887331cd2dc17dc38d373e9b1f8f977c8716", - "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads/modules/pre-commit/1.0.7/source.json": "0b06736dfaa3e6314b254d1ae6ef0d05bc8ac9eb95bc9f4e388d2c0d1a66eca4" + "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads/bazel_registry.json": "not found", + "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads/modules/pre-commit/1.0.8/MODULE.bazel": "2e6bf5e28f303073347e2fe71c8ef3cc5bf01c702ddd626b86dcf83c164b1d10", + "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads/modules/pre-commit/1.0.8/source.json": "b1e520be0b43347ad6f4e39621a5ba3fe0a4ee8c6fe473890cd2558f70a679a2" }, "selectedYankedVersions": {}, "moduleExtensions": { @@ -537,7 +537,7 @@ "@@rules_python+//python/extensions:pip.bzl%pip": { "general": { "bzlTransitiveDigest": "ouX/B418vzXubGa7sZUg0SiHVVe359gqb//X5Kx/AKE=", - "usagesDigest": "oOdEFORIME6tzjX1sYH0t2i1GvEUDpIWV+z+pbmza60=", + "usagesDigest": "FkBDU3XFn679HGtb25N87QrB5boXKAyA35hKXKSriUk=", "recordedFileInputs": { "@@pre-commit+//pre-commit/config/requirements/lock.txt": "c4df528d05090e2268c3f64b30c016de5175939606c1ebc14088f888f5d93dd0", "@@pre-commit+//pre-commit/hook/requirements/lock.txt": "5f20fd61af75464158a62d2d3739cefca20d6963130c6cb37e345bcfef567424", diff --git a/e2e/.bazelrc b/e2e/.bazelrc index 38a4b55..7eba8bc 100644 --- a/e2e/.bazelrc +++ b/e2e/.bazelrc @@ -1,6 +1,6 @@ # Use pre-release registry. Remove when available in BCR common --registry https://bcr.bazel.build -common --registry=https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads +common --registry=https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads # Enable hermetic `rules_python` common --@rules_python//python/config_settings:bootstrap_impl=script diff --git a/e2e/MODULE.bazel.lock b/e2e/MODULE.bazel.lock index d2c8dfc..f0ac20b 100644 --- a/e2e/MODULE.bazel.lock +++ b/e2e/MODULE.bazel.lock @@ -61,7 +61,7 @@ "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", - "https://bcr.bazel.build/modules/pre-commit/1.0.7/MODULE.bazel": "not found", + "https://bcr.bazel.build/modules/pre-commit/1.0.8/MODULE.bazel": "not found", "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", @@ -160,9 +160,9 @@ "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/MODULE.bazel": "af322bc08976524477c79d1e45e241b6efbeb918c497e8840b8ab116802dda79", "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.3/source.json": "2be409ac3c7601245958cd4fcdff4288be79ed23bd690b4b951f500d54ee6e7d", "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198", - "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads/bazel_registry.json": "not found", - "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads/modules/pre-commit/1.0.7/MODULE.bazel": "635e5074e8716bb2ebab32001987887331cd2dc17dc38d373e9b1f8f977c8716", - "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.7/downloads/modules/pre-commit/1.0.7/source.json": "0b06736dfaa3e6314b254d1ae6ef0d05bc8ac9eb95bc9f4e388d2c0d1a66eca4" + "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads/bazel_registry.json": "not found", + "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads/modules/pre-commit/1.0.8/MODULE.bazel": "2e6bf5e28f303073347e2fe71c8ef3cc5bf01c702ddd626b86dcf83c164b1d10", + "https://gitlab.arm.com/bazel/pre-commit/-/releases/v1.0.8/downloads/modules/pre-commit/1.0.8/source.json": "b1e520be0b43347ad6f4e39621a5ba3fe0a4ee8c6fe473890cd2558f70a679a2" }, "selectedYankedVersions": {}, "moduleExtensions": { -- GitLab From 1ea43b5b70219420f6d3108c442d0120b2c158a2 Mon Sep 17 00:00:00 2001 From: tomsht01 Date: Wed, 30 Jul 2025 10:36:41 +0300 Subject: [PATCH 3/5] chore: add yamlfmt hook and run hooks --- .gitlab-ci.yml | 10 +- BUILD.bazel | 1 + hooks/.pre-commit-config.yaml | 183 +++++++++++++++++----------------- 3 files changed, 99 insertions(+), 95 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9c84326..b9139c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,13 +11,11 @@ include: - 7.4.0 - 7.x - 8.2.1 - hooks: - extends: .job - stage: .pre - script: - - bazelisk run -- hooks - + extends: .job + stage: .pre + script: + - bazelisk run -- hooks default: tags: - arm64 diff --git a/BUILD.bazel b/BUILD.bazel index a05d8b4..e0f0176 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -27,6 +27,7 @@ pre_commit_hooks( "//ruff", "//shellcheck", "//shfmt", + "//yamlfmt", ], visibility = ["//visibility:public"], ) diff --git a/hooks/.pre-commit-config.yaml b/hooks/.pre-commit-config.yaml index 7d25ccd..32ddec5 100644 --- a/hooks/.pre-commit-config.yaml +++ b/hooks/.pre-commit-config.yaml @@ -1,93 +1,98 @@ # Regenerate with `bazel run -- //hooks:config`. Do not edit minimum_pre_commit_version: 2.18.0 default_install_hook_types: -- pre-commit + - pre-commit repos: -- repo: local - hooks: - - id: //buildifier:format - name: Format Bazel files - description: Will load a `.buildifier.json` at the root of the workspace for extra - configuration. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //buildifier:format - types_or: - - bazel - - id: //buildifier:lint - name: Lint Bazel files - description: Will load a `.buildifier.json` at the root of the workspace for extra - configuration. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //buildifier:lint - types_or: - - bazel - - id: //ruff:check - name: Check Python files with `ruff` - description: Performs checks with `ruff` against Python files. Will read a `ruff.toml` - for configuration. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //ruff:check - types: - - python - - id: //ruff:format - name: Format Python files with `ruff` - description: Performs formatting with `ruff` against Python files. Will read a - `ruff.toml` for configuration. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //ruff:format - types: - - python - - id: //clang-format - name: Format various file types with `clang-format` - description: Performs formatting using `clang-format` on various file types. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //clang-format - types_or: - - c - - c++ - - id: //shellcheck - name: Lint Shell files with `shellcheck` - description: Performs linting with `shellcheck` against Shell files. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //shellcheck - types: - - shell - - id: //shfmt - name: Format Shell files with `shfmt` - description: Performs formatting with `shfmt` against Shell files. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //shfmt - types: - - shell - - id: //hooks:config - name: Update `pre-commit` config - description: Keeps the `.pre-commit-config.yaml` in sync with any changes to the - `pre_commit_config` rule. - language: system - require_serial: true - stages: - - pre-commit - entry: bazel run --config=pre-commit -- //hooks:config - pass_filenames: false - files: ^(MODULE.bazel.lock|hooks/BUILD.bazel)$ + - repo: local + hooks: + - id: //buildifier:format + name: Format Bazel files + description: Will load a `.buildifier.json` at the root of the workspace for extra configuration. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //buildifier:format + types_or: + - bazel + - id: //buildifier:lint + name: Lint Bazel files + description: Will load a `.buildifier.json` at the root of the workspace for extra configuration. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //buildifier:lint + types_or: + - bazel + - id: //ruff:check + name: Check Python files with `ruff` + description: Performs checks with `ruff` against Python files. Will read a `ruff.toml` for configuration. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //ruff:check + types: + - python + - id: //ruff:format + name: Format Python files with `ruff` + description: Performs formatting with `ruff` against Python files. Will read a `ruff.toml` for configuration. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //ruff:format + types: + - python + - id: //clang-format + name: Format various file types with `clang-format` + description: Performs formatting using `clang-format` on various file types. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //clang-format + types_or: + - c + - c++ + - id: //shellcheck + name: Lint Shell files with `shellcheck` + description: Performs linting with `shellcheck` against Shell files. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //shellcheck + types: + - shell + - id: //shfmt + name: Format Shell files with `shfmt` + description: Performs formatting with `shfmt` against Shell files. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //shfmt + types: + - shell + - id: //yamlfmt + name: Format yaml files with `yamlfmt` + description: Performs formatting with `yamlfmt` against yaml files. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //yamlfmt + types: + - yaml + - id: //hooks:config + name: Update `pre-commit` config + description: Keeps the `.pre-commit-config.yaml` in sync with any changes to the `pre_commit_config` rule. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //hooks:config + pass_filenames: false + files: ^(MODULE.bazel.lock|hooks/BUILD.bazel)$ -- GitLab From 455199bd4dada58f31665b26044d2ee3b3b438c1 Mon Sep 17 00:00:00 2001 From: tomsht01 Date: Wed, 30 Jul 2025 11:50:17 +0300 Subject: [PATCH 4/5] chore: add .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..d31fa0a --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# yamlfmt hook changes +1ea43b5b70219420f6d3108c442d0120b2c158a2 -- GitLab From beba46223485ebd26a1215f9a177b98781ea1733 Mon Sep 17 00:00:00 2001 From: tomsht01 Date: Mon, 30 Jun 2025 14:52:26 +0300 Subject: [PATCH 5/5] test: add yamlfmt e2e --- e2e/yamlfmt/BUILD.bazel | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 e2e/yamlfmt/BUILD.bazel diff --git a/e2e/yamlfmt/BUILD.bazel b/e2e/yamlfmt/BUILD.bazel new file mode 100644 index 0000000..1cfff56 --- /dev/null +++ b/e2e/yamlfmt/BUILD.bazel @@ -0,0 +1,9 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") + +build_test( + name = "yamlfmt", + size = "small", + targets = [ + "@pre-commit-hooks//yamlfmt", + ], +) -- GitLab