forked from rstudio/rstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.groovy
202 lines (178 loc) · 6.02 KB
/
utils.groovy
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
// Utility methods for Jenkins pipelines
/**
* Returns true if branch has changes in the specified path with the target branch.
* If invertMatch is true, returns true if branch has changes that do not match the specified path.
*/
boolean hasChangesIn(String module, boolean invertMatch = false) {
sh "echo 'Comparing changes in ${module} with ${env.CHANGE_TARGET}..${env.BRANCH_NAME}'"
grepArgs = invertMatch ? '-v' : ''
mergeBase = sh(
returnStdout: true, script: "git merge-base origin/${env.BRANCH_NAME} origin/${env.CHANGE_TARGET}").trim()
return !env.CHANGE_TARGET ||
sh(
returnStatus: true,
script: "git diff --name-only --quiet ${mergeBase}..origin/${env.BRANCH_NAME} | grep ${grepArgs} \"${module}\"") == 1
}
/**
* Adds a remote reference to the specified branch.
*/
void addRemoteRef(String branchName) {
withCredentials([gitUsernamePassword(credentialsId: 'github-rstudio-jenkins', gitToolName: 'Default')]) {
sh "git config --add remote.origin.fetch +refs/heads/${branchName}:refs/remotes/origin/${branchName}"
sh "git fetch --no-tags --force --progress ${GIT_URL} refs/heads/${branchName}:refs/remotes/origin/${branchName}"
}
}
/**
* Get Version.
* Does not work on windows.
*/
def getVersion(boolean isHourly) {
def buildType = ""
if(isHourly) {
buildType="--build-type=hourly"
}
def rstudioVersion = sh(
script: "docker/jenkins/rstudio-version.sh --patch=${params.RSTUDIO_VERSION_PATCH} ${buildType}",
returnStdout: true
).trim()
echo "RStudio build version: ${rstudioVersion}"
// Split on [-+] first to avoid having to worry about splitting out .pro<n>
def version = rstudioVersion.split('[-+]')
// extract major / minor /patch version
def majorComponents = version[0].split('\\.')
rstudioVersionMajor = majorComponents[0]
rstudioVersionMinor = majorComponents[1]
rstudioVersionPatch = majorComponents[2]
// Extract suffix
if (version.length > 2) {
rstudioVersionSuffix = '-' + version[1] + '+' + version[2]
}
else {
rstudioVersionSuffix = '+' + version[1]
}
return [rstudioVersion, rstudioVersionMajor, rstudioVersionMinor, rstudioVersionPatch, rstudioVersionSuffix]
}
def jenkins_user_build_args() {
def jenkins_uid = sh (script: 'id -u jenkins', returnStdout: true).trim()
def jenkins_gid = sh (script: 'id -g jenkins', returnStdout: true).trim()
return " --build-arg JENKINS_UID=${jenkins_uid} --build-arg JENKINS_GID=${jenkins_gid}"
}
/**
* Get the branch flower name from the version/RELEASE file
*/
def getFlower() {
return readFile(file: 'version/RELEASE').replaceAll(" ", "-").toLowerCase().trim()
}
/**
* Upload the package specified by packageFile to the location of destinationPath in the rstudio-ide-build S3 bucket.
* Sets the correct ACLs.
*/
def uploadPackageToS3(String packageFile, String destinationPath) {
s3Upload acl: 'BucketOwnerFullControl', bucket: "rstudio-ide-build", file: "${packageFile}", path: "${destinationPath}"
}
/**
* Upload javascript source maps to Sentry.
* Does not work on windows.
*/
def sentryUploadSourceMaps() {
def retryCount = 0
def ret = 1
while (retryCount < 5 && ret != 0) {
ret = sh returnStatus: true, script: 'sentry-cli --auth-token ${SENTRY_API_KEY} releases --org rstudio --project ide-backend files ' + RSTUDIO_VERSION + ' upload-sourcemaps --ext js --ext symbolMap --rewrite .'
echo "Return code: ${ret}"
if (ret != 0 && retryCount < 5) {
sleep time: 30, unit: 'SECONDS'
retryCount = retryCount + 1
}
}
}
/**
* Upload debug symbols to sentry. Symbol type should be dsym or elf.
* Does not work on windows.
*/
def sentryUpload(String symbolType) {
def retryCount = 0
def ret = 1
while (retryCount < 5 && ret != 0) {
ret = sh returnStatus: true, script: 'sentry-cli --auth-token ${SENTRY_API_KEY} upload-dif --org rstudio --project ide-backend -t ' + symbolType + ' .'
echo "Return code: ${ret}"
if (ret != 0 && retryCount < 5) {
sleep time: 30, unit: 'SECONDS'
retryCount = retryCount + 1
}
}
}
/**
* Publish a build to the dailies site.
* Does not work on windows.
*/
def publishToDailiesSite(String packageFile, String destinationPath, String urlPath = '') {
def channel = ''
if (!params.DAILY) {
channel = ' --channel Hourly'
}
if (urlPath == '')
{
urlPath = destinationPath
}
sh '${WORKSPACE}/docker/jenkins/publish-build.sh --pat ${GITHUB_LOGIN_PSW} ' +
channel +
' --version ' +
RSTUDIO_VERSION +
' --build ' +
destinationPath +
' --url https://s3.amazonaws.com/rstudio-ide-build/' +
urlPath +
'/' +
packageFile +
' --file ' +
packageFile
}
/**
* Convert an architecture to the operating specific version of that arch.
* amd64 -> x86_64 on non-Debian
* x86_64 -> amd64 on Debian
*/
def getArchForOs(String os, String arch) {
if ((arch == "amd64") && (os != "bionic") && (os != "jammy")) {
return "x86_64"
}
if ((arch == "x86_64") && ((os == "bionic") || (os == "jammy"))) {
return "amd64"
}
if (arch == "aarch64") {
return "arm64"
}
return arch
}
/**
* Gets environment variasbles needed for running the build on Linux and Mac.
* Does not work on windows.
*/
def getBuildEnv(boolean isHourly) {
def env = "RSTUDIO_VERSION_MAJOR=${RSTUDIO_VERSION_MAJOR} RSTUDIO_VERSION_MINOR=${RSTUDIO_VERSION_MINOR} RSTUDIO_VERSION_PATCH=${RSTUDIO_VERSION_PATCH} RSTUDIO_VERSION_SUFFIX=${RSTUDIO_VERSION_SUFFIX}"
if (isHourly) {
env = "${env} SCCACHE_ENABLED=1"
}
return env
}
/**
* Get the name of the product based on the type of build
*/
def getProductName() {
def name = FLAVOR.toLowerCase()
if (IS_PRO && name != "server") {
name = name + "-pro"
} else if (IS_PRO) {
name = "workbench"
}
return name
}
/**
* Upload dailiy redirects.
* Does not work on windows.
*/
def updateDailyRedirects(String path) {
sh 'docker/jenkins/publish-daily-binary.sh https://s3.amazonaws.com/rstudio-ide-build/' + path + ' ${RSTUDIO_ORG_PEM}'
}
return this