From c3279e65b74c0fc7c38cdf13a4b98e69b5241254 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 14 Nov 2021 12:10:53 +0530 Subject: build-logic: add automation convention plugins --- ...hub.android-password-store.git-hooks.gradle.kts | 12 ++++++ ...github.android-password-store.gradle.gradle.kts | 12 ++++++ .../src/main/kotlin/tasks/GitHooks.kt | 46 ++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.git-hooks.gradle.kts create mode 100644 build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.gradle.gradle.kts create mode 100644 build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt (limited to 'build-logic') diff --git a/build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.git-hooks.gradle.kts b/build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.git-hooks.gradle.kts new file mode 100644 index 00000000..6f661a6a --- /dev/null +++ b/build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.git-hooks.gradle.kts @@ -0,0 +1,12 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +import tasks.GitHooks + +tasks.register("installGitHooks") { + val projectDirectory = layout.projectDirectory + hookScript.set(projectDirectory.file("scripts/pre-push-hook.sh").asFile.readText()) + hookOutput.set(projectDirectory.file(".git/hooks/pre-push").asFile) +} diff --git a/build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.gradle.gradle.kts b/build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.gradle.gradle.kts new file mode 100644 index 00000000..b66631c6 --- /dev/null +++ b/build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.gradle.gradle.kts @@ -0,0 +1,12 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +import org.gradle.api.tasks.wrapper.Wrapper +import org.gradle.kotlin.dsl.withType + +tasks.withType { + gradleVersion = "7.3" + distributionSha256Sum = "de8f52ad49bdc759164f72439a3bf56ddb1589c4cde802d3cec7d6ad0e0ee410" +} diff --git a/build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt b/build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt new file mode 100644 index 00000000..ec045227 --- /dev/null +++ b/build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt @@ -0,0 +1,46 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package tasks + +import java.io.File +import java.nio.file.Files +import java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE +import java.nio.file.attribute.PosixFilePermission.GROUP_READ +import java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE +import java.nio.file.attribute.PosixFilePermission.OTHERS_READ +import java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE +import java.nio.file.attribute.PosixFilePermission.OWNER_READ +import java.nio.file.attribute.PosixFilePermission.OWNER_WRITE +import org.gradle.api.DefaultTask +import org.gradle.api.provider.Property +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +@CacheableTask +abstract class GitHooks : DefaultTask() { + @get:Input abstract val hookScript: Property + + @get:OutputFile abstract val hookOutput: Property + + @TaskAction + fun install() { + hookOutput.get().writeText(hookScript.get()) + Files.setPosixFilePermissions( + hookOutput.get().toPath(), + setOf( + OWNER_READ, + OWNER_WRITE, + OWNER_EXECUTE, + GROUP_READ, + GROUP_EXECUTE, + OTHERS_READ, + OTHERS_EXECUTE, + ) + ) + } +} -- cgit v1.2.3