2025-02-07 07:18:40 +00:00
|
|
|
package com.freeleaps.devops
|
|
|
|
|
|
|
|
|
|
class SemanticReleasingExecutor {
|
|
|
|
|
def steps
|
|
|
|
|
def workspace
|
|
|
|
|
def config
|
|
|
|
|
def plugins = [
|
2025-02-07 10:26:19 +00:00
|
|
|
'semantic-release',
|
2025-02-07 07:18:40 +00:00
|
|
|
'@semantic-release/git',
|
|
|
|
|
'@semantic-release/changelog',
|
|
|
|
|
'@semantic-release/exec',
|
|
|
|
|
'conventional-changelog-conventionalcommits'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
SemanticReleasingExecutor(steps, workspace) {
|
|
|
|
|
this.steps = steps
|
|
|
|
|
this.workspace = workspace
|
|
|
|
|
// TODO: This should be a parameter, not hardcoded
|
|
|
|
|
this.config = 'com/freeleaps/devops/builtins/semantic-release/releaserc.json'
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-17 22:10:59 +00:00
|
|
|
def release(credentialsId, branch) {
|
2025-02-07 07:18:40 +00:00
|
|
|
steps.log.warn("SemanticReleasingExecutor", "Configuration file customization is not supported yet, using builtin release rules as fallback")
|
|
|
|
|
steps.log.info("SemanticReleasingExecutor", "Releasing with config: ${config}")
|
|
|
|
|
|
|
|
|
|
steps.dir(steps.env.workroot) {
|
2025-02-08 02:43:26 +00:00
|
|
|
steps.withCredentials([steps.usernamePassword(credentialsId: credentialsId, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
|
2025-02-17 22:13:55 +00:00
|
|
|
steps.env.GIT_CREDENTIALS = "${steps.env.GIT_USERNAME}:${steps.env.GIT_PASSWORD}"
|
2025-02-17 21:21:17 +00:00
|
|
|
steps.log.info("SemanticReleasingExecutor", "Installing semantic-release requirements...")
|
|
|
|
|
steps.sh "apt-get -y update && apt-get install -y --no-install-recommends git apt-transport-https ca-certificates curl wget gnupg"
|
2025-02-08 03:02:02 +00:00
|
|
|
steps.writeFile file: '.releaserc.json', text: steps.libraryResource(config)
|
2025-02-08 02:20:52 +00:00
|
|
|
steps.log.info("SemanticReleasingExecutor", "Installing semantic-release plugins...")
|
|
|
|
|
steps.sh "npm install -g ${plugins.join(' ')}"
|
2025-02-08 02:49:13 +00:00
|
|
|
steps.sh "git config --global --add safe.directory ${steps.env.workroot}"
|
2025-02-17 22:21:06 +00:00
|
|
|
steps.env.GIT_LOCAL_BRANCH = "${branch}"
|
2025-02-17 21:39:03 +00:00
|
|
|
steps.sh "semantic-release --debug"
|
2025-02-08 02:20:52 +00:00
|
|
|
steps.log.info("SemanticReleasingExecutor", "Semantic release completed, read latest version from VERSION file")
|
2025-02-17 11:27:05 +00:00
|
|
|
def released = steps.sh(script: 'test -f "VERSION"', returnStatus: true) == 0
|
|
|
|
|
if (released) {
|
|
|
|
|
steps.env.LATEST_VERSION = steps.readFile('VERSION').trim()
|
|
|
|
|
steps.env.SEMANTIC_RELEASED = true
|
|
|
|
|
}
|
2025-02-08 02:20:52 +00:00
|
|
|
}
|
2025-02-07 07:18:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|