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
183 lines (159 loc) · 5.95 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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.novoda.build-properties'
buildProperties {
secrets {
using rootProject.file('secrets.properties')
description = '''
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
'''
}
cli {
using(project)
}
bintray {
def bintrayCredentials = {
boolean isDryRun = cli['dryRun'].or(true).boolean
return isDryRun ?
['bintrayRepo': 'n/a', 'bintrayUser': 'n/a', 'bintrayKey': 'n/a'] :
new File("${System.getenv('BINTRAY_PROPERTIES')}")
}
using(bintrayCredentials()).or(cli)
description = '''This should contain the following properties:
| - bintrayRepo: name of the repo of the organisation to deploy the artifacts to
| - bintrayUser: name of the account used to deploy the artifacts
| - bintrayKey: API key of the account used to deploy the artifacts
'''.stripMargin()
}
publish {
def generateVersion = {
boolean isSnapshot = cli['bintraySnapshot'].or(false).boolean
return isSnapshot ? "SNAPSHOT-${System.getenv('BUILD_NUMBER') ?: 'LOCAL'}" : project.version
}
using(['version': "${generateVersion()}"]).or(buildProperties.bintray)
}
}
apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'com.novoda.bintray-release'
publish {
userOrg = 'novoda'
repoName = 'maven'
groupId = 'com.novoda'
artifactId = 'gradle-static-analysis-plugin'
version = project.buildProperties.publish['version'].string
publishVersion = project.buildProperties.publish['version'].string
bintrayUser = project.buildProperties.publish['bintrayUser'].string
bintrayKey = project.buildProperties.publish['bintrayKey'].string
website = websiteUrl
}
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'
boolean isDryRun = buildProperties.cli['dryRun'].or(true).boolean
if (isDryRun) {
dependsOn publishArtifact
} else {
dependsOn publishArtifact
boolean isSnapshot = buildProperties.cli['bintraySnapshot'].or(false)
if (!isSnapshot) {
dependsOn prepareRelease, publishGroovydoc, publishPlugins
doLast {
grgit.push {
tags = true
}
}
}
}
}