Merge commit '66082496ba' into 1.10003.j20-comscr

This commit is contained in:
Damian Smith 2018-12-03 10:29:43 +00:00
commit 652623f85b
3 changed files with 284 additions and 56 deletions

View file

@ -31,6 +31,27 @@ class ProductInfo extends GISJsonSerialised {
}
void set(String productname, String subcomponentname, String jirakey) {
// Make sure the fields can be used in git tags
def int pstatus = 0
if (script.isUnix()) {
pstatus = script.sh(script: "git check-ref-format --normalize \"refs/tags/${productname}\" >/dev/null 2>/dev/null", , returnStatus: true)
}
else {
pstatus = script.bat(script: "@git check-ref-format --normalize \"refs/tags/${productname}\" > NUL 2> NUL", , returnStatus: true)
}
if (pstatus > 0) {
script.error("The product name: ${productname} needs to be renamed as it cannot be used in a git tag name")
}
def int sstatus = 0
if (script.isUnix()) {
sstatus = script.sh(script: "git check-ref-format --normalize \"refs/tags/${subcomponentname}\" >/dev/null 2>/dev/null", , returnStatus: true)
}
else {
sstatus = script.bat(script: "@git check-ref-format --normalize \"refs/tags/${subcomponentname}\" > NUL 2> NUL", , returnStatus: true)
}
if (sstatus > 0) {
script.error("The subcomponent name: ${subcomponentname} needs to be renamed as it cannot be used in a git tag name")
}
this.productname = productname
this.subcomponentname = subcomponentname
this.jirakey = jirakey
@ -425,6 +446,7 @@ class MetaInfo extends GISJsonSerialised {
ChecksumInfo checksuminfo
private ArrayList<ConfigurationInfo> configurationinfo
private ArrayList<PublishableInfo> publishableinfo
private LinkedHashMap<String, String> custominfo
private ArrayList<RelatedMetaInfo> associatedmeta
MetaInfo(script) {
@ -437,6 +459,7 @@ class MetaInfo extends GISJsonSerialised {
checksuminfo = new ChecksumInfo(script)
configurationinfo = new ArrayList<ConfigurationInfo>()
publishableinfo = new ArrayList<PublishableInfo>()
custominfo = new LinkedHashMap<String, String>()
associatedmeta = new ArrayList<RelatedMetaInfo>()
}
@ -458,6 +481,14 @@ class MetaInfo extends GISJsonSerialised {
configurationinfo.add(ci)
}
void addCustomInfo(String customId, String customValue) {
custominfo.put(customId.trim(), customValue)
}
String getCustomInfo(String customId) {
return custominfo.getAt(customId.trim())
}
List publishableinfoserialised() {
def publishable = []
for (publishableitem in publishableinfo) {
@ -495,6 +526,7 @@ class MetaInfo extends GISJsonSerialised {
pb.deserialiseJson(rawpublishable)
publishableinfo.add(pb)
}
custominfo = rawmeta['custominfo']
for (rawrelatedmeta in rawmeta['associatedmeta']) {
def rm = new RelatedMetaInfo(script)
rm.deserialiseJson(rawrelatedmeta)
@ -562,13 +594,14 @@ class MetaInfo extends GISJsonSerialised {
'configuration' : configurationinfoserialised(),
'checksuminfo' : checksuminfo.serialisationdata(),
'publishableinfo' : publishableinfoserialised(),
'custominfo' : custominfo,
'associatedmeta' : associatedmetaserialised(),
]
return data
}
String folder() {
static String folder() {
return METAFOLDERNAME
}
@ -624,6 +657,10 @@ class MetaInfo extends GISJsonSerialised {
}
return releasemetauniquecollection
}
MetaInfo getNewMetaObject(script) {
return new MetaInfo(script)
}
}
MetaInfo metareset(script) {

View file

@ -3,8 +3,13 @@ unstablereason = ""
summaryfolder = "${WORKSPACE}/summary"
summaryfile = "${summaryfolder}/summary.txt"
summarystring = ""
releaserepofolder = "${WORKSPACE}/releaserepos"
sourcerepofolder = "${WORKSPACE}/sourcerepos"
tempfolder = "${WORKSPACE}/temp"
gitrevparseoutputfile = "${tempfolder}/gitrevparse.out"
metascript = autobuilder.getmetafolderscript()
def resetfolders() {
dir(summaryfolder) {
@ -21,6 +26,7 @@ def resetfolders() {
def preconditions() {
markunstable = false
unstablereason = ""
summarystring = ""
writeFile(file: summaryfile, text: "Release summary: \n")
}
@ -32,23 +38,64 @@ def setunstable(String reason) {
def summaryappend(String summary) {
def String currentsummarycontents = readFile(file: summaryfile)
writeFile(file: summaryfile, text: currentsummarycontents + summary)
summarystring += summary
}
def checkoutreleaserepo(info, String checkoutfolder) {
def String releaserepo = info.meta.releaseinfo.releaserepoURL
// Get the latest head revision of the release repo without checking out working copy; Check out to a folder unique to component
def getpreviousreleasemeta(buildmeta, String checkoutfolder) {
def previousreleasemeta = buildmeta.getNewMetaObject(this)
// See if there is meta data file from the current release
def String releasemetafolderpath = "${checkoutfolder}/${buildmeta.folder()}"
if (fileExists(releasemetafolderpath)) {
previousreleasemeta = metascript.metafromfolder(checkoutfolder)
}
return previousreleasemeta
}
def checkoutreleaserepo(buildmeta, String checkoutfolder) {
def String releaserepo = buildmeta.releaseinfo.releaserepoURL
// Get the latest head revision of the release repo without checking out working copy; Check out to a folder unique to component; Extract any meta
def previousreleasemeta = buildmeta.getNewMetaObject(this)
dir(releaserepofolder) {
sh("git clone -n --depth 1 ${releaserepo} ${checkoutfolder}")
sh("git clone --depth 1 ${releaserepo} ${checkoutfolder}")
}
previousreleasemeta = getpreviousreleasemeta(buildmeta, checkoutfolder)
dir(checkoutfolder) {
// Clear all existing files
sh("git rm -r *")
}
return previousreleasemeta
}
def checkoutsourcerepo(buildmeta, String checkoutfolder) {
def String sourcerepo = buildmeta.gitinfo.remoteurl
// Get the latest revision of the source repo without checking out working copy; Check out to a folder unique to component
if (fileExists(checkoutfolder)) {
dir(checkoutfolder) {
sh("""
git reset --hard
git clean -fdx
git pull
# Remove all tags that are not already on the remote
git tag -l | xargs git tag -d >/dev/null
git fetch -t >/dev/null
"""
)
}
}
else {
dir(sourcerepofolder) {
sh("git clone ${sourcerepo} ${checkoutfolder}")
}
}
}
def getcomponentartifacts(info, String repofolder, String tempfolder) {
def getcomponentartifacts(buildinfo, String repofolder, String tempfolder) {
// Copy relevant artifacts to temp folder
summaryappend("Artifacts: ")
for (artifactfilter in info.meta.releaseinfo.releaseitems) {
for (artifactfilter in buildinfo.meta.releaseinfo.releaseitems) {
def filterpath = artifactfilter
if (info.offsetpath) {
filterpath = info.offsetpath + '/' + artifactfilter
if (buildinfo.offsetpath) {
filterpath = buildinfo.offsetpath + '/' + artifactfilter
}
// Copy relevant artifacts to temp folder
echo "Copying artifacts: ${filterpath} to ${tempfolder}"
@ -62,7 +109,7 @@ def getcomponentartifacts(info, String repofolder, String tempfolder) {
target: tempfolder
)
// Move relevant artifacts from temp folder to release position
def originalrootdir = tempfolder + "/" + info.offsetpath
def originalrootdir = tempfolder + "/" + buildinfo.offsetpath
dir(originalrootdir) {
sh("mv * ${repofolder}")
}
@ -70,66 +117,217 @@ def getcomponentartifacts(info, String repofolder, String tempfolder) {
}
}
def gitrelease(String releaserepo, String buildstamp, String dryrunpush) {
summaryappend(" Git operations: ")
dir(releaserepo) {
// Add anything new
sh("git add .")
summaryappend("Add,")
// Perform git commit (if necessary)
def changesoccurred = sh(script: "git status --porcelain", returnStdout: true)
if (changesoccurred) {
sh("git commit -a -m ${buildstamp}")
summaryappend("Commit,")
def releasegitadd() {
// Add anything new
sh("git add .")
summaryappend("Add,")
}
def releasegitreset() {
// Add anything new
sh("git reset --hard")
sh("git clean -fdx")
summaryappend("Reset,")
}
def releasegitcommit(String buildstamp) {
sh("git commit -a -m ${buildstamp}")
summaryappend("Commit,")
}
// Determine if there has been a change by comparing the sha code in previous release meta and the build meta
def boolean checkforchange(buildmeta, previousreleasemeta) {
String buildsha = buildmeta.gitinfo.gitrevision
String previoussha = previousreleasemeta.gitinfo.gitrevision
def boolean changed = (buildsha != previoussha)
echo "buildsha: ${buildsha} previoussha: ${previoussha} changed: ${changed}"
return changed
}
def ArrayList<String> maketaglist(String buildstamp, String otherreleasetags) {
def ArrayList<String> taglist = new ArrayList<String>()
taglist.add(buildstamp)
def ArrayList<String> othertaglist = otherreleasetags.split(',')
for (othertagitem in othertaglist) {
if (othertagitem?.trim()) {
taglist.add(othertagitem.trim())
}
}
return taglist
}
def boolean releasegittag(String postcommitshacode, String tag) {
def boolean tagadded = false
// Check if tag exists already
def int gitrevparsestatus = sh(script: "git rev-parse \"${tag}\" >\"${gitrevparseoutputfile}\" 2>/dev/null", returnStatus: true)
if (gitrevparsestatus == 0) { // Tag exists
def existingshacode = readFile(file: gitrevparseoutputfile).trim()
if (existingshacode != postcommitshacode) { // If the existing tag is not associated with HEAD
// This is a problem - The tag is already at another position in git repo
setunstable("The tag ${tag} has been used at another commit other than HEAD - You must decide what to do with it - Not good practice to delete it or move it")
summaryappend("(${tag} - Could not add!)")
}
else {
summaryappend("(${tag} - Already added)")
}
}
else { // If tag does not exist already
// Tag
sh("git tag \"${tag}\"")
summaryappend("(${tag})")
tagadded = true
}
return tagadded
}
def boolean releasegittags(String postcommitshacode, ArrayList<String> taglist) {
boolean tagadded = false
summaryappend("Rel Tag ")
for (tag in taglist) {
if (releasegittag(postcommitshacode, tag)) {
tagadded = true
}
}
return tagadded
}
def boolean sourcegittag(String shacode, String tag) {
def boolean tagadded = false
// Check if tag exists already
def int gitrevparsestatus = sh(script: "git rev-parse \"${tag}\" >\"${gitrevparseoutputfile}\" 2>/dev/null", returnStatus: true)
if (gitrevparsestatus == 0) { // Tag exists
def existingshacode = readFile(file: gitrevparseoutputfile).trim()
if (existingshacode != shacode) { // If the existing tag is not associated with HEAD
// This is a problem - The tag is already at another position in git repo
setunstable("The source tag ${tag} has been used at another commit (${existingshacode}) - You must decide what to do with it - Not good practice to delete it or move it")
summaryappend("(${tag} - Could not add!)")
}
else {
summaryappend("(${tag} - Already added)")
}
}
else { // If tag does not exist already
// Tag
sh("git tag \"${tag}\" ${shacode}")
summaryappend("(${tag})")
tagadded = true
}
return tagadded
}
def sourcegittags(String buildsha, List taglist) {
boolean tagadded = false
summaryappend(",Src Tag ")
for (tag in taglist) {
if (sourcegittag(buildsha, tag)) {
tagadded = true
}
}
return tagadded
}
def releasegitpush(String dryrunpush ) {
if (dryrunpush == "true") {
sh("git push -n --tags origin master")
summaryappend(",Dry-Run-Push")
setunstable("The artifact(s) have not been pushed/saved (\"Dry run push\" parameter/option is selected)")
}
else {
sh("git push --tags origin master")
summaryappend(",Push")
}
}
def sourcegitpush(String dryrunpush ) {
if (dryrunpush == "true") {
sh("git push -n --tags")
summaryappend(",Src-Dry-Run-Push")
setunstable("The source tag(s) have not been pushed/saved (\"Dry run push\" parameter/option is selected)")
}
else {
sh("git push --tags")
summaryappend(",Src Push")
}
}
def gitrelease(buildmeta, previousreleasemeta, String releaserepo, String sourcerepo, String otherreleasetags, String dryrunpush) {
summaryappend(" Git operations: ")
def String buildstamp = buildmeta.buildstampinfo.buildstamp
dir(releaserepo) {
def String precommitshacode = sh(script: "git rev-parse --verify HEAD", returnStdout: true).trim()
echo "Pre commit sha code: ${precommitshacode}"
releasegitadd()
def boolean changed = checkforchange(buildmeta, previousreleasemeta)
if (changed) {
releasegitcommit(buildstamp)
}
else {
releasegitreset()
summaryappend("No-commit,")
}
// Tag with buildstamp
sh("git tag ${buildstamp}")
summaryappend("Tag (${buildstamp}),")
if (dryrunpush == "true") {
sh("git push -n --tags origin master")
summaryappend("Dry-Run-Push,")
setunstable("The artifact(s) have not been pushed/saved (\"Dry run push\" parameter/option is selected)")
def String postcommitshacode = sh(script: "git rev-parse --verify HEAD", returnStdout: true).trim()
echo "Post commit sha code: ${postcommitshacode}"
ArrayList<String> taglist = maketaglist(buildstamp, otherreleasetags)
def tagadded = releasegittags(postcommitshacode, taglist)
if (changed || tagadded) {
releasegitpush(dryrunpush)
}
else {
sh("git push --tags origin master")
summaryappend("Push")
}
dir(sourcerepo) {
def String srcbuildstamp = "${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}_${buildmeta.buildstampinfo.buildstamp}"
def String buildsha = buildmeta.gitinfo.gitrevision
def ArrayList<String> srctaglist = maketaglist(srcbuildstamp, otherreleasetags)
def tagadded = sourcegittags(buildsha, srctaglist)
if (tagadded) {
sourcegitpush(dryrunpush)
}
}
}
def releasecomponent(info, String dryrunpush) {
def String uniquefolder = "${info.meta.productinfo.productname}_${info.meta.productinfo.subcomponentname}"
def releasecomponent(buildinfo, String otherreleasetags, String dryrunpush) {
def buildmeta = buildinfo.meta
def String uniquefolder = "${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}"
def String uniquefolderforrepo = "${releaserepofolder}/${uniquefolder}"
def String uniquefoldertemp = "${tempfolder}/${uniquefolder}"
def String uniquefolderforsourcerepo = "${sourcerepofolder}/${uniquefolder}"
summaryappend("${info.meta.productinfo.productname} ${info.meta.productinfo.subcomponentname}: ")
checkoutreleaserepo(info, uniquefolderforrepo)
summaryappend("${buildmeta.productinfo.productname} ${buildmeta.productinfo.subcomponentname}: ")
def previousreleasemeta = checkoutreleaserepo(buildmeta, uniquefolderforrepo)
getcomponentartifacts(info, uniquefolderforrepo, uniquefoldertemp)
checkoutsourcerepo(buildmeta, uniquefolderforsourcerepo)
def String buildstamp = info.meta.buildstampinfo.buildstamp
gitrelease(uniquefolderforrepo, buildstamp, dryrunpush)
getcomponentartifacts(buildinfo, uniquefolderforrepo, uniquefoldertemp)
gitrelease(buildmeta, previousreleasemeta, uniquefolderforrepo, uniquefolderforsourcerepo, otherreleasetags, dryrunpush)
summaryappend("\n")
}
def releasehierarchy(buildmeta, String maxdepth, dryrunpush) {
def releasehierarchy(buildmeta, String maxdepth, String otherreleasetags, String dryrunpush) {
int md = maxdepth.toInteger()
resetfolders()
preconditions()
// Walk the meta information to a max depth, looking for artifacts to import for release
componentReleaseInfo = buildmeta.releasewalkerunique(md)
// For each component
for (key in componentReleaseInfo.keySet()) {
def info = componentReleaseInfo[key]
releasecomponent(info, dryrunpush)
def buildinfo = componentReleaseInfo[key]
releasecomponent(buildinfo, otherreleasetags, dryrunpush)
}
return [markunstable, unstablereason]
return [summarystring, markunstable, unstablereason]
}
return this;
return this;

View file

@ -10,42 +10,35 @@ def getGitRevision(String gitrootpath, int basebuildnumber) {
def String remoteinfo
def String remoteurl
dir( gitrootpath) {
def int changecount
def int changecount = 0
if (isUnix()) {
changecount = sh(returnStdout: true, script: "git rev-list HEAD --count").trim()
changecount = sh(returnStdout: true, script: "git rev-list HEAD --count").trim().toInteger()
}
else {
def stdout = bat(returnStdout:true , script: "git rev-list HEAD --count").trim()
changecount = stdout.readLines()[1] as int
}
changecount = bat(returnStdout: true, script: "@git rev-list HEAD --count").trim().toInteger()
}
echo "Change count: ${changecount}"
adjustedchangecount = (changecount + basebuildnumber) % (maxversionnumber() + 1)
echo "Adjusted change count: ${adjustedchangecount}"
if (isUnix()) {
gitrevision = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}
else {
def stdout = bat(returnStdout:true , script: "git rev-parse HEAD").trim()
gitrevision = stdout.readLines()[1]
gitrevision = bat(returnStdout: true, script: "@git rev-parse HEAD").trim()
}
echo "Revision: ${gitrevision}"
if (isUnix()) {
remoteinfo = sh(returnStdout: true, script: "git remote show origin").trim()
}
else {
def stdout = bat(returnStdout:true , script: "git remote show origin").trim()
remoteinfo = stdout.readLines()[1..-1]
remoteinfo = bat(returnStdout: true, script: "@git remote show origin").trim()
}
echo "Remote info: ${remoteinfo}"
if (isUnix()) {
remoteurl = sh(returnStdout: true, script: "git config --get remote.origin.url").trim()
}
else {
def stdout = bat(returnStdout:true , script: "git config --get remote.origin.url").trim()
remoteurl = stdout.readLines()[1]
remoteurl = bat(returnStdout: true, script: "@git config --get remote.origin.url").trim()
}
echo "Remote URL: ${remoteurl}"
}