Revamp stages and restructure project (#1)

Reviewed-on: #1
Co-authored-by: Jim Nicholson <thejimnicholson@gmail.com>
Co-committed-by: Jim Nicholson <thejimnicholson@gmail.com>
This commit is contained in:
Jim Nicholson 2024-02-08 02:22:19 +00:00 committed by jim
parent 1a1d694001
commit b76d3f0fc5
7 changed files with 110 additions and 30 deletions

View File

@ -1,6 +1,9 @@
{ {
"extends": "recommended", "extends": "recommended",
"rules": { "rules": {
"DuplicateStringLiteral": {
"enabled": false
},
"Indentation": { "Indentation": {
"enabled": false "enabled": false
} }

View File

@ -10,5 +10,14 @@ String call(Map config = [:]) {
script: "git describe --tags --always --dirty=${runConfig.dirtyFlag}", script: "git describe --tags --always --dirty=${runConfig.dirtyFlag}",
returnStdout: true returnStdout: true
).trim() ).trim()
return gitTag
gitHash = sh(
script: 'git rev-parse --short HEAD',
returnStdout: true
).trim()
runConfig.tag = gitTag
runConfig.hash = gitHash
return runConfig
} }

View File

@ -1,24 +1,29 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
void call(Map config = [:]) { void call(Map config = [:], Closure body = { }) {
Map defaults = [ Map defaults = [
saveArtifaces: false, saveArtifaces: false,
buildTest: 'Makefile', buildTest: 'Makefile',
buildCmd: 'make all' buildCmd: 'make all',
stepName: 'Build'
] ]
Map runConfig = defaults + config Map runConfig = defaults + config
if (runConfig.saveArtifacts) { stage(runConfig.stepName) {
assert runConfig.artifacts : 'Error: saveArtifacts is set to true; must specify artifacts!' printBanner(runConfig.stepName)
} if (runConfig.saveArtifacts) {
if ( fileExists(runConfig.buildTest)) { assert runConfig.artifacts : 'Error: saveArtifacts is set to true; must specify artifacts!'
sh """ }
${runConfig.buildCmd} if ( fileExists(runConfig.buildTest)) {
""" sh """
} else { ${runConfig.buildCmd}
error("ERROR: File ${runConfig.buildTest} does not exist in workspace.") """
} } else {
if (runConfig.saveArtifacts) { error("ERROR: File ${runConfig.buildTest} does not exist in workspace.")
artifactsList = runConfig.artifacts.inspect().replaceAll('[\\[\\]\'\"]', '') }
archiveArtifacts artifacts: artifactsList, followSymlinks: false if (runConfig.saveArtifacts) {
artifactsList = runConfig.artifacts.join(',')
archiveArtifacts artifacts: artifactsList, followSymlinks: false
}
body()
} }
} }

View File

@ -1,5 +1,16 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
void call() { void call(Map config = [:], Closure body = { }) {
checkout scm Map defaults = [
stepName: 'Checkout',
useJobSCM: true
]
runConfig = defaults + config
stage(runConfig.stepName) {
printBanner(runConfig.stepName)
if (runConfig.useJobSCM) {
checkout scm
}
body()
}
} }

View File

@ -1,21 +1,33 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
void call(Map config = [:]) { void call(Map config = [:], Closure body = { }) {
Map defaults = [ Map defaults = [
name: env.BUILD_TAG, name: env.BUILD_TAG,
archiveCmd: 'tar zcvf', archiveCmd: 'tar',
archiveParams: 'zcvf',
extension: 'tgz', extension: 'tgz',
artifacts: [] artifacts: [],
stepName: 'Package',
separator: '-'
] ]
Map runConfig = defaults + config Map runConfig = defaults + config
stage(runConfig.stepName) {
printBanner(runConfig.stepName)
if (runConfig.artifacts.size() < 1) {
assert runConfig.artifacts : 'Error: No named artifacts to package!'
}
archiveName = runConfig.name + runConfig.separator + runConfig.tag + runConfig.separator + runConfig.extension
echo "Will tag result as: ${archiveName}"
String archiveName = "${runConfig.name}-${runConfig.tag}.${runConfig.extension}" sh """
if command -v "${runConfig.archiveCmd}"; then
echo "Will tag result as: ${archiveName}" ${runConfig.archiveCmd} ${runConfig.archiveParams} ${archiveName} ${runConfig.artifacts.join(' ')}
else
sh """ echo "Error: ${runConfig.archiveCmd} is not a valid executable!"
${runConfig.archiveCmd} ${archiveName} ${runConfig.artifacts.join(' ')} exit 2
""" fi
archiveArtifacts artifacts: archiveName, followSymlinks: false """
archiveArtifacts artifacts: archiveName, followSymlinks: false
body()
}
} }

28
vars/printBanner.groovy Normal file
View File

@ -0,0 +1,28 @@
void call(String stepName) {
red = '\033[31m'
blue = '\033[34m'
normal = '\033[0m'
stepBanner = "║ $blue$stepName$red ║"
bannerWidth = stepName.length() + 6
top = '╔' + ('═' * bannerWidth) + '╗'
bottom = '╚' + ('═' * bannerWidth) + '╝'
ansiColor('xterm') {
echo "$red$top\n$stepBanner\n$bottom$normal"
}
}
// fg_black = '\x1b[30m'
// fg_red = "\x1b[31m"
// fg_green = "\x1b[32m"
// fg_yellow = "\x1b[33m"
// fg_blue = "\x1b[34m"
// fg_magenta = "\x1b[35m"
// fg_cyan = "\x1b[36m"
// fg_white = "\x1b[37m"
// fg_default = "\x1b39m"
// fg_reset = "\x1b[0m"
//

12
vars/publishStep.groovy Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env groovy
void call(Map config = [:], Closure body = { }) {
Map defaults = [
stepName: 'Publish'
]
runConfig = defaults + config
stage(runConfig.stepName) {
printBanner(runConfig.stepName)
body()
}
}