freeleaps-ops/first-class-pipeline/src/com/freeleaps/devops/SemanticReleasingExecutor.groovy

41 lines
1.8 KiB
Groovy

package com.freeleaps.devops
class SemanticReleasingExecutor {
def steps
def workspace
def config
def plugins = [
'semantic-release',
'@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'
}
def release(credentialsId) {
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) {
steps.withCredentials([steps.usernamePassword(credentialsId: credentialsId, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
steps.env.GIT_CREDENTIALS = "${steps.env.GIT_USERNAME}:${steps.env.GIT_PASSWORD}"
steps.writeFile file: '.releaserc.json', text: steps.libraryResource(config)
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"
steps.log.info("SemanticReleasingExecutor", "Installing semantic-release plugins...")
steps.sh "npm install -g ${plugins.join(' ')}"
steps.sh "git config --global --add safe.directory ${steps.env.workroot}"
steps.sh "semantic-release"
steps.log.info("SemanticReleasingExecutor", "Semantic release completed, read latest version from VERSION file")
steps.env.LATEST_VERSION = steps.readFile('VERSION').trim()
}
}
}
}