forked from n8ebel/GitHubActionsAutomationSandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-hooks.gradle
36 lines (32 loc) · 1.02 KB
/
git-hooks.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Adapted from https://proandroiddev.com/ooga-chaka-git-hooks-to-enforce-code-quality-11ce8d0d23cb
*/
static def isLinuxOrMacOs() {
def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)
return osName.contains('linux') || osName.contains('mac os') || osName.contains('macos')
}
task copyGitHooks(type: Copy) {
description 'Copies the git hooks from scripts/git-hooks to the .git folder.'
from("${rootDir}/scripts/git-hooks/") {
include '**/*.sh'
rename '(.*).sh', '$1'
}
into "${rootDir}/.git/hooks"
onlyIf { isLinuxOrMacOs() }
}
task installGitHooks(type: Exec) {
description 'Installs the git hooks from scripts/git-hooks.'
group 'git hooks'
workingDir rootDir
commandLine 'chmod'
args '-R', '+x', '.git/hooks/'
dependsOn copyGitHooks
onlyIf { isLinuxOrMacOs() }
doLast {
logger.info('Git hooks installed successfully.')
}
}
afterEvaluate {
// We install the hook at the first occasion
tasks['clean'].dependsOn installGitHooks
}