build-logic: add automation convention plugins

This commit is contained in:
Harsh Shandilya 2021-11-14 12:10:53 +05:30
parent cfeca2d3ee
commit c3279e65b7
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
3 changed files with 70 additions and 0 deletions

View file

@ -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)
}

View file

@ -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"
}

View file

@ -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,
)
)
}
}