diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-11-14 12:10:53 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-11-16 00:22:17 +0530 |
commit | c3279e65b74c0fc7c38cdf13a4b98e69b5241254 (patch) | |
tree | 60fe198ec4999d0b5b2d5d8e5d1bf1a16eaf3d45 /build-logic/automation-plugins/src/main | |
parent | cfeca2d3ee149f72d3af18844a78f76aaa9fa790 (diff) |
build-logic: add automation convention plugins
Diffstat (limited to 'build-logic/automation-plugins/src/main')
3 files changed, 70 insertions, 0 deletions
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<GitHooks>("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<Wrapper> { + 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<String> + + @get:OutputFile abstract val hookOutput: Property<File> + + @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, + ) + ) + } +} |