aboutsummaryrefslogtreecommitdiff
path: root/build-logic/automation-plugins/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'build-logic/automation-plugins/src/main')
-rw-r--r--build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.git-hooks.gradle.kts12
-rw-r--r--build-logic/automation-plugins/src/main/kotlin/com.github.android-password-store.gradle.gradle.kts12
-rw-r--r--build-logic/automation-plugins/src/main/kotlin/tasks/GitHooks.kt46
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,
+ )
+ )
+ }
+}