This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
publish.gradle
142 lines (125 loc) · 4.43 KB
/
publish.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
ext {
websiteUrl = 'https://github.com/novoda/gradle-static-analysis-plugin'
}
version = '0.5.2'
String tag = "v$project.version"
groovydoc.docTitle = 'Static Analysis Plugin'
apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'com.novoda.bintray-release'
publish {
userOrg = 'novoda'
groupId = 'com.novoda'
artifactId = 'gradle-static-analysis-plugin'
publishVersion = project.version
website = websiteUrl
}
apply plugin: 'com.novoda.build-properties'
buildProperties {
secrets {
file(rootProject.file('secrets.properties'), '''
This file should contain:
- git.username: the username used to push to the repo
- git.password: the password used to push to the repo
- gradle.publish.key: the key to publish the plugin to the Gradle Plugins Repository
- gradle.publish.secret: the secret to publish the plugin to the Gradle Plugins Repository
''')
}
}
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'org.ajoberstar.github-pages'
githubPages {
commitMessage = "Deploy groovydoc for release $tag"
pages {
from groovydoc.destinationDir
into "docs/${project.version}"
}
}
pluginBundle {
website = websiteUrl
vcsUrl = websiteUrl
description = 'A Gradle plugin to easily apply the same setup of static analysis tools across different Android, Java or Kotlin projects.'
tags = ['java', 'kotlin', 'android', 'static analysis', 'code quality']
plugins {
gradleStaticAnalysisPlugin {
id = 'com.novoda.static-analysis'
displayName = 'Gradle static analysis plugin'
}
}
}
task prepareGhCredentials {
description = 'Prepare GitHub credentials'
group = 'release'
doLast {
String username = buildProperties.env['GITHUB_USERNAME'].or(buildProperties.secrets['github.username']).string
String password = buildProperties.env['GITHUB_TOKEN'].or(buildProperties.secrets['github.password']).string
System.properties['org.ajoberstar.grgit.auth.username'] = username
System.properties['org.ajoberstar.grgit.auth.password'] = password
}
}
prepareGhPages.dependsOn groovydoc
publishGhPages.dependsOn prepareGhCredentials
task prepareGradlePluginsRepoRelease {
doLast {
def key = buildProperties.env['GRADLE_PLUGINS_REPO_KEY'] | buildProperties.secrets['gradle.publish.key']
def secret = buildProperties.env['GRADLE_PLUGINS_REPO_SECRET'] | buildProperties.secrets['gradle.publish.secret']
System.properties['gradle.publish.key'] = key.string
System.properties['gradle.publish.secret'] = secret.string
}
}
task prepareRelease {
description = 'Prepare changelog and tag for release'
group = 'release'
dependsOn prepareGhPages, prepareGhCredentials, prepareGradlePluginsRepoRelease
doLast {
String changelog = extractChangelog()
grgit.tag.add {
name = tag
message = "Release $tag\n\n$changelog"
}
}
}
String extractChangelog() {
String fullChangelog = rootProject.file('CHANGELOG.md').text
def latestChangelog = (fullChangelog =~ /\[Version ${project.version}.*\n-*([\s\S]*?)\[Version.*\n-*/)
if (latestChangelog.size() > 0) {
return latestChangelog[0][1].trim()
}
def firstChangelog = (fullChangelog =~ /\[Version ${project.version}.*\n-*([\s\S]*)/)
if (firstChangelog.size() > 0) {
return firstChangelog[0][1].trim()
}
throw new GradleException("No changelog found for version $project.version")
}
task printChangelog {
group = 'help'
description = "Print the provisional changelog for version $project.version"
doLast {
println "\nChangelog for version $project.version:\n${extractChangelog()}\n"
}
}
task publishArtifact {
description = "Publish artifact for plugin version: $tag"
group = 'release'
project.afterEvaluate { dependsOn bintrayUpload }
mustRunAfter prepareRelease
}
task publishGroovydoc {
description = "Deploy groovydoc for plugin version: $tag"
group = 'release'
dependsOn publishGhPages
mustRunAfter publishArtifact
}
task publishRelease {
description = "Publish release for plugin version: $tag"
group = 'release'
if (project.hasProperty('dryRun') && project['dryRun'] == 'false') {
dependsOn prepareRelease, publishArtifact, publishGroovydoc, publishPlugins
doLast {
grgit.push {
tags = true
}
}
} else {
dependsOn publishArtifact
}
}