Skip to content

Commit

Permalink
Support publishing pre-release versions (#2371)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
CsCherrYY authored May 12, 2022
1 parent c106d9d commit 20f66cc
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 62 deletions.
163 changes: 101 additions & 62 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,86 +1,81 @@
#!/usr/bin/env groovy

def installBuildRequirements(){
def nodeHome = tool 'nodejs-12.13.1'
def nodeHome = tool 'nodejs-14.19.1'
env.PATH="${env.PATH}:${nodeHome}/bin"
sh "npm install -g typescript"
sh 'npm install -g "vsce@<2"'
sh 'npm install -g "vsce"'
}

def buildVscodeExtension(){
sh "npm install"
sh "npm run vscode:prepublish"
}

node('rhel8'){
stage 'Build JDT LS'

env.JAVA_HOME="${tool 'openjdk-11'}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
sh 'java -version'

git url: 'https://github.com/eclipse/eclipse.jdt.ls.git'
sh "./mvnw clean verify -B -U -e -Pserver-distro -Dtycho.disableP2Mirrors=true -DskipTests -P!jboss-maven-repos,!redhat-ga-repository,!redhat-ea-repository"

def files = findFiles(glob: '**/org.eclipse.jdt.ls.product/distro/**.tar.gz')
stash name: 'server_distro', includes :files[0].path
def packageSpecificExtensions() {
stage "Package platform specific vscode-java"
def platforms = ["win32-x64", "linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64"]
def embeddedJRE = 17
for(platform in platforms){
sh "npx gulp download_jre --target ${platform} --javaVersion ${embeddedJRE}"
if (publishPreRelease.equals('true')) {
sh "vsce package --pre-release --target ${platform} -o java-${platform}-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
} else {
sh "vsce package --target ${platform} -o java-${platform}-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
}
}
}

node('rhel8'){
env.JAVA_HOME="${tool 'openjdk-11'}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
stage 'Checkout vscode-java code'
deleteDir()
git url: 'https://github.com/redhat-developer/vscode-java.git'

stage 'install vscode-java build requirements'
installBuildRequirements()
def packageExtensions() {
if (publishPreRelease.equals('true')) {
// for pre-release versions we only package platform specific extensions
stage "replace extension version"
sh "npx gulp prepare_pre_release"

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

stage "Package vscode-java"
def packageJson = readJSON file: 'package.json'
env.EXTENSION_VERSION = "${packageJson.version}"
sh "vsce package -o java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}.vsix"
packageSpecificExtensions()
} else {
stage "package generic version"
def packageJson = readJSON file: 'package.json'
env.EXTENSION_VERSION = "${packageJson.version}"

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

def vsix = findFiles(glob: '**.vsix')
stash name:'vsix', includes:vsix[0].path
def vsix = findFiles(glob: '**.vsix')
stash name:'vsix', includes:vsix[0].path

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

stage 'Upload vscode-java to staging'
def artifactDir = "java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}"
sh "mkdir ${artifactDir}"
sh "mv *.vsix ${artifactDir}"
stage 'Upload vscode-java to staging'
def artifactDir = "java-${env.EXTENSION_VERSION}-${env.BUILD_NUMBER}"
sh "mkdir ${artifactDir}"
sh "mv *.vsix ${artifactDir}"

sh "sftp ${UPLOAD_LOCATION}/jdt.ls/staging <<< \$'mkdir ${artifactDir}\nput -r ${artifactDir}'"
// Clean up build vsix
sh "rm -rf ${artifactDir}"
sh "sftp ${UPLOAD_LOCATION}/jdt.ls/staging <<< \$'mkdir ${artifactDir}\nput -r ${artifactDir}'"
// Clean up build vsix
sh "rm -rf ${artifactDir}"
}
}

node('rhel8'){
if(publishToMarketPlace.equals('true')){
def publishExtensions() {
if (publishPreRelease.equals('true')) {
stage "publish generic version"
withCredentials([[$class: 'StringBinding', credentialsId: 'vscode_java_marketplace', variable: 'TOKEN']]) {
sh 'vsce publish --pre-release -p ${TOKEN} --target win32-ia32 win32-arm64 linux-armhf alpine-x64 alpine-arm64'
}

stage "publish specific version"
// for pre-release versions, vsixs are not stashed and kept in project folder
withCredentials([[$class: 'StringBinding', credentialsId: 'vscode_java_marketplace', variable: 'TOKEN']]) {
def platformVsixes = findFiles(glob: '**.vsix')
for(platformVsix in platformVsixes){
sh 'vsce publish -p ${TOKEN}' + " --packagePath ${platformVsix.path}"
}
}
} else if (publishToMarketPlace.equals('true')) {
timeout(time:5, unit:'DAYS') {
input message:'Approve deployment?', submitter: 'fbricon,rgrunber'
}
Expand All @@ -89,7 +84,7 @@ node('rhel8'){
unstash 'vsix'
def vsix = findFiles(glob: '**.vsix')
// Open-vsx Marketplace
sh 'npm install -g "ovsx@<0.3.0"'
sh 'npm install -g "ovsx"'
withCredentials([[$class: 'StringBinding', credentialsId: 'open-vsx-access-token', variable: 'OVSX_TOKEN']]) {
sh 'ovsx publish -p ${OVSX_TOKEN}' + " ${vsix[0].path}"
}
Expand Down Expand Up @@ -119,5 +114,49 @@ node('rhel8'){

// copy this stable build to Akamai-mirrored /static/ URL, so staging can be cleaned out more easily
sh "sftp ${UPLOAD_LOCATION}/static/jdt.ls/stable/ <<< \$'mkdir ${artifactDir}\nput -r ${artifactDir}'"
}// if publishToMarketPlace
}
}

node('rhel8'){
stage 'Build JDT LS'

env.JAVA_HOME="${tool 'openjdk-11'}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
sh 'java -version'

git url: 'https://github.com/eclipse/eclipse.jdt.ls.git'
sh "./mvnw clean verify -B -U -e -Pserver-distro -Dtycho.disableP2Mirrors=true -DskipTests -P!jboss-maven-repos,!redhat-ga-repository,!redhat-ea-repository"

def files = findFiles(glob: '**/org.eclipse.jdt.ls.product/distro/**.tar.gz')
stash name: 'server_distro', includes :files[0].path
}

node('rhel8'){
env.JAVA_HOME="${tool 'openjdk-11'}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
stage 'Checkout vscode-java code'
deleteDir()
git url: 'https://github.com/redhat-developer/vscode-java.git'

stage 'install vscode-java build requirements'
installBuildRequirements()

stage 'Build vscode-java'
buildVscodeExtension()
unstash 'server_distro'
def files = findFiles(glob: '**/org.eclipse.jdt.ls.product/distro/**.tar.gz')
sh "rm -rf ./out"
sh "mkdir ./server"
sh "tar -xvzf ${files[0].path} -C ./server"

stage 'Test vscode-java for staging'
wrap([$class: 'Xvnc']) {
sh "npm run compile" //compile the test code too
env.SKIP_COMMANDS_TEST="true"
sh "npm test --silent"
}

packageExtensions()

publishExtensions()
}
24 changes: 24 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ gulp.task('clean_test_folder', function(done) {
done();
});

gulp.task('prepare_pre_release', function(done) {
const json = JSON.parse(fse.readFileSync("./package.json").toString());
const stableVersion = json.version.match(/(\d+)\.(\d+)\.(\d+)/);
const major = stableVersion[1];
const minor = stableVersion[2];
const date = new Date();
const month = date.getMonth() + 1;
const day = date.getDate();
const hours = date.getHours();
const patch = `${date.getFullYear()}${prependZero(month)}${prependZero(day)}${prependZero(hours)}`;
const insiderPackageJson = Object.assign(json, {
version: `${major}.${minor}.${patch}`,
});
fse.writeFileSync("./package.json", JSON.stringify(insiderPackageJson, null, 2));
done();
});

function isWin() {
return /^win/.test(process.platform);
}
Expand All @@ -192,3 +209,10 @@ function isLinux() {
function mvnw() {
return isWin()?"mvnw.cmd":"./mvnw";
}

function prependZero(number) {
if (number > 99) {
throw "Unexpected value to prepend with zero";
}
return `${number < 10 ? "0" : ""}${number}`;
}

0 comments on commit 20f66cc

Please sign in to comment.