Skip to content

Commit

Permalink
Use matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Apr 21, 2021
1 parent e2381d0 commit 9eacd58
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions .ci/bumpStackVersion.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -75,52 +75,55 @@ pipeline {
def generateSteps(Map args = [:]) {
def projects = readYaml(file: '.ci/.bump-stack-version.yml')
def parallelTasks = [:]
projects['projects'].each { p ->
p.branches?.each { b ->
parallelTasks["${p.repo}-${b}"] = generateStep(repo: "${p.repo}",
scriptFile: "${p.script}",
branch: b)
projects['projects'].each { project ->
matrix(agent: 'linux && immutable', axes:[ axis('BRANCH', project.branches) ] ) {
bumpStackVersion(repo: "${project}", scriptFile: "${project.script}", branch: env.BRANCH, versions: latestVersions)
}
}
parallel(parallelTasks)
}

def generateStep(Map args = [:]){
def repo = args.containsKey('repo') ? args.get('repo') : error('generateStep: repo argument is required')
def scriptFile = args.containsKey('scriptFile') ? args.get('scriptFile') : error('generateStep: scriptFile argument is required')
def branch = args.containsKey('branch') ? args.get('branch') : error('generateStep: branch argument is required')
def bumpStackVersion(Map args = [:]){
def repo = args.containsKey('repo') ? args.get('repo') : error('bumpStackVersion: repo argument is required')
def scriptFile = args.containsKey('scriptFile') ? args.get('scriptFile') : error('bumpStackVersion: scriptFile argument is required')
def branch = args.containsKey('branch') ? args.get('branch') : error('bumpStackVersion: branch argument is required')
def versions = args.containsKey('versions') ? args.get('versions') : error('bumpStackVersion: versions argument is required')
log(level: 'INFO', text: "bumpStackVersion(repo: ${repo}, branch: ${branch}, scriptFile: ${scriptFile})")

def branchName = findBranch(branch: branch, versions: versions)
def versionEntry = versions.get(branchName)
def message = createPRDescription(versionEntry)

catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
deleteDir()
setupAPMGitEmail(global: true)
git(url: "https://github.com/elastic/${repo}.git", branch: branchName, credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken')
sh(script: "${scriptFile} '${versionEntry.build_id}'", label: "Prepare changes for ${repo}")
if (params.DRY_RUN_MODE) {
echo "DRY-RUN: ${repo} with description: '${message}'"
} else {
githubCreatePullRequest(title: "bump: stack version '${versionEntry.build_id}'", labels: 'automation', description: "${message}")
}
}
}

def findBranch(Map args = [:]){
def branch = args.branch
// special macro to look for the latest minor version
if (branch.contains('<minor>')) {
def parts = branch.split('\\.')
def major = parts[0]
branch = latestVersions.collect{ k,v -> k }.findAll { it ==~ /${major}\.\d+/}.sort().last()
branch = args.versions.collect{ k,v -> k }.findAll { it ==~ /${major}\.\d+/}.sort().last()
}
return branch
}

def versionEntry = latestVersions.get(branch)

def message = """
def createPRDescription(versionEntry) {
return """
### What
Bump stack version with the latest one.
### Further details
```
${versionEntry}
```
"""
return {
node('linux && immutable') {
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
deleteDir()
log(level: 'INFO', text: "repo: ${repo} - branch: ${branch} - scriptFile: ${scriptFile} - build_id: ${versionEntry.build_id}")
setupAPMGitEmail(global: true)
git(url: "https://github.com/elastic/${repo}.git", branch: branch, credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken')
sh(script: "${scriptFile} '${versionEntry.build_id}'", label: "Prepare changes for ${repo}")
if (params.DRY_RUN_MODE) {
echo "DRY-RUN: ${repo} with description: '${message}'"
} else {
githubCreatePullRequest(title: "bump: stack version '${versionEntry.build_id}'", labels: 'automation', description: "${message}")
}
}
}
}
}

0 comments on commit 9eacd58

Please sign in to comment.