-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathreleaser.gradle
122 lines (110 loc) · 4.27 KB
/
releaser.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
/*
* Copyright (c) 2011-2021 VMware Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.temporal.ChronoField
if (rootProject.hasProperty("releaserDryRun") && rootProject.findProperty("releaserDryRun") != "false") {
println "Adding MavenLocal() for benefit of releaser dry run"
rootProject.repositories {
mavenLocal()
}
}
/**
* return a specific property value, assuming all the provided projects have it with the
* same value, or throw if multiple values are found
*/
private static def getUniquePropertyPerProject(Set<Project> projects, String property) {
//"multimap": dictionary of lists
def props = [:].withDefault {[]}
projects.each { props.get(it.findProperty(property)).add(it.name) }
if (props.size() != 1) {
throw new InvalidUserDataException("build defines multiple values for property `${property}`: ${props}")
}
return props.keySet().find()
}
//NOTE: this task is intended for rootProject with submodules
task groupId(group: "releaser helpers", description: "output the group id of submodules, checking there is only one") {
doLast {
println getUniquePropertyPerProject(rootProject.subprojects, "group")
}
}
task copyReadme(type: Copy, group: "releaser helpers", description: "copies the README in preparation for search and replace") {
from(rootProject.rootDir) {
include "README.md"
}
into rootProject.buildDir
}
task bumpVersionsInReadme(type: Copy, group: "releaser helpers", description: "replaces versions in README") {
def oldVersion = rootProject.findProperty("oldVersion")
def currentVersion = rootProject.findProperty("currentVersion")
def nextVersion = rootProject.findProperty("nextVersion")
def oldSnapshot = currentVersion + "-SNAPSHOT"
onlyIf { oldVersion != null && currentVersion != null && nextVersion != null }
dependsOn copyReadme
doLast {
println "Will replace $oldVersion with $currentVersion and $oldSnapshot with $nextVersion"
}
from(rootProject.buildDir) {
include 'README.md'
}
into rootProject.rootDir
filter { line -> line
.replace(oldVersion, currentVersion)
.replace(oldSnapshot, nextVersion)
}
}
String getOrGenerateBuildNumber() {
if (project.hasProperty("buildNumber")) {
return project.findProperty("buildNumber")
}
def ciNumber = System.getenv("GITHUB_RUN_NUMBER")
if (ciNumber != null) {
return ciNumber
}
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC)
long secondsInDay = now.toEpochSecond() - ZonedDateTime.now(ZoneOffset.UTC).withSecond(0).withHour(0).withMinute(0).toEpochSecond()
String buildNumber = "$version-${now.get(ChronoField.YEAR)}${now.get(ChronoField.MONTH_OF_YEAR).toString().padLeft(2,'0')}${now.get(ChronoField.DAY_OF_MONTH).toString().padLeft(2,'0')}@${secondsInDay}"
println "No buildNumber set, generated: $buildNumber"
return buildNumber
}
task printBuildNumber() {
doLast {
println getOrGenerateBuildNumber()
}
}
if (project.hasProperty("artifactory_publish_password")) {
configure(rootProject) { p ->
apply plugin: "com.jfrog.artifactory"
def buildNumber = getOrGenerateBuildNumber()
artifactory {
contextUrl = "${artifactory_publish_contextUrl}"
publish {
repository {
repoKey = "${artifactory_publish_repoKey}"
username = "${artifactory_publish_username}"
password = "${artifactory_publish_password}"
}
}
clientConfig.setIncludeEnvVars(false)
clientConfig.info.setBuildName('Reactor - Kafka')
clientConfig.info.setBuildNumber(buildNumber)
if (System.getenv("GITHUB_ACTIONS") == "true") {
clientConfig.info.setBuildUrl(System.getenv("GITHUB_SERVER_URL") + "/" + System.getenv("GITHUB_REPOSITORY") + "/actions/runs/" + System.getenv("GITHUB_RUN_ID"))
clientConfig.info.setVcsRevision(System.getenv("GITHUB_SHA"))
}
}
}
}