From 4a0db0884dd72936f78f7b3fe91312399c57907c Mon Sep 17 00:00:00 2001 From: Mihail Mihov Date: Thu, 9 Jan 2025 11:29:50 +0200 Subject: [PATCH] ci: Add pre-commit yaml configuration. Remove previous files. Signed-off-by: Mihail Mihov --- .pre-commit-config.yaml | 20 +++++++++++++++++ build.gradle.kts | 47 ---------------------------------------- scripts/hooks/pre-commit | 8 ------- 3 files changed, 20 insertions(+), 55 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100644 build.gradle.kts delete mode 100644 scripts/hooks/pre-commit diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000000..be16c658092d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: check-added-large-files + - id: check-merge-conflict + - id: forbid-new-submodules + - repo: https://github.com/jguttman94/pre-commit-gradle + rev: v0.3.0 + hooks: + - id: gradle-task + args: ['-w', '-o', 'spotlessAppl'] + - repo: https://github.com/compilerla/conventional-pre-commit + rev: v2.4.0 + hooks: + - id: conventional-pre-commit + stages: [ commit-msg ] diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index d75b65c92699..000000000000 --- a/build.gradle.kts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2025 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -tasks.register("installGitHooks") { - group = "setup" - description = "Installs Git hooks" - - val gitDir = layout.projectDirectory.dir(".git") - val hookSource = layout.projectDirectory.file("scripts/hooks/pre-commit") - val hookDestination = gitDir.dir("hooks").file("pre-commit") - - doLast { - if (!gitDir.asFile.exists()) { - logger.warn(".git directory not found. Skipping Git hooks installation.") - return@doLast - } - - val hooksDir = gitDir.dir("hooks").asFile - if (!hooksDir.exists()) { - hooksDir.mkdirs() - } - - if (hookSource.asFile.exists()) { - hookSource.asFile.copyTo(hookDestination.asFile, overwrite = true) - hookDestination.asFile.setExecutable(true) - logger.lifecycle("Pre-commit hook installed at ${hookDestination.asFile.path}") - } else { - logger.error("Hook source file not found at ${hookSource.asFile.path}") - } - } -} - -// Ensure installGitHooks runs before the build task -tasks.named("build") { dependsOn("installGitHooks") } diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit deleted file mode 100644 index cc080f13ff2f..000000000000 --- a/scripts/hooks/pre-commit +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -echo "Running spotlessApply..." -./gradlew spotlessApply - -if [ $? -ne 0 ]; then - echo "spotlessApply failed. Please fix the issues before committing." - exit 1 -fi \ No newline at end of file