ELGIP-20 moved common_scripts directory as this seems to be expected now

This commit is contained in:
Damian Smith 2018-11-27 18:55:45 +00:00
commit fda8b6fdff
31 changed files with 1900 additions and 0 deletions

17
.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Common Build Scripts</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

8
.pydevproject Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python35</pydev_property>
</pydev_project>

View file

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//versionnumbering/versioninfo.py=utf-8

View file

@ -0,0 +1,23 @@
// Take a list of Sub-job descriptors and output folder pairs, copy the artifacts, while filling in a string of artifact folders
def combineSubjobArtifacts(meta, subJobs) {
def importer = load("${autobuilder.commonscripts()}/import/importer.groovy")
def ArrayList<String> artifactFolders = new ArrayList<String>()
for (subJob in subJobs) {
def subJobObject = subJob[0]
if (subJobObject != null) {
def subJobName = subJobObject.getProjectName()
def subJobNumber = subJobObject.getNumber()
destFolder = subJob[1]
dir(destFolder) {
deleteDir()
}
importer.artifactimport(meta, subJobName, subJobNumber, destFolder)
artifactFolders.add("${destFolder}/**")
}
}
return artifactFolders;
}
return this;

60
autobuilder.groovy Normal file
View file

@ -0,0 +1,60 @@
// Assume that WORKSPACE environment variable is set
autobuildroot = "${WORKSPACE}/autobuild"
commonscriptsroot = "${autobuildroot}/Common_scripts"
def conditionalclean(doclean = "${CLEAN_WORKSPACE}" == "true") {
if (doclean) {
echo "Cleaning workspace"
// Save any script files that were loaded into the workspace at first and are required after cleaning the workspace
stash allowEmpty: true, includes: 'autobuild/**', name: 'Clean workspace stash', useDefaultExcludes: false
cleanWs()
unstash name: 'Clean workspace stash'
}
else {
echo "Not cleaning workspace"
}
}
def commonscripts() {
return commonscriptsroot
}
def getautobuildpath() {
return autobuildroot
}
// Start up boilderplate
def start(script, productname = PRODUCT_NAME, subcomponentname = SUBCOMPONENT_NAME, jirakey = JIRA_KEY, releaserepo = RELEASE_REPO, autobuildpath = autobuildroot, commonscriptspath = commonscriptsroot) {
echo "Starting...."
autobuildroot = autobuildpath
commonscriptsroot = commonscriptspath
conditionalclean()
def metafolder = load("${commonscripts()}/meta/folder.groovy")
def meta = metafolder.metareset(script)
meta.productinfo.set(productname, subcomponentname, jirakey)
def now = new Date()
now.format("yyMMdd.HHmm", TimeZone.getTimeZone('UTC'))
meta.jenkinsbuildinfo.set(JOB_NAME, BUILD_ID.toInteger(), NODE_NAME, now.toString())
def rr = load("${commonscripts()}/release/registerrepo.groovy")
rr.registerrepo(meta, releaserepo)
def ch = load("${commonscripts()}/configuration/configuration.groovy")
ch.registerPipelineScriptConfiguration(meta)
return meta
}
def configurationhelper() {
return load("${commonscripts()}/configuration/configuration.groovy")
}
// Everyone wants to know this
autobuilder = this
return this;

14
checksum/utils.groovy Normal file
View file

@ -0,0 +1,14 @@
// Generate a checksum file of from a list of files/directories relative to workspace
def generatelist(meta, checksummable) {
for (filepath in checksummable) {
def checksumset = meta.checksuminfo.addChecksumSet(filepath)
def files = findFiles(glob: filepath)
for (file in files) {
def sum = sha1(file: file.path).trim()
checksumset.addChecksumPair(file.path, sum)
}
}
}
return this;

10
clean/clean.groovy Normal file
View file

@ -0,0 +1,10 @@
def clean(folderlist) {
for (folder in folderlist) {
dir(folder) {
deleteDir()
}
}
}
return this;

View file

@ -0,0 +1,13 @@
String getCommandOutput(String cmd) {
if (isUnix()) {
return sh(returnStdout: true, script: '#!/bin/sh -e\n' + cmd).trim()
} else {
return bat(returnStdout: true, script: """
@echo off
${cmd}
"""
).trim()
}
}
return this

View file

@ -0,0 +1,12 @@
// Disable parallel make builds - which may be causing autobuild issues
def doDisableParallelMake(rootSearchFolder = "${WORKSPACE}") {
if (isUnix()) {
sh """
# Looks for "<builder*parallelBuildOn="true"* in all .cproject files and replaces the "true" with "false"
find "${rootSearchFolder}" -iname ".cproject" | xargs -iXX sed -i "s@\\(<builder.*parallelBuildOn=\\"\\)true\\(\\"\\)@\\1false\\2@g" XX
"""
}
}
return this;

View file

@ -0,0 +1,198 @@
def doDisplayLeftovers() {
if (isUnix()) {
sh """
# Killing any processes that may interfere with the next build
# The build system must be setup to do more than one eclipse build concurrently
# Don't return an error if the processes don't exist
USER=`whoami`
ps aux | grep "eclipse"
ps aux | grep "make"
ps aux | grep "arm-linux"
# ps aux | grep "sh"
"""
}
}
def doKillLeftovers() {
if (isUnix()) {
doDisplayLeftovers()
sh """
# Killing any processes that may interfere with the next build
# The build system must be setup to do more than one eclipse build concurrently
# Don't return an error if the processes don't exist
USER=`whoami`
pkill -U "${USER}" -9 eclipse || true
pkill -U "${USER}" -9 make || true
pkill -U "${USER}" -9 ".*arm-linux.*" || true
"""
}
}
def doExport(exportfolder, exportpathlist, project = "", build_variant = "") {
def result = 0
for (exportpath in exportpathlist) {
echo "Export path at: ${exportpath}"
script {
echo "Build variant is ${build_variant}"
if (build_variant) {
echo "Build variant is ${build_variant}"
env.destFolder = "${exportfolder}/${build_variant}"
env.srcFile = "${WORKSPACE}/${exportpath}"
env.srcFileExpanded = srcFile.replace("-BUILDVARIANT-", "${build_variant}")
}
else {
echo "No build variant"
env.destFolder = "${exportfolder}/${project}"
env.srcFileExpanded = "${WORKSPACE}/${exportpath}"
}
}
dir (env.destFolder) {
echo "Copy \"${srcFileExpanded}\" to \"${destFolder}\""
if (isUnix()) {
result = sh( script: """
cp -r -v "${srcFileExpanded}" "${destFolder}"
if [ \$? -ne 0 ]; then exit 1; fi
""",
returnStatus: true
)
if (result != 0) {
return result
}
}
else {
result = bat( script: '''
copy \"%srcFileExpanded%\" \"%destFolder%\"
if errorlevel 1 EXIT /b 1
''',
returnStatus: true
)
if (result != 0) {
return result
}
}
}
}
return result
}
// Register toolchain
def doRegisterToolchain(ds5folder, toolchainfolder) {
// Register toolchain (if it is not already)
if (isUnix()) {
sh """
"${ds5folder}/bin/add_toolchain" --non-interactive "${toolchainfolder}"
"""
}
else {
bat """
"%ds5folder%\\bin\\add_toolchain" --non-interactive "%toolchainfolder%"
"""
}
echo "Path is: ${PATH}"
}
// Add toolchain to path
def addToolchainPath(toolchainfolder) {
// Register toolchain (if it is not already)
if (isUnix()) {
env.PATH = toolchainfolder + ":" + env.PATH
}
else {
env.PATH = toolchainfolder + ";" + env.PATH
}
echo "Path is: ${PATH}"
}
// Import all eclipse projects in a given folder
def doImportProjects(ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder) {
doRegisterToolchain(ds5folder, toolchainfolder)
if (isUnix()) {
sh """
${ds5shellcommand} \'${buildcommand} -no-indexer -importAll "${sourcefolder}"\'
"""
}
else {
bat '%ds5shellcommand% %buildcommand% -no-indexer -importAll "%sourcefolder%"'
}
}
// Build and export files
def doBuild(apps, ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder, variantstobuild, exportfolder = "${WORKSPACE}/bin") {
toBuild = []
if (variantstobuild) {
toBuildUntrimmed = variantstobuild.split(',')
toBuildUntrimmed.each {
toBuild.add(it.trim())
}
}
// The lock is being used because it was being found that the doKillLeftovers was affecting other builds
lock(resource: "eclipsebuild_${env.NODE_NAME}") {
try {
timeout(time: 2, unit: 'MINUTES') {
addToolchainPath(toolchainfolder)
doImportProjects(ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder)
}
for (appInfo in apps ) {
(build, cleanbuild, project, variants, exportpathlist) = appInfo
if (build) {
if (cleanbuild) {
buildtype = "-cleanBuild"
}
else {
buildtype = "-build"
}
for (build_variant in variants) {
retry(maxprojectbuildretries) { // Eclipse occasionally raises exceptions (rather than the builds failing)
try {
if (toBuild.contains(build_variant)) {
doDisplayLeftovers()
doRegisterToolchain(ds5folder, toolchainfolder)
echo "Build command: ${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'"
timeout(time: 10, unit: 'MINUTES') {
if (isUnix()) {
sh """
echo Start time: `date`
${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'
echo End time: `date`
"""
}
else {
bat """
"%ds5shellcommand%" "%buildcommand%" -no-indexer ${buildtype} "${project}\\${build_variant}"
"""
}
}
result = doExport(exportfolder, exportpathlist, "", build_variant)
if (result != 0) {
error "Failed to copy...."
}
}
else {
echo "Not building ${build_variant} variant of project: ${project}"
}
} catch (Exception e) {
echo "Build failed - Waiting for a while"
sleep(time: 4, unit: 'SECONDS')
error "Build failed..."
}
}
}
}
else {
// Only export if the project has no variants - signifying that there are files to export which have been prebuilt
if (!variants) {
result = doExport(exportfolder, exportpathlist, project)
if (result != 0) {
error "Failed to copy...."
}
}
}
}
} catch (Exception e) {
// doKillLeftovers()
error "Build failed - Killing leftovers"
}
}
}
return this;

View file

@ -0,0 +1,16 @@
gh = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy")
def registerConfigurationInfo(meta, String configurationName, String configurationURL, String configurationVersion, String configurationSHA) {
meta.addConfigurationInfo(configurationName, configurationURL, configurationVersion, configurationSHA)
}
def registerPipelineScriptConfiguration(meta) {
registerConfigurationInfo(meta, 'pipeline script', '-', '-', gh.getGitInfo("${autobuilder.getautobuildpath()}"))
}
def gitCheckoutAndRegister(meta, String tool, String gitURL, String revision, String targetDir, String repoRoot = "", int cloneDepth = 1, boolean shallowClone = true) {
gh.gitCheckout(gitURL, revision, targetDir, repoRoot, cloneDepth, shallowClone)
registerConfigurationInfo(meta, tool, gitURL, revision, gh.getGitInfo(targetDir))
}
return this

17
differences/.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Release_difference</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>

18
differences/do.groovy Normal file
View file

@ -0,0 +1,18 @@
def differences(meta, String sourcerevision, String previoussourcerevision, String sourcepath) {
def String cs = autobuilder.commonscripts()
def String difffolder = meta.folder()
def String jirakey = meta.productinfo.jirakey
if (isUnix()) {
sh """
"${PYTHON}" -u "${cs}/differences/show_release_differences.py" -g "${sourcepath}" -s "${sourcerevision}" -p "${previoussourcerevision}" -j "${jirakey}" -o "opposite notcommon" -d "${difffolder}"
"""
}
else {
bat """
"${PYTHON}" -u "${cs}\\differences\\show_release_differences.py" -g "${sourcepath}" -s "${sourcerevision}" -p "${previoussourcerevision}" -j "${jirakey}" -o "opposite notcommon" -d "${difffolder}"
"""
}
}
return this;

15
differences/json.groovy Normal file
View file

@ -0,0 +1,15 @@
def comparefiles(importedjsonfile, currentjsonfile) {
env.IMPORTED_JSON="${importedjsonfile}"
env.CURRENT_JSON="${currentjsonfile}"
if (isUnix()) {
sh """
# jq -S sorts json output
diff -c <(jq -S . "${IMPORTED_JSON}") <(jq -S . "${CURRENT_JSON}")
"""
}
else {
error "Windows not currently supporting json file comparison"
}
}
return this;

View file

@ -0,0 +1,226 @@
'''
showreleasedifferences -- shortdesc
showreleasedifferences generates a version folder with a common set of version information files in it
@author: dan
@copyright: 2017 Global Inkjet Systems Ltd. All rights reserved.
'''
import subprocess
import os
import sys
import re
from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter
__all__ = []
__version__ = 0.1
__date__ = '2017-11-29'
__updated__ = '2017-11-29'
gitExecutable = os.getenv("GIT_EXECUTABLE", default="git")
class GitException(Exception):
def __init__(self, message):
self.message = message
def __repr__(self):
return self.message
def makeFolder(difffolder):
print("Creating folder (if not already there): {0}".format(difffolder))
os.makedirs(difffolder, exist_ok = True)
def printDivider(outfh, times = 1, length = 100):
for _ in range(times):
outfh.write("{0}\n".format("*" * length))
TABSIZE = 4
def printTabbed(outfh, string, tabs = 0):
outfh.write("{0}{1}\n".format(" " * (TABSIZE * tabs), string))
def getGitLogDifferences(outfh, gitrootfolder, previousRelease, currentRelease, tripledot = False):
if tripledot:
releaseExpression = previousRelease + "..." + currentRelease
else:
releaseExpression = previousRelease + ".." + currentRelease
currentdir = os.getcwd()
os.chdir(gitrootfolder)
gitlog = []
printTabbed(outfh, "Executing: {0} {1} {2} {3}".format(gitExecutable, "log", "--oneline", releaseExpression))
proc = subprocess.Popen([gitExecutable, "log", "--oneline", releaseExpression], stdout=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if line:
linestring = line.decode('utf-8').rstrip()
gitlog.append(linestring)
#printTabbed(outfh, linestring, 1)
else:
break
proc.wait()
if proc.returncode > 0:
raise GitException("Git executable returned an error")
os.chdir(currentdir)
return gitlog
jiraprojectpattern = {
'GIS' : ( re.compile("^.* +(?:[gG][iI][sS][ _-]*|[tT]rac \#*|\#\s*)(\d+):*(.*)$"),
re.compile('^(\S*) Revert " *GIS-(\d+):* (.*)"$'),
),
'IMB': ( re.compile("^.* +(?:[Ii][Mm][Bb][ _-]*|\#\s*)(\d+):*(.*)$"),
re.compile('^(\S*) Revert " *IMB-(\d+):* (.*)"$'),
),
'HMBXR5601': ( re.compile("^.* +(?:[Hh][Mm][Bb][Xx][Rr]5601[ _-]*|\#\s*)(\d+):*(.*)$"),
re.compile('^(\S*) Revert " *HMBXR5601-(\d+):* (.*)"$'),
),
'SMB': ( re.compile("^.* +(?:[Ss][Mm][Bb][ _-]*|\#\s*)(\d+):*(.*)$"),
re.compile('^(\S*) Revert " *SMB-(\d+):* (.*)"$'),
),
'MCS': ( re.compile("^.* +(?:[Mm][Cc][Ss][ _-]*|\#\s*)(\d+):*(.*)$"),
re.compile('^(\S*) Revert " *MCS-(\d+):* (.*)"$'),
),
'HMBFDHV': ( re.compile("^.* +(?:[Hh][Mm][Bb][Ff][Dd][Hh][Vv][ _-]*|\#\s*)(\d+):*(.*)$"),
re.compile('^(\S*) Revert " *HMBFDHV-(\d+):* (.*)"$'),
),
}
mergepattern = re.compile("^(.*)((?:Merge branch '.*'|Merge remote-tracking branch '.*'|Merge commit '.*'|Add '.*' from commit).*)$")
def processLog(gitlog, jirakeyprefix):
reverts = []
merges = {}
other = []
numbered = {}
(expectedpattern, revertpattern) = jiraprojectpattern[jirakeyprefix]
for line in gitlog:
expectedmatch = expectedpattern.match(line)
revertmatch = revertpattern.match(line)
mergematch = mergepattern.match(line)
if expectedmatch == None and revertmatch == None and mergematch == None:
other.append(line)
if revertmatch:
gisnumber = jirakeyprefix + "-" + revertmatch.group(2)
description = revertmatch.group(3)
reverts.append("Revert: {0} {1}".format(gisnumber, description))
if mergematch:
merge = mergematch.group(2)
if not merge in merges:
merges[merge] = 1
else:
merges[merge] += 1
if expectedmatch:
gisnumber = jirakeyprefix + "-" + expectedmatch.group(1)
description = expectedmatch.group(2)
if not gisnumber in numbered:
numbered[gisnumber] = []
numbered[gisnumber].append(description)
return (reverts, merges, other, numbered)
def showDifferences(differences, jirakeyprefix, outfh):
(revertslog, mergeslog, otherlog, numberedlog) = differences
printDivider(outfh)
printTabbed(outfh, jirakeyprefix + "-Numbers Log:")
for (gisnumber, descriptions) in sorted(numberedlog.items()):
printTabbed(outfh, gisnumber, 1)
descriptions = numberedlog[gisnumber];
for description in descriptions:
printTabbed(outfh, description, 2)
printDivider(outfh)
printTabbed(outfh, "Revert log:")
for reversion in sorted(revertslog):
printTabbed(outfh, reversion, 1)
printDivider(outfh)
printTabbed(outfh, "Merges log:")
for merge in sorted(mergeslog):
printTabbed(outfh, merge, 1)
printDivider(outfh)
printTabbed(outfh, "Other log:")
for other in sorted(otherlog):
printTabbed(outfh, other, 1)
def main(argv=None): # IGNORE:C0111
'''Command line options.'''
if argv is None:
argv = sys.argv
else:
sys.argv.extend(argv)
program_name = os.path.basename(sys.argv[0])
program_version = "v%s" % __version__
program_build_date = str(__updated__)
program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
program_license = '''%s
Created by dan on %s.
Copyright 2017 Global Inkjet Systems Ltd. All rights reserved.
Distributed on an "AS IS" basis without warranties
or conditions of any kind, either express or implied.
USAGE
''' % (program_shortdesc, str(__date__))
try:
# Setup argument parser
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-g", "--gitroot", dest="gitrootfolder", action="store", default="GitRepository", help="root path of source files [default: %(default)s]")
parser.add_argument("-s", "--sourceversion", dest="sourceversion", action="store", default="origin/master", help="source version branch or tag to discover compare against [default: %(default)s]")
parser.add_argument("-p", "--previousversion", dest="previousversion", action="store", default="origin/master", help="source branch or tag to compare with [default: %(default)s]")
parser.add_argument("-j", "--jirakeyprefix", dest="jirakeyprefix", action="store", default="GIS", help="jira key prefix [default: %(default)s]")
parser.add_argument("-o", "--outputoptions", dest="outputoptions", action="store", default="", help="output options: Can be: opposite notcommon [default: %(default)s]")
parser.add_argument("-d", "--difffolder", dest="difffolder", action="store", default="", help="folder where differences file stored [default: %(default)s]")
# Process arguments
args = parser.parse_args()
try:
gitrootfolder = args.gitrootfolder
sourceversion = args.sourceversion
previousversion = args.previousversion
jirakeyprefix = args.jirakeyprefix
outputoptions = args.outputoptions
difffolder = args.difffolder
print("Git root:", gitrootfolder, "Source version:", sourceversion, "Previous source version:", previousversion)
print("Jira key prefix:", jirakeyprefix, "Output options:", outputoptions, "Version folder:", difffolder)
if difffolder:
makeFolder(difffolder)
outfh = open(os.path.join(difffolder, "differences.txt"), 'w')
else:
outfh = sys.stdout
printDivider(outfh, times = 4)
printTabbed(outfh, "Looking for changes in {2} that are not in {1} of the repository at path: {0}".format(gitrootfolder, previousversion, sourceversion))
gitlog = getGitLogDifferences(outfh, gitrootfolder, previousversion, sourceversion)
showDifferences(processLog(gitlog, jirakeyprefix), jirakeyprefix, outfh)
if 'opposite' in outputoptions.lower():
printDivider(outfh, times = 4)
printTabbed(outfh, "Looking for changes in {2} that are not in {1} of the repository at path: {0}".format(gitrootfolder, sourceversion, previousversion))
gitlog = getGitLogDifferences(outfh, gitrootfolder, sourceversion, previousversion)
showDifferences(processLog(gitlog, jirakeyprefix), jirakeyprefix, outfh)
if 'notcommon' in outputoptions.lower():
printDivider(outfh, times = 4)
printTabbed(outfh, "Looking for changes that are not common to {1} or {2} at path: {0}".format(gitrootfolder, sourceversion, previousversion))
gitlog = getGitLogDifferences(outfh, gitrootfolder, sourceversion, previousversion, tripledot = True)
showDifferences(processLog(gitlog, jirakeyprefix), jirakeyprefix, outfh)
if difffolder:
outfh.close()
return 0
except Exception as e:
print("Error while determining differences:", e.__repr__())
return 1
except Exception as e:
indent = len(program_name) * " "
print(program_name + ": " + repr(e) + "\n")
print(indent + " for help use --help")
return 2
if __name__ == "__main__":
sys.exit(main())

16
file/utils.groovy Normal file
View file

@ -0,0 +1,16 @@
def lineendings = load("${autobuilder.commonscripts()}/platform/lineendings.groovy")
// Get current contents of given file and optionally add a newline string/character; If file doesn't exist, return default contents
def currentContents(file, newline = "${nl}", defaultContents = "") {
def contents = ""
if (fileExists("${file}")) {
contents = readFile(file: "${file}").trim() + newline
}
else {
contents = defaultContents
}
return contents
}
return this;

27
import/importer.groovy Normal file
View file

@ -0,0 +1,27 @@
def artifactimport(meta, String jenkinsjob, int buildnumber, String destpath, String filter = '**', boolean fingerprint = false) {
copyArtifacts(
filter: filter,
fingerprintArtifacts: fingerprint,
projectName: jenkinsjob.trim(),
selector: specific(buildnumber.toString()),
target: destpath
)
meta.importrelated(destpath)
}
def artifactimport(meta, String jenkinsjob, String buildselector, String destpath, String filter = '**', boolean fingerprint = false) {
copyArtifacts(
filter: filter,
fingerprintArtifacts: fingerprint,
projectName: jenkinsjob.trim(),
selector: [
$class: 'ParameterizedBuildSelector',
parameterName: buildselector
],
target: destpath
)
meta.importrelated(destpath)
}
return this;

View file

@ -0,0 +1,42 @@
// Given details about artifacts to import and details of installers to build, import artifacts that are required
def artifactsImporter(artifactDetails, installerDetails) {
artifactFetched = [:]
for (installer in toBuild) {
def artifactKey = installerDetails.get(installer)[0]
//echo "To build: ${installer} use artifactKey: ${artifactKey}"
(sourceProject, destFolder, toCopy, notToCopy, binariesFolders) = artifactDetails.get(artifactKey)
env.importDest = destFolder
if (artifactFetched.get(artifactKey) == null) {
//echo "Artifact info: ${artifactInfo}"
copyArtifacts excludes: notToCopy, filter: toCopy, fingerprintArtifacts: true, projectName: "${sourceProject}", selector: lastSuccessful(), target: "${destFolder}"
def componentVersionFolder = "${WORKSPACE}\\version\\version_${artifactKey}"
def folderToCopy = "${destFolder}\\version"
echo "Copying from: ${folderToCopy} to: ${componentVersionFolder}"
fileOperations([folderCopyOperation(destinationFolderPath: componentVersionFolder, sourceFolderPath: folderToCopy)])
//fileOperations([fileCopyOperation(excludes: '', flattenFiles: false, includes: filesToCopy, targetLocation: componentVersionFolder )])
def gh = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy")
artifactVersion = gh.getSHAFromVersion("${destFolder}/version")
artifactFetched.put(artifactKey, artifactVersion)
}
}
return artifactFetched
}
// Export any required binaries to the <WORKSPACE>/bin folder
def exportBinaries(artifactDetails, installerDetails) {
for (installer in toBuild) {
(artifactSet, targetFolder, executionPath, ISMprojectFile, installerVariant, exportBinaries) = installerDetails.get(installer)
if (exportBinaries) {
(artifactsSourceProject, destinationFolder, artifactsToCopy, artifactsToNotCopy, binariesFolders) = artifactDetails.get(artifactSet)
for (binaryFolder in binariesFolders) {
binariesSourceFolder = "${destinationFolder}/${binaryFolder}"
binariesDestFolder = "${WORKSPACE}/bin/${artifactSet}/${binaryFolder}"
echo "Copying from: ${binariesSourceFolder} to: ${binariesDestFolder}"
fileOperations([folderCopyOperation(destinationFolderPath: binariesDestFolder, sourceFolderPath: binariesSourceFolder)])
}
}
}
}
return this;

578
meta/folder.groovy Normal file
View file

@ -0,0 +1,578 @@
import java.nio.file.Paths
import java.nio.file.Path
abstract class GISJsonSerialised implements Serializable {
def script
GISJsonSerialised(script) {
this.script = script
}
abstract LinkedHashMap serialisationdata()
abstract void deserialiseJson(rawmeta)
def saveJsonSerialised(String outputfile, int prettylevel = 4) {
def outJson = script.readJSON text: groovy.json.JsonOutput.toJson(serialisationdata())
script.writeJSON(file: outputfile, json: outJson, pretty: prettylevel)
}
}
class ProductInfo extends GISJsonSerialised {
private String productname
private String subcomponentname
String jirakey
ProductInfo(script, productname = "", subcomponentname = "", jirakey = "") {
super(script)
this.productname = productname
this.subcomponentname = subcomponentname
this.jirakey = jirakey
}
void set(String productname, String subcomponentname, String jirakey) {
this.productname = productname
this.subcomponentname = subcomponentname
this.jirakey = jirakey
}
void deserialiseJson(rawmeta) {
productname = rawmeta['productname']
subcomponentname = rawmeta['subcomponentname']
jirakey = rawmeta['jirakey']
}
LinkedHashMap serialisationdata() {
def data = [
'productname' : productname,
'subcomponentname' : subcomponentname,
'jirakey' : jirakey,
]
return data
}
}
class GitInfo extends GISJsonSerialised {
private String sourcepath
private String sourcerevision
private String gitrevision
private String remoteurl
private String remoteinfo
GitInfo(script, sourcepath = "", sourcerevision = "", gitrevision = "", remoteurl = "", remoteinfo = "") {
super(script)
this.sourcepath = sourcepath
this.sourcerevision = sourcerevision
this.gitrevision = gitrevision
this.remoteurl = remoteurl
this.remoteinfo = remoteinfo
}
void set(String sourcepath, String sourcerevision, String gitrevision, String remoteurl, String remoteinfo) {
this.sourcepath = sourcepath
this.sourcerevision = sourcerevision
this.gitrevision = gitrevision
this.remoteurl = remoteurl
this.remoteinfo = remoteinfo
}
void deserialiseJson(rawmeta) {
sourcepath = rawmeta['sourcepath']
sourcerevision = rawmeta['sourcerevision']
gitrevision = rawmeta['gitrevision']
remoteurl = rawmeta['remoteurl']
remoteinfo = rawmeta['remoteinfo']
}
LinkedHashMap serialisationdata() {
def data = [
'sourcepath' : sourcepath,
'sourcerevision' : sourcerevision,
'gitrevision' : gitrevision,
'remoteurl' : remoteurl,
'remoteinfo' : remoteinfo,
]
return data
}
}
class JenkinsBuildInfo extends GISJsonSerialised {
private String buildjobname
private int buildnumber
private String buildmachine
private String builddate
JenkinsBuildInfo(script, String buildjobname = "", int buildnumber = 0, String buildmachine = "", String builddate = "") {
super(script)
this.buildjobname = buildjobname
this.buildnumber = buildnumber
this.buildmachine = buildmachine
this.builddate = builddate
}
void set(String buildjobname, int buildnumber, String buildmachine, String builddate) {
this.buildjobname = buildjobname
this.buildnumber = buildnumber
this.buildmachine = buildmachine
this.builddate = builddate
}
void deserialiseJson(rawmeta) {
buildjobname = rawmeta['buildjobname']
buildnumber = rawmeta['buildnumber']
buildmachine = rawmeta['buildmachine']
builddate = rawmeta['builddate']
}
LinkedHashMap serialisationdata() {
def data = [
'buildjobname' : buildjobname,
'buildnumber' : buildnumber,
'buildmachine' : buildmachine,
'builddate' : builddate,
]
return data
}
}
class BuildStampInfo extends GISJsonSerialised {
private String buildstampprefix
private int revision
String buildstamp
String buildstampcommasep
BuildStampInfo(script, buildstampprefix = "", revision = 0, buildstamp = "", buildstampcommasep = "") {
super(script)
this.buildstampprefix = buildstampprefix
this.revision = revision
this.buildstamp = buildstamp
this.buildstampcommasep = buildstampcommasep
}
void set(String buildstampprefix, int revision, String buildstamp, String buildstampcommasep) {
this.buildstampprefix = buildstampprefix
this.revision = revision
this.buildstamp = buildstamp
this.buildstampcommasep = buildstampcommasep
}
void deserialiseJson(rawmeta) {
buildstampprefix = rawmeta['buildstampprefix']
revision = rawmeta['revision']
buildstamp = rawmeta['buildstamp']
buildstampcommasep = rawmeta['buildstampcommasep']
}
LinkedHashMap serialisationdata() {
def data = [
'buildstampprefix' : buildstampprefix,
'revision' : revision,
'buildstamp' : buildstamp,
'buildstampcommasep' : buildstampcommasep,
]
return data
}
}
class ReleaseInfo extends GISJsonSerialised {
private String releaserepoURL
private ArrayList<String> releaseitems
ReleaseInfo(script, releaserepoURL = "") {
super(script)
this.releaserepoURL = releaserepoURL
this.releaseitems = new ArrayList<String>()
}
void set(String releaserepoURL = "") {
this.releaserepoURL = releaserepoURL
}
void addReleaseItem(String releaseitem) {
releaseitems.add(releaseitem)
}
List releaseitemssserialised() {
def items = []
for (ri in releaseitems) {
items.add(ri)
}
return items
}
void deserialiseJson(rawmeta) {
releaserepoURL = rawmeta['releaserepoURL']
releaseitems = new ArrayList<String>()
for (rawreleaseitem in rawmeta['releaseitems']) {
releaseitems.add(rawreleaseitem)
}
}
LinkedHashMap serialisationdata() {
def data = [
'releaserepoURL' : releaserepoURL,
'releaseitems' : releaseitemssserialised(),
]
return data
}
}
class ConfigurationInfo extends GISJsonSerialised {
private String configurationname
private String configurationURL
private String configurationversion
private String configurationSHA
ConfigurationInfo(script, configurationname = "", configurationURL = "", configurationversion = "", configurationSHA = "") {
super(script)
this.configurationname = configurationname
this.configurationURL = configurationURL
this.configurationversion = configurationversion
this.configurationSHA = configurationSHA
}
void deserialiseJson(rawmeta) {
configurationname = rawmeta['configurationname']
configurationURL = rawmeta['configurationURL']
configurationversion = rawmeta['configurationversion']
configurationSHA = rawmeta['configurationSHA']
}
LinkedHashMap serialisationdata() {
def data = [
'configurationname' : configurationname,
'configurationURL' : configurationURL,
'configurationversion' : configurationversion,
'configurationSHA' : configurationSHA,
]
return data
}
}
class ChecksumPair extends GISJsonSerialised {
private String filepath
private String sum
ChecksumPair(script, String filepath = "", String sum = "") {
super(script)
this.filepath = filepath
this.sum = sum
}
void deserialiseJson(rawmeta) {
filepath = rawmeta['filepath']
sum = rawmeta['sum']
}
LinkedHashMap serialisationdata() {
def data = [
'filepath' : filepath,
'sum' : sum,
]
return data
}
}
class ChecksumSet extends GISJsonSerialised {
private String artifactpath
private ArrayList<ChecksumPair> checksumpairs
ChecksumSet(script, artifactpath = "") {
super(script)
this.artifactpath = artifactpath
checksumpairs = new ArrayList<ChecksumPair>()
}
ChecksumPair addChecksumPair(String filepath, String sum) {
def cp = new ChecksumPair(script, filepath, sum)
checksumpairs.add(cp)
return cp
}
List checksumpairsserialised() {
def associated = []
for (cp in checksumpairs) {
associated.add(cp.serialisationdata())
}
return associated
}
void deserialiseJson(rawmeta) {
artifactpath = rawmeta['artifactpath']
checksumpairs = new ArrayList<ChecksumPair>()
for (rawchecksumpair in rawmeta['checksumpairs']) {
def csp = new ChecksumPair(script)
csp.deserialiseJson(rawchecksumpair)
checksumpairs.add(csp)
}
}
LinkedHashMap serialisationdata() {
def data = [
'artifactpath' : artifactpath,
'checksumpairs' : checksumpairsserialised(),
]
return data
}
}
class ChecksumInfo extends GISJsonSerialised {
private ArrayList<ChecksumSet> checksumsets
ChecksumInfo(script) {
super(script)
checksumsets = new ArrayList<ChecksumSet>()
}
ChecksumSet addChecksumSet(String artifactpath) {
def cs = new ChecksumSet(script, artifactpath)
checksumsets.add(cs)
return cs
}
List checksumsetsserialised() {
def associated = []
for (cs in checksumsets) {
associated.add(cs.serialisationdata())
}
return associated
}
void deserialiseJson(rawmeta) {
checksumsets = new ArrayList<ChecksumSet>()
for (rawchecksumset in rawmeta['checksumsets']) {
def cs = new ChecksumSet(script)
cs.deserialiseJson(rawchecksumset)
checksumsets.add(cs)
}
}
LinkedHashMap serialisationdata() {
def data = [
'checksumsets' : checksumsetsserialised(),
]
return data
}
}
class PublishableInfo extends GISJsonSerialised {
private String filepath
PublishableInfo(script, String filepath = "") {
super(script)
this.filepath = filepath
}
void deserialiseJson(rawmeta) {
filepath = rawmeta['filepath']
}
LinkedHashMap serialisationdata() {
def data = [
'filepath' : filepath,
]
return data
}
}
class MetaInfo extends GISJsonSerialised {
private String FORMAT = "0.1"
private String METAFOLDERNAME = "meta"
private String METAFILENAME = "info.json"
private String METAARTIFACTS = "${METAFOLDERNAME}/**"
class RelatedMetaInfo extends GISJsonSerialised {
String offsetpath
MetaInfo meta
RelatedMetaInfo(script, offsetpath = "", MetaInfo meta = null) {
super(script)
this.offsetpath = offsetpath
this.meta = meta
}
void deserialiseJson(rawmeta) {
offsetpath = rawmeta['offsetpath']
meta = new MetaInfo(script)
meta.deserialiseJson(rawmeta['meta'])
}
LinkedHashMap serialisationdata() {
def data = [
'offsetpath' : offsetpath,
'meta' : meta.serialisationdata(),
]
return data
}
}
private String format = FORMAT
ProductInfo productinfo
GitInfo gitinfo
JenkinsBuildInfo jenkinsbuildinfo
BuildStampInfo buildstampinfo
ReleaseInfo releaseinfo
ChecksumInfo checksuminfo
private ArrayList<ConfigurationInfo> configurationinfo
private ArrayList<PublishableInfo> publishableinfo
private ArrayList<RelatedMetaInfo> associatedmeta
MetaInfo(script) {
super(script)
productinfo = new ProductInfo(script)
gitinfo = new GitInfo(script)
jenkinsbuildinfo = new JenkinsBuildInfo(script)
buildstampinfo = new BuildStampInfo(script)
releaseinfo = new ReleaseInfo(script)
checksuminfo = new ChecksumInfo(script)
configurationinfo = new ArrayList<ConfigurationInfo>()
publishableinfo = new ArrayList<PublishableInfo>()
associatedmeta = new ArrayList<RelatedMetaInfo>()
}
List configurationinfoserialised() {
def configuration = []
for (configurationitem in configurationinfo) {
configuration.add(configurationitem.serialisationdata())
}
return configuration
}
void addPublishable(String filepath) {
def PublishableInfo pi = new PublishableInfo(script, filepath)
publishableinfo.add(pi)
}
void addConfigurationInfo(String configurationname, String configurationURL, String configurationversion, String configurationSHA) {
def ConfigurationInfo ci = new ConfigurationInfo(script, configurationname, configurationURL, configurationversion, configurationSHA)
configurationinfo.add(ci)
}
List publishableinfoserialised() {
def publishable = []
for (publishableitem in publishableinfo) {
publishable.add(publishableitem.serialisationdata())
}
return publishable
}
List associatedmetaserialised() {
def associated = []
for (metaitem in associatedmeta) {
associated.add(metaitem.serialisationdata())
}
return associated
}
void deserialiseJson(rawmeta) {
if (rawmeta['format'] != FORMAT) {
script.error("Unsupported meta format found at ${filepath}")
return
}
productinfo.deserialiseJson(rawmeta['productinfo'])
gitinfo.deserialiseJson(rawmeta['gitinfo'])
jenkinsbuildinfo.deserialiseJson(rawmeta['jenkinsbuildinfo'])
buildstampinfo.deserialiseJson(rawmeta['buildstampinfo'])
releaseinfo.deserialiseJson(rawmeta['releaseinfo'])
checksuminfo.deserialiseJson(rawmeta['checksuminfo'])
for (rawconfig in rawmeta['configuration']) {
def cf = new ConfigurationInfo(script)
cf.deserialiseJson(rawconfig)
configurationinfo.add(cf)
}
for (rawpublishable in rawmeta['publishableinfo']) {
def pb = new PublishableInfo(script)
pb.deserialiseJson(rawpublishable)
publishableinfo.add(pb)
}
for (rawrelatedmeta in rawmeta['associatedmeta']) {
def rm = new RelatedMetaInfo(script)
rm.deserialiseJson(rawrelatedmeta)
associatedmeta.add(rm)
}
}
def deserialiseJson(String filepath) {
def rawmeta = script.readJSON(file: filepath)
deserialiseJson(rawmeta)
}
String relativize(String path) {
def Path thispath = Paths.get(path)
if (thispath.startsWith(script.WORKSPACE)) {
def Path wspath = Paths.get(script.WORKSPACE)
def Path wsrelativePath = wspath.relativize(thispath)
return wsrelativePath.toString()
}
return path
}
String metafilepath() {
return METAFOLDERNAME + "/" + METAFILENAME
}
MetaInfo importrelated(String destpath) {
MetaInfo mi = new MetaInfo(script)
def String adjustedpath = relativize(destpath)
def importedmetafile = adjustedpath + "/" + metafilepath()
if (script.fileExists(importedmetafile)) {
mi.deserialiseJson(importedmetafile)
}
RelatedMetaInfo rmi = new RelatedMetaInfo(script, adjustedpath, mi)
associatedmeta.add(rmi)
return mi
}
LinkedHashMap serialisationdata() {
def data = [
'format' : format,
'productinfo' : productinfo.serialisationdata(),
'gitinfo' : gitinfo.serialisationdata(),
'jenkinsbuildinfo' : jenkinsbuildinfo.serialisationdata(),
'buildstampinfo' : buildstampinfo.serialisationdata(),
'releaseinfo' : releaseinfo.serialisationdata(),
'configuration' : configurationinfoserialised(),
'checksuminfo' : checksuminfo.serialisationdata(),
'publishableinfo' : publishableinfoserialised(),
'associatedmeta' : associatedmetaserialised(),
]
return data
}
String folder() {
return METAFOLDERNAME
}
String generateartifacts(ArrayList<String> releasedfromhere = new ArrayList<String>(),
ArrayList<String> releasedfromsubmeta = new ArrayList<String>(),
String metafilepath ="${METAFOLDERNAME}/${METAFILENAME}"
) {
def String artifactlist = METAARTIFACTS
releaseinfo.addReleaseItem(METAARTIFACTS)
for (releaseitem in releasedfromhere) {
artifactlist += "," + releaseitem
releaseinfo.addReleaseItem(releaseitem)
}
for (releaseitem in releasedfromsubmeta) {
artifactlist += "," + releaseitem
}
saveJsonSerialised(metafilepath)
return artifactlist
}
}
MetaInfo metareset(script) {
echo "Resetting meta folder"
def mi = new MetaInfo(script)
dir(mi.folder()) {
deleteDir()
}
return mi
}
return this;

View file

@ -0,0 +1,5 @@
// Put ${nl} into strings when wanting a newline
nl = System.properties['line.separator']
return this;

10
publishing/utils.groovy Normal file
View file

@ -0,0 +1,10 @@
// Generate a list of artifact files that are publishable to outside parties
def generatelist(meta, publishable) {
filelist = []
for (filepath in publishable) {
meta.addPublishable(filepath)
}
}
return this;

View file

@ -0,0 +1,12 @@
vc = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy")
// Prove the existence of the release repo - otherwise there is a large wait to cycle the build to correct the meta data
def registerrepo(meta, String releaserepo) {
if (releaserepo?.trim()) {
vc.gitCheckout(releaserepo, "origin/master", "tmp/releaserepo")
}
meta.releaseinfo.set(releaserepo)
}
return this;

67
versioncontrol/git.groovy Normal file
View file

@ -0,0 +1,67 @@
clh = load("${autobuilder.commonscripts()}/commandline/commandline.groovy")
String getGitInfo(String workingSetRootPath) {
dir(workingSetRootPath) {
return clh.getCommandOutput('git rev-parse HEAD')
}
}
def gitCheckout(String gitURL, String revision, String targetDir, String repoRoot = "", int cloneDepth = 1, boolean shallowClone = true) {
reporootenv = env.REPO_ROOT
if (reporootenv != null && repoRoot != "") {
reporootpath = "${reporootenv.trim()}/${repoRoot}"
} else {
reporootpath = ""
echo "To improve Git performance: Define the REPO_ROOT enviroment to a path where a cache of git repositories can be placed on this slave"
}
checkout([
$class: 'GitSCM',
userRemoteConfigs: [
[url: gitURL]
],
branches: [
[name: revision]
],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'GitLFSPull'],
[$class: 'CleanBeforeCheckout'],
[$class: 'CloneOption', depth: cloneDepth, noTags: false, reference: reporootpath, shallow: shallowClone, timeout: 120],
[$class: 'CheckoutOption', timeout: 120],
[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir]
],
submoduleCfg: [],
])
}
String getSHAFromVersion(String versionFolder) {
dir (versionFolder) {
srcRevision = readFile("gitrevision.txt").trim()
}
return srcRevision
}
boolean checkAllVersionsAgree(java.util.LinkedHashMap versions) {
def keys = versions.keySet()
if (keys.size() < 1) {
return false
}
if (keys.size() == 1) {
return true
}
else {
version = ""
for (key in keys) {
nextversion = versions.get(key)
if (version == "") {
version = nextversion
}
if (nextversion != version) {
return false
}
}
}
return true
}
return this

View file

@ -0,0 +1,20 @@
def stamp(convertdetails) {
for (convertdetail in convertdetails) {
filetoconvert = convertdetail[0]
pattern = convertdetail[1]
replacement = convertdetail[2]
if (isUnix()) {
sh """
"${PYTHON}" -u "${autobuilder.commonscripts()}/versionstamping/versionstamper.py" -f "${filetoconvert}" -p "${pattern}" -s "${replacement}"
"""
}
else {
bat """
"%${PYTHON}%" -u "%${autobuilder.commonscripts()}%\\versionstamping\\versionstamper.py" -f "%${filetoconvert}%" -p "%${pattern}%" -s "%${replacement}%"
"""
}
}
}
return this;

View file

@ -0,0 +1,120 @@
def getGitRevision(String gitrootpath, int basebuildnumber) {
def int adjustedchangecount
def String gitrevision
def String remoteinfo
def String remoteurl
dir( gitrootpath) {
def int MAXVERSIONNUMBER = 65535
def int changecount = sh(returnStdout: true, script: "git rev-list HEAD --count").trim()
echo "Change count: ${changecount}"
adjustedchangecount = (changecount + basebuildnumber) % (MAXVERSIONNUMBER + 1)
echo "Adjusted change count: ${adjustedchangecount}"
gitrevision = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
echo "Revision: ${gitrevision}"
remoteinfo = sh(returnStdout: true, script: "git remote show origin").trim()
echo "Remote info: ${remoteinfo}"
remoteurl = sh(returnStdout: true, script: "git remote get-url --push origin").trim()
echo "Remote URL: ${remoteurl}"
}
return [adjustedchangecount, gitrevision, remoteinfo, remoteurl]
}
// Handle:
// origin/master
// origin/2.0.x
def getVersionPrefix(String sourcebranch) {
def int MAXVERSIONNUMBER = 65535
echo "Determining version number prefix from source branch name: ${sourcebranch}"
sourcebranch = sourcebranch.toLowerCase()
def defaultversionprefix = "1.30000.0."
def splits = sourcebranch.split('/')
if (splits.size() < 1) {
echo "Source branch name is invalid. Defaulting to: ${defaultversionprefix}"
return defaultversionprefix
}
def mastertypeversionprefix = "1.20000.0."
sourcebranch = splits.last()
if (sourcebranch.toLowerCase().find("master") != null) {
echo "Source branch name has 'master' in it. Defaulting to: ${mastertypeversionprefix}"
return mastertypeversionprefix
}
def splits2 = sourcebranch.split('\\.')
if (splits2.size() < 1) {
def thirdpartyversionprefix = "1.25000.0."
echo "Source branch name has no dots in it (eg. 1.9.2). Defaulting to: ${thirdpartyversionprefix}"
return thirdpartyversionprefix
}
for (split in splits2) {
if (split == "x") {
echo "Source branch name has '.x' or 'x.' in it. Defaulting to: ${mastertypeversionprefix}"
return mastertypeversionprefix
}
}
def integerstrings = sourcebranch.findAll(/\d+/)
def integers = []
for (integerstring in integerstrings) {
int integer = integerstring.toInteger()
integer = integer % (MAXVERSIONNUMBER + 1)
integers.add(integer)
}
def versionprefix = ""
if (integers.size() < 1) {
echo "This source branch name has no numbers in its name so defaulting to: ${defaultversionprefix}"
versionprefix = defaultversionprefix
}
else {
def int integernumbercount = 0
for (integer in integers) {
versionprefix += integer + "."
integernumbercount += 1
if (integernumbercount > 2) {
break
}
}
if (integernumbercount == 0) {
echo "No leading numbers were found in source branch name so defaulting to: ${defaultversionprefix}"
versionprefix = defaultversionprefix
}
else if (integernumbercount == 1) {
versionprefix += "0.0."
}
else if (integernumbercount == 2) {
versionprefix += "0."
}
}
echo "Determined version prefix to be: ${versionprefix}"
return versionprefix
}
String generate(meta, String sourcerevision, String sourcepath, int basebuildnumber = 1000) {
def int gitrevisioncount
def String gitrevision
def String remoteinfo
def String remoteurl
(gitrevisioncount, gitrevision, remoteinfo, remoteurl) = getGitRevision(sourcepath, basebuildnumber)
def versionprefix = getVersionPrefix(sourcerevision)
def buildstamp = versionprefix + gitrevisioncount.toString()
echo "Build stamp is: ${buildstamp}"
meta.gitinfo.set(sourcepath, sourcerevision, gitrevision, remoteurl, remoteinfo)
meta.buildstampinfo.set(versionprefix, gitrevisioncount, buildstamp, buildstamp.replace(".", ","))
return buildstamp
}
return this;

View file

@ -0,0 +1,100 @@
def lineendings = load("${autobuilder.commonscripts()}/platform/lineendings.groovy")
def fileutils = load("${autobuilder.commonscripts()}/file/utils.groovy")
def prefixline(rootpath, filepath) {
def fileContents = readFile("${filepath}").trim()
def fileContentsNormalized = fileContents.normalize()
def newFileContents = ""
def lines = fileContentsNormalized.readLines()
for (aline in lines) {
newFileContents += "${rootpath}" + "/" + aline + "${nl}"
}
return newFileContents
}
def mergemeta(rootpath, versionFolder, outputFolder) {
echo "Merging meta data from folder: ${versionFolder} to ${outputFolder}"
def differencesFile = "${versionFolder}/differences.txt"
def newContents = readFile file: "${differencesFile}"
def metadifferencesFile = "${outputFolder}/differences.txt"
writeFile file: "${metadifferencesFile}", text: fileutils.currentContents(metadifferencesFile) + newContents
def buildStampFile = "${versionFolder}/buildstamps.txt"
def buildStampFileContents = prefixline(rootpath, "${buildStampFile}")
def metabuildStampFile = "${outputFolder}/buildstamps.txt"
writeFile file: "${metabuildStampFile}", text: fileutils.currentContents(metabuildStampFile) + buildStampFileContents
def intrevision = 0
if (fileExists("${versionFolder}/revision.txt")) {
def revision = readFile("${versionFolder}/revision.txt").trim()
intrevision = revision.toInteger()
echo "Revision read in: ${intrevision}"
}
else {
intrevision = 1
}
return intrevision
}
def appendcomponentinfo(rootpath, versionFolder, outputFolder) {
echo "Appending component version data from folder: ${versionFolder} to ${outputFolder}"
def differencesFile = "${versionFolder}/differences.txt"
if (fileExists("${differencesFile}")) {
def newContents = readFile file: "${differencesFile}"
def metadifferencesFile = "${outputFolder}/differences.txt"
writeFile file: "${metadifferencesFile}", text: fileutils.currentContents(metadifferencesFile) + "${differencesFile}:\n" + newContents
}
def buildStampFile = "${versionFolder}/buildstamps.txt"
def buildStampFileContents = readFile("${buildStampFile}").trim()
def remoteurlFile = "${versionFolder}/remoteurl.txt"
def remoteurlFileContents = fileutils.currentContents(remoteurlFile, "", 'Unknown').trim()
def gitRevisionFile = "${versionFolder}/gitrevision.txt"
def gitRevisionFileContents = readFile("${gitRevisionFile}").trim()
def releaseJobNameFile = "${versionFolder}/releasejobname.txt"
def releaseJobNameContents = fileutils.currentContents("${releaseJobNameFile}", "", "-").trim()
def metabuildStampFile = "${outputFolder}/buildstamps.txt"
writeFile file: "${metabuildStampFile}", text: fileutils.currentContents(metabuildStampFile) + "${rootpath}" + ":" + buildStampFileContents + "," + remoteurlFileContents + "," + gitRevisionFileContents + "," + releaseJobNameContents
def revision = readFile("${versionFolder}/revision.txt").trim()
def intrevision = revision.toInteger()
echo "Revision read in: ${intrevision}"
return intrevision
}
// Each version folder should have been created using version creation scripts in this Common_scripts folder
// as their are well-known files in each folder
def combineSubjobVersions(versionLabelPrefix, artifactList, outputFolder = "${WORKSPACE}/metaversion") {
def totalrevision = 0
dir("${outputFolder}") {
deleteDir()
}
for (artifactItem in artifactList) {
(rootpath, versionFolder) = artifactItem
echo "Inspecting folder: ${versionFolder}"
def metaversionsignaturefile = "${versionFolder}/metaversion.txt"
// If the sub project is a meta job
def intrevision = 0
if (fileExists("${metaversionsignaturefile}")) {
intrevision = mergemeta(rootpath, versionFolder, outputFolder)
}
else {
intrevision = appendcomponentinfo(rootpath, versionFolder, outputFolder)
}
totalrevision += intrevision
}
echo "Accumulated revision is: ${totalrevision}"
writeFile file: "${outputFolder}/metaversion.txt", text: versionLabelPrefix + ((versionLabelPrefix.endsWith(".")) ? "" : ".") + totalrevision.toString()
writeFile(file: "${outputFolder}/revision.txt", text: totalrevision.toString())
}
return this;

View file

@ -0,0 +1,180 @@
# encoding: utf-8
'''
versionnumbering -- shortdesc
versionnumbering generates a version folder with a common set of version information files in it
@author: dan
@copyright: 2017 Global Inkjet Systems Ltd. All rights reserved.
'''
import os
import sys
import shutil
import subprocess
import re
import datetime
from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter
__all__ = []
__version__ = 0.1
__date__ = '2017-11-29'
__updated__ = '2017-11-29'
# Handle:
# origin/master
# origin/2.0.x
def getVersionPrefix(sourcebranch):
print("Determining version number prefix from source branch name: {0}".format(sourcebranch))
defaultversionprefix = "1.30000.0."
mastertypeversionprefix = "1.20000.0."
thirdpartyversionprefix = "1.25000.0."
splits = sourcebranch.split('/')
if len(splits) < 1:
print("Source branch name is invalid. Defaulting to: {0}".format(defaultversionprefix))
return defaultversionprefix
sourcebranch = splits[-1]
if sourcebranch.lower().find("master") != -1: # Special case
return mastertypeversionprefix
splits2 = re.split(r'(\d+)', sourcebranch)
splits = []
hasdot = False
for split in splits2:
if split.isdigit():
splits.append(split)
if split == ".":
hasdot = True
if not hasdot:
print("Source branch name has not dots in it (eg. 1.9.2). Defaulting to: {0}".format(thirdpartyversionprefix))
return thirdpartyversionprefix
versionprefix = ""
if len(splits) < 1:
print("This source branch name has no numbers in its name so defaulting to: {0}".format(defaultversionprefix))
versionprefix = defaultversionprefix
else:
splitnumbercount = 0
isIntermediateReleaseBranch = False
for split in splits:
if split.isdigit():
versionprefix += split + "."
splitnumbercount += 1
else:
if split == "x":
isIntermediateReleaseBranch = True
break
if splitnumbercount > 2:
break
if splitnumbercount == 0:
print("No leading numbers were found in source branch name so defaulting to: {0}".format(defaultversionprefix))
versionprefix = defaultversionprefix
else:
if isIntermediateReleaseBranch:
versionprefix = mastertypeversionprefix
elif splitnumbercount == 1:
versionprefix += "0.0."
elif splitnumbercount == 2:
versionprefix += "0."
print("Determined version prefix to be: {0}".format(versionprefix))
return versionprefix
def writeversionfiles(versionfolder, versionprefix, gitrevisioncount, gitrevision, remoteinfo, remoteurl, buildstamp):
with open(os.path.join(versionfolder, "prefix.txt"), 'w') as f:
f.write(versionprefix)
with open(os.path.join(versionfolder, "revision.txt"), 'w') as f:
f.write(str(gitrevisioncount))
with open(os.path.join(versionfolder, "gitrevision.txt"), 'w') as f:
f.write(gitrevision)
with open(os.path.join(versionfolder, "remoteinfo.txt"), 'w') as f:
f.write(remoteinfo)
with open(os.path.join(versionfolder, "remoteurl.txt"), 'w') as f:
f.write(remoteurl)
with open(os.path.join(versionfolder, "buildstamp.txt"), 'w') as f:
f.write(buildstamp)
buildstampcommasep = buildstamp.replace(".", ",")
with open(os.path.join(versionfolder, "buildstampcommasep.txt"), 'w') as f:
f.write(buildstampcommasep)
with open(os.path.join(versionfolder, "builddate.txt"), 'w') as f:
f.write(str(datetime.datetime.now()))
def main(argv=None): # IGNORE:C0111
'''Command line options.'''
if argv is None:
argv = sys.argv
else:
sys.argv.extend(argv)
program_name = os.path.basename(sys.argv[0])
program_version = "v%s" % __version__
program_build_date = str(__updated__)
program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
program_license = '''%s
Created by dan on %s.
Copyright 2017 Global Inkjet Systems Ltd. All rights reserved.
Distributed on an "AS IS" basis without warranties
or conditions of any kind, either express or implied.
USAGE
''' % (program_shortdesc, str(__date__))
try:
# Setup argument parser
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-s", "--sourcebranch", dest="sourcebranch", action="store", default="origin/master", help="source branch name to discover version number [default: %(default)s]")
parser.add_argument("-v", "--versionfolder", dest="versionfolder", action="store", default="version", help="version folder to be created [default: %(default)s]")
parser.add_argument("-g", "--gitroot", dest="gitrootfolder", action="store", default="GitRepository", help="root path of source files [default: %(default)s]")
parser.add_argument("-b", "--baseversionnumber", dest="baseversionnumber", action="store", default=int(1000), help="base git version number [default: %(default)s]")
# Process arguments
args = parser.parse_args()
try:
sourcebranch = args.sourcebranch
versionfolder = args.versionfolder
gitrootfolder = args.gitrootfolder
baseversionnumber = args.baseversionnumber
print("Source branch:", sourcebranch, "version folder:", versionfolder, "Git root:", gitrootfolder)
print("Base version number:", baseversionnumber)
(gitrevisioncount, gitrevision, remoteinfo, remoteurl) = getGitRevision(gitrootfolder, baseversionnumber)
versionprefix = getVersionPrefix(sourcebranch)
buildstamp = versionprefix + str(gitrevisioncount)
print("Build stamp is: {0}".format(buildstamp))
writeversionfiles(versionfolder, versionprefix, gitrevisioncount, gitrevision, remoteinfo, remoteurl, buildstamp)
return 0
except Exception as e:
print("Error while creating version info:", e.__repr__())
return 1
except Exception as e:
indent = len(program_name) * " "
print(program_name + ": " + repr(e) + "\n")
print(indent + " for help use --help")
return 2
if __name__ == "__main__":
sys.exit(main())

17
versionstamping/.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>versionstamping</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python35</pydev_property>
</pydev_project>

View file

@ -0,0 +1,41 @@
import argparse
import sys
import shutil
from builtins import FileNotFoundError
def main(argv):
parser = argparse.ArgumentParser(description="Look for version number pattern in file and replace with autobuild version number")
# Call once arguments to allow or disallow something
parser.add_argument('-f', '--filetoconvert', help='The file to convert')
parser.add_argument('-p', '--pattern', default='1.30000.0.0', help='The pattern to search for and replace')
parser.add_argument('-s', '--substitute', help='The new version number that will substitute the pattern')
args = parser.parse_args(argv)
filetoconvert = args.filetoconvert
pattern = args.pattern
substitute = args.substitute
print("Converting incidences of {0} with {1} in file: {2}\n".format(pattern, substitute, filetoconvert))
filecopy = filetoconvert + ".orig"
try:
shutil.move(filetoconvert, filecopy)
except FileNotFoundError:
print("Could not find file: {0}\n".format(filetoconvert))
return 1
with open(filetoconvert, 'x') as f:
with open(filecopy,'r') as c:
fileread = c.read()
print("Detected %s instances of %s pre-conversion"%(fileread.count(pattern),pattern))
converted = fileread.replace(pattern, substitute)
#print ("DEBUG: %s "%converted)
print("Confirmed %s instances of %s post-conversion"%(converted.count(substitute),substitute))
f.write(converted)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))