forked from earocorn/osh-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.gradle
159 lines (133 loc) · 4.79 KB
/
release.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
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.6.0'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1'
classpath 'org.kohsuke:github-api:1.132'
}
}
//apply plugin: org.sonarqube.gradle.SonarQubePlugin
apply plugin: org.ajoberstar.gradle.git.base.GrgitPlugin
/* Bintray was shutdown in Feb 2021 */
/*subprojects {
/*afterEvaluate { project ->
// only publish with bintray if credentials are configured
// and project is not a SNAPSHOT
if (project.hasProperty("bintray_user") && !project.version.endsWith('SNAPSHOT')) {
// bintray publishing options
bintray {
user = bintray_user
key = bintray_api_key
publications = ['mavenJava']
dryRun = false // whether to run this as dry-run, without deploying
publish = true // whether version should be auto published after an upload
override = true // whether to override version artifacts already published
pkg {
repo = 'osh'
name = rootProject.name
userOrg = 'sensiasoft'
if (rootProject.description != null)
desc = rootProject.description
websiteUrl = 'https://github.com/opensensorhub/' + rootProject.name
issueTrackerUrl = 'https://github.com/opensensorhub/' + rootProject.name + '/issues'
vcsUrl = 'git://github.com/opensensorhub/' + rootProject.name + '.git'
licenses = ['MPL-2.0']
labels = ['sensor', 'sensor hub', 'ogc', 'swe', 'iot']
publicDownloadNumbers = true
version {
name = rootProject.version
}
}
}
}
}
}*/
// this task checks that release conditions are met
task prerelease {
doLast {
println 'Current version is ' + version
println 'Current HEAD is ' + grgit.head().abbreviatedId
// check that we're on master branch
if (grgit.branch.current.name != 'master')
throw new GradleException('A release can only be done from the master branch. First merge your changes to master')
// check that current version is not a snapshot
if (version.endsWith('SNAPSHOT'))
throw new GradleException('Cannot release a SNAPSHOT. Please update the project version number')
// check that we don't have any snapshot dependencies
// check that there is no existing tag with this version
// this ensures version has been incremented since last release
def tags = grgit.tag.list()
tags.each {
if (it.name == 'v' + version)
throw new GradleException('Version ' + version + ' has already been released (existing tag)')
}
// check for uncommited files
def status = grgit.status()
if (!status.isClean()) {
throw new GradleException('Local version has uncommited changes')
}
}
}
// this task creates a Git tag
task releaseGit {
doLast {
// tag release version (after successful build)
println '> Adding release tag for version ' + version
grgit.tag.add {
name = 'v' + version
message = 'Release of version ' + version
}
// push new tag
println '> Pushing new tag to remote'
grgit.push(tags: true)
}
}
// this task creates a GitHub release
import org.kohsuke.github.*
task releaseGithub {
doLast {
println '> Publishing Release to GitHub'
GitHub gh = GitHub.connect(github_user, github_token);
GHRepository repo = gh.getRepository("opensensorhub/" + project.name);
// load release template
String text = ""
File templateFile = new File(rootDir, 'release-text.md')
if (templateFile.exists()) {
text = templateFile.text;
}
// find version milestone
def milestone = repo.listMilestones(GHIssueState.ALL).find {
it.title == 'v' + project.version
}
if (milestone == null) {
println 'No milestone found for release version ' + project.version
}
else {
// append issues fixed for this milestone
def issues = repo.getIssues(GHIssueState.CLOSED, milestone)
if (!issues.isEmpty())
text += "Resolved Issues:\n\n"
issues.each {
text += " * **#" + it.number + "** " + it.title + "\n"
}
println text
}
// publish new release
GHReleaseBuilder builder = repo.createRelease('v' + project.version);
builder.name(project.name + " v" + project.version)
.draft(true)
.body(text)
.create()
}
}
// release subtasks ordering
// prerelease > build > releaseGit > bintrayUpload > releaseGithub
task release
build.shouldRunAfter prerelease
releaseGit.dependsOn prerelease
releaseGit.dependsOn build
/*bintrayUpload.dependsOn releaseGit*/
releaseGithub.dependsOn releaseGit
release.dependsOn releaseGithub