Skip to content

Commit 20f66cc

Browse files
authored
Support publishing pre-release versions (#2371)
* Use new publishPreRelease parameter to control this setting * Re-structure pipeline for ease of understanding * Move from Node 12 -> 14 for builds * Add pre-release preparation script to gulpfile Signed-off-by: Shi Chen <[email protected]>
1 parent c106d9d commit 20f66cc

File tree

2 files changed

+125
-62
lines changed

2 files changed

+125
-62
lines changed

Jenkinsfile

+101-62
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,81 @@
11
#!/usr/bin/env groovy
22

33
def installBuildRequirements(){
4-
def nodeHome = tool 'nodejs-12.13.1'
4+
def nodeHome = tool 'nodejs-14.19.1'
55
env.PATH="${env.PATH}:${nodeHome}/bin"
66
sh "npm install -g typescript"
7-
sh 'npm install -g "vsce@<2"'
7+
sh 'npm install -g "vsce"'
88
}
99

1010
def buildVscodeExtension(){
1111
sh "npm install"
1212
sh "npm run vscode:prepublish"
1313
}
1414

15-
node('rhel8'){
16-
stage 'Build JDT LS'
17-
18-
env.JAVA_HOME="${tool 'openjdk-11'}"
19-
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
20-
sh 'java -version'
21-
22-
git url: 'https://github.com/eclipse/eclipse.jdt.ls.git'
23-
sh "./mvnw clean verify -B -U -e -Pserver-distro -Dtycho.disableP2Mirrors=true -DskipTests -P!jboss-maven-repos,!redhat-ga-repository,!redhat-ea-repository"
24-
25-
def files = findFiles(glob: '**/org.eclipse.jdt.ls.product/distro/**.tar.gz')
26-
stash name: 'server_distro', includes :files[0].path
15+
def packageSpecificExtensions() {
16+
stage "Package platform specific vscode-java"
17+
def platforms = ["win32-x64", "linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64"]
18+
def embeddedJRE = 17
19+
for(platform in platforms){
20+
sh "npx gulp download_jre --target ${platform} --javaVersion ${embeddedJRE}"
21+
if (publishPreRelease.equals('true')) {
22+
sh "vsce package --pre-release --target ${platform} -o java-${platform}-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
23+
} else {
24+
sh "vsce package --target ${platform} -o java-${platform}-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
25+
}
26+
}
2727
}
2828

29-
node('rhel8'){
30-
env.JAVA_HOME="${tool 'openjdk-11'}"
31-
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
32-
stage 'Checkout vscode-java code'
33-
deleteDir()
34-
git url: 'https://github.com/redhat-developer/vscode-java.git'
35-
36-
stage 'install vscode-java build requirements'
37-
installBuildRequirements()
29+
def packageExtensions() {
30+
if (publishPreRelease.equals('true')) {
31+
// for pre-release versions we only package platform specific extensions
32+
stage "replace extension version"
33+
sh "npx gulp prepare_pre_release"
3834

39-
stage 'Build vscode-java'
40-
buildVscodeExtension()
41-
unstash 'server_distro'
42-
def files = findFiles(glob: '**/org.eclipse.jdt.ls.product/distro/**.tar.gz')
43-
sh "rm -rf ./out"
44-
sh "mkdir ./server"
45-
sh "tar -xvzf ${files[0].path} -C ./server"
35+
def packageJson = readJSON file: 'package.json'
36+
env.EXTENSION_VERSION = "${packageJson.version}"
4637

47-
stage "Package vscode-java"
48-
def packageJson = readJSON file: 'package.json'
49-
env.EXTENSION_VERSION = "${packageJson.version}"
50-
sh "vsce package -o java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
38+
packageSpecificExtensions()
39+
} else {
40+
stage "package generic version"
41+
def packageJson = readJSON file: 'package.json'
42+
env.EXTENSION_VERSION = "${packageJson.version}"
5143

52-
stage 'Test vscode-java for staging'
53-
wrap([$class: 'Xvnc']) {
54-
sh "npm run compile" //compile the test code too
55-
env.SKIP_COMMANDS_TEST="true"
56-
sh "npm test --silent"
57-
}
44+
sh "vsce package -o java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
5845

59-
def vsix = findFiles(glob: '**.vsix')
60-
stash name:'vsix', includes:vsix[0].path
46+
def vsix = findFiles(glob: '**.vsix')
47+
stash name:'vsix', includes:vsix[0].path
6148

62-
// Package platform specific versions
63-
stage "Package platform specific vscode-java"
64-
def platforms = ["win32-x64", "linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64"]
65-
def embeddedJRE = 17
66-
for(platform in platforms){
67-
sh "npx gulp download_jre --target ${platform} --javaVersion ${embeddedJRE}"
68-
sh "vsce package --target ${platform} -o java-${platform}-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
69-
}
70-
stash name:'platformVsix', includes:'java-win32-*.vsix,java-linux-*.vsix,java-darwin-*.vsix'
49+
packageSpecificExtensions()
50+
stash name:'platformVsix', includes:'java-win32-*.vsix,java-linux-*.vsix,java-darwin-*.vsix'
7151

72-
stage 'Upload vscode-java to staging'
73-
def artifactDir = "java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}"
74-
sh "mkdir ${artifactDir}"
75-
sh "mv *.vsix ${artifactDir}"
52+
stage 'Upload vscode-java to staging'
53+
def artifactDir = "java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}"
54+
sh "mkdir ${artifactDir}"
55+
sh "mv *.vsix ${artifactDir}"
7656

77-
sh "sftp ${UPLOAD_LOCATION}/jdt.ls/staging <<< \$'mkdir ${artifactDir}\nput -r ${artifactDir}'"
78-
// Clean up build vsix
79-
sh "rm -rf ${artifactDir}"
57+
sh "sftp ${UPLOAD_LOCATION}/jdt.ls/staging <<< \$'mkdir ${artifactDir}\nput -r ${artifactDir}'"
58+
// Clean up build vsix
59+
sh "rm -rf ${artifactDir}"
60+
}
8061
}
8162

82-
node('rhel8'){
83-
if(publishToMarketPlace.equals('true')){
63+
def publishExtensions() {
64+
if (publishPreRelease.equals('true')) {
65+
stage "publish generic version"
66+
withCredentials([[$class: 'StringBinding', credentialsId: 'vscode_java_marketplace', variable: 'TOKEN']]) {
67+
sh 'vsce publish --pre-release -p ${TOKEN} --target win32-ia32 win32-arm64 linux-armhf alpine-x64 alpine-arm64'
68+
}
69+
70+
stage "publish specific version"
71+
// for pre-release versions, vsixs are not stashed and kept in project folder
72+
withCredentials([[$class: 'StringBinding', credentialsId: 'vscode_java_marketplace', variable: 'TOKEN']]) {
73+
def platformVsixes = findFiles(glob: '**.vsix')
74+
for(platformVsix in platformVsixes){
75+
sh 'vsce publish -p ${TOKEN}' + " --packagePath ${platformVsix.path}"
76+
}
77+
}
78+
} else if (publishToMarketPlace.equals('true')) {
8479
timeout(time:5, unit:'DAYS') {
8580
input message:'Approve deployment?', submitter: 'fbricon,rgrunber'
8681
}
@@ -89,7 +84,7 @@ node('rhel8'){
8984
unstash 'vsix'
9085
def vsix = findFiles(glob: '**.vsix')
9186
// Open-vsx Marketplace
92-
sh 'npm install -g "ovsx@<0.3.0"'
87+
sh 'npm install -g "ovsx"'
9388
withCredentials([[$class: 'StringBinding', credentialsId: 'open-vsx-access-token', variable: 'OVSX_TOKEN']]) {
9489
sh 'ovsx publish -p ${OVSX_TOKEN}' + " ${vsix[0].path}"
9590
}
@@ -119,5 +114,49 @@ node('rhel8'){
119114

120115
// copy this stable build to Akamai-mirrored /static/ URL, so staging can be cleaned out more easily
121116
sh "sftp ${UPLOAD_LOCATION}/static/jdt.ls/stable/ <<< \$'mkdir ${artifactDir}\nput -r ${artifactDir}'"
122-
}// if publishToMarketPlace
117+
}
118+
}
119+
120+
node('rhel8'){
121+
stage 'Build JDT LS'
122+
123+
env.JAVA_HOME="${tool 'openjdk-11'}"
124+
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
125+
sh 'java -version'
126+
127+
git url: 'https://github.com/eclipse/eclipse.jdt.ls.git'
128+
sh "./mvnw clean verify -B -U -e -Pserver-distro -Dtycho.disableP2Mirrors=true -DskipTests -P!jboss-maven-repos,!redhat-ga-repository,!redhat-ea-repository"
129+
130+
def files = findFiles(glob: '**/org.eclipse.jdt.ls.product/distro/**.tar.gz')
131+
stash name: 'server_distro', includes :files[0].path
132+
}
133+
134+
node('rhel8'){
135+
env.JAVA_HOME="${tool 'openjdk-11'}"
136+
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
137+
stage 'Checkout vscode-java code'
138+
deleteDir()
139+
git url: 'https://github.com/redhat-developer/vscode-java.git'
140+
141+
stage 'install vscode-java build requirements'
142+
installBuildRequirements()
143+
144+
stage 'Build vscode-java'
145+
buildVscodeExtension()
146+
unstash 'server_distro'
147+
def files = findFiles(glob: '**/org.eclipse.jdt.ls.product/distro/**.tar.gz')
148+
sh "rm -rf ./out"
149+
sh "mkdir ./server"
150+
sh "tar -xvzf ${files[0].path} -C ./server"
151+
152+
stage 'Test vscode-java for staging'
153+
wrap([$class: 'Xvnc']) {
154+
sh "npm run compile" //compile the test code too
155+
env.SKIP_COMMANDS_TEST="true"
156+
sh "npm test --silent"
157+
}
158+
159+
packageExtensions()
160+
161+
publishExtensions()
123162
}

gulpfile.js

+24
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,23 @@ gulp.task('clean_test_folder', function(done) {
177177
done();
178178
});
179179

180+
gulp.task('prepare_pre_release', function(done) {
181+
const json = JSON.parse(fse.readFileSync("./package.json").toString());
182+
const stableVersion = json.version.match(/(\d+)\.(\d+)\.(\d+)/);
183+
const major = stableVersion[1];
184+
const minor = stableVersion[2];
185+
const date = new Date();
186+
const month = date.getMonth() + 1;
187+
const day = date.getDate();
188+
const hours = date.getHours();
189+
const patch = `${date.getFullYear()}${prependZero(month)}${prependZero(day)}${prependZero(hours)}`;
190+
const insiderPackageJson = Object.assign(json, {
191+
version: `${major}.${minor}.${patch}`,
192+
});
193+
fse.writeFileSync("./package.json", JSON.stringify(insiderPackageJson, null, 2));
194+
done();
195+
});
196+
180197
function isWin() {
181198
return /^win/.test(process.platform);
182199
}
@@ -192,3 +209,10 @@ function isLinux() {
192209
function mvnw() {
193210
return isWin()?"mvnw.cmd":"./mvnw";
194211
}
212+
213+
function prependZero(number) {
214+
if (number > 99) {
215+
throw "Unexpected value to prepend with zero";
216+
}
217+
return `${number < 10 ? "0" : ""}${number}`;
218+
}

0 commit comments

Comments
 (0)