Skip to content

Commit

Permalink
[Build] Migrate status checks and git actions to Jenkins-Pipeline
Browse files Browse the repository at this point in the history
This avoids the need for a Java-11 JRE to run Javascript in the pipeline
and moves the file changes and git actions into one common place, making
it simpler to understand.

Simplify the step to commit the binaries binaries by deleting all
existing native binaries in the repo before they are build and then just
committing all new, deleted and changed files.
Also skip version increment tasks that change nothing (i.e. the major-
and minor swt-version value are unchanged and thus the entire
version.txt is not updated in the automated pipeline.
Remove the 'check_fragment_libraries' task without replacement since it
is not useful anymore.

Part of eclipse-platform#513
Fixes eclipse-platform#626
  • Loading branch information
HannesWell committed Jan 16, 2024
1 parent 9cdbcfc commit ea2c685
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 330 deletions.
122 changes: 95 additions & 27 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ def getNativeJdkUrl(String os, String arch){ // To update the used JDK version u
return "https://download.eclipse.org/justj/jres/17/downloads/20230428_1804/org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped-17.0.7-${os}-${arch}.tar.gz"
}

def getLatestGitTag() {
return sh(script: 'git describe --abbrev=0 --tags --match v[0-9][0-9][0-9][0-9]*', returnStdout: true).strip()
}

def getSWTVersions() { // must be called from the repository root
def props = readProperties(file: 'bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak')
props['new_rev'] = props['rev'].toInteger() + 1
props['swt_version'] = props['maj_ver'] + props['min_ver'] + 'r' + props['rev']
props['new_version'] = props['maj_ver'] + props['min_ver'] + 'r' + props['new_rev']
return props
}

pipeline {
options {
skipDefaultCheckout() // Specialiced checkout is performed below
Expand Down Expand Up @@ -104,15 +116,66 @@ pipeline {
}
stage('Check if SWT-binaries build is needed') {
steps {
withAnt(installation: 'apache-ant-latest', jdk: 'openjdk-jdk11-latest') { // nashorn javascript-engine required in ant-scripts
dir('eclipse.platform.swt') {
sh'''
java -version
git config --global user.email '[email protected]'
git config --global user.name 'Eclipse Releng Bot'
ant -f eclipse.platform.swt/bundles/org.eclipse.swt/buildSWT.xml check_preprocessing
ant -f eclipse.platform.swt/bundles/org.eclipse.swt/buildSWT.xml new_build_with_create_file -DTAG=HEAD
'''
script {
def swtTag = getLatestGitTag()
echo "Current tag=${swtTag}."
boolean nativesChanged = false
dir('bundles/org.eclipse.swt') {
// Check preprocessing is completed
sh '''
notProcessed=$(grep -R --include='*.java' --line-number --fixed-strings -e 'int /*long*/' -e 'float /*double*/' -e 'int[] /*long[]*/' -e 'float[] /*double[]*/' .)
if [[ -n "$notProcessed" ]]; then
echo There are files with the wrong long /*int*/ preprocessing:
echo $notProcessed
exit 1
fi
'''
def sourceFoldersProps = readProperties(file: 'nativeSourceFolders.properties')
def sources = sourceFoldersProps.collectEntries{ k, src -> [ k, src.split(',').collect{ f -> '\'' + f + '\''}.join(' ') ] }
def diff = sh(script: "git diff HEAD ${swtTag} ${sources.values().join(' ')}", returnStdout: true)
nativesChanged = !diff.trim().isEmpty()
echo "Natives changed: ${nativesChanged}, since ${swtTag}"
}
if (nativesChanged) {
def swtVersions = getSWTVersions()
def swt_version = swtVersions['swt_version']
// Delete native binaries to be replaced
sh """
rm -f binaries/org.eclipse.swt.gtk.*/lib*-${swt_version}.so
rm -f binaries/org.eclipse.swt.win32.*/*-${swt_version}.dll
rm -f binaries/org.eclipse.swt.cocoa.*/lib*-${swt_version}.jnilib
"""

def rev = swtVersions['rev']
def new_rev = swtVersions['new_rev']
def comma_ver = swtVersions['comma_ver']
def new_comma_ver = swtVersions['maj_ver'] + ',' + swtVersions['min_ver'] + ',' + new_rev + ',0'
echo "Incrementing version from ${swt_version} to ${swtVersions['new_version']}; new comma_ver=${new_comma_ver}"

def libraryFile = 'bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java'
def libraryFileContentUpdated = readFile(file: libraryFile)
.replace("REVISION = ${rev}","REVISION = ${new_rev}")
writeFile(file: libraryFile, text: libraryFileContentUpdated)

def makeCommonFile = 'bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak'
def makeCommonFileContentUpdated = readFile(file: makeCommonFile)
.replace("rev=${rev}", "rev=${new_rev}")
.replace("comma_ver=${comma_ver}", "comma_ver=${new_comma_ver}")
writeFile(file: makeCommonFile, text: makeCommonFileContentUpdated)

sh """
git add '${file_library}' '${file_version}' '${file_make_common}
git status
"""
writeFile(file: '../tmp/natives_changed.txt', text:'true')
}
}
}
}
}
Expand Down Expand Up @@ -252,22 +315,35 @@ pipeline {
expression { return params.forceNativeBuilds || fileExists('tmp/natives_changed.txt') }
}
steps {
withAnt(installation: 'apache-ant-latest', jdk: 'openjdk-jdk11-latest') { // nashorn javascript-engine required in ant-scripts
//The maven build reads the git-history so we should have to commit the native-binaries before building
dir('eclipse.platform.swt') {
script {
def swt_version = getSWTVersions()['swt_version'] // versions are read from updated file
sh """
find binaries -name "*${swt_version}*" -type f -exec chmod 644 {} +
git add --all *
echo "git status after git add"
git status
git commit -m 'v${swt_version}'
"""
try {
sh "git tag v${swt_version}"
} catch (ex) { // May fail in case this is a forced native re-build without revision increment
def tagged = ('a'..'z').any{ suffix ->
try {
sh "git tag v${swt_version + suffix}"
return true
}catch (ex1) {
return false
}
}
if(!tagged) {
fail "Fail to create tag for v${swt_version}"
}
}
}
sh '''
pushd eclipse.platform.swt
git add --all *
echo "git status after add"
git status
popd
ant -f eclipse.platform.swt/bundles/org.eclipse.swt/buildSWT.xml commit_binaries
ant -f eclipse.platform.swt/bundles/org.eclipse.swt/buildSWT.xml tag_projects
pushd eclipse.platform.swt
git status
git log -p -2
popd
'''
}
}
Expand Down Expand Up @@ -300,23 +376,17 @@ pipeline {
}
steps {
sshagent(['github-bot-ssh']) {
script {
def newSWTNativesTag = null;
dir('eclipse.platform.swt') {
newSWTNativesTag = sh(script: 'git describe --abbrev=0 --tags --match v[0-9][0-9][0-9][0-9]*', returnStdout: true).strip()
}
echo "newSWTNativesTag: ${newSWTNativesTag}"
dir('eclipse.platform.swt') {
sh """
newSWTNativesTag = ${getLatestGitTag()}
# Check for the master-branch as late as possible to have as much of the same behaviour as possible
if [[ '${BRANCH_NAME}' == master ]] || [[ '${BRANCH_NAME}' =~ R[0-9]+_[0-9]+(_[0-9]+)?_maintenance ]]; then
if [[ ${params.skipCommit} != true ]]; then
#Don't rebase and just fail in case another commit has been pushed to the master/maintanance branch in the meantime
pushd eclipse.platform.swt
git push origin HEAD:refs/heads/${BRANCH_NAME}
git push origin refs/tags/${newSWTNativesTag}
popd
exit 0
else
Expand All @@ -326,9 +396,7 @@ pipeline {
echo Skip pushing changes of native-binaries for branch '${BRANCH_NAME}'
fi
# The commits are not pushed. At least list them, so one can check if the result is as expected.
pushd eclipse.platform.swt
git log -n 2
popd
"""
}
}
Expand Down
Loading

0 comments on commit ea2c685

Please sign in to comment.