Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automated Changelog creation in build script #257

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 61 additions & 40 deletions jenkins/oasisui.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ node {

properties([
parameters([
[$class: 'StringParameterDefinition', name: 'BUILD_BRANCH', defaultValue: 'master'],
[$class: 'StringParameterDefinition', name: 'SOURCE_BRANCH', defaultValue: BRANCH_NAME],
[$class: 'StringParameterDefinition', name: 'RELEASE_TAG', defaultValue: BRANCH_NAME.split('/').last() + "-${BUILD_NUMBER}"],
[$class: 'StringParameterDefinition', name: 'BASE_TAG', defaultValue: 'latest'],
[$class: 'BooleanParameterDefinition', name: 'PURGE', value: Boolean.valueOf(true)],
[$class: 'BooleanParameterDefinition', name: 'PUBLISH', value: Boolean.valueOf(false)],
[$class: 'BooleanParameterDefinition', name: 'PRE_RELEASE', value: Boolean.valueOf(true)],
[$class: 'BooleanParameterDefinition', name: 'AUTO_MERGE', defaultValue: Boolean.valueOf(true)],
[$class: 'BooleanParameterDefinition', name: 'SLACK_MESSAGE', value: Boolean.valueOf(false)]
[$class: 'StringParameterDefinition', description: "Oasis Build scripts branch", name: 'BUILD_BRANCH', defaultValue: 'master'],
[$class: 'StringParameterDefinition', description: "OasisUI branch", name: 'SOURCE_BRANCH', defaultValue: BRANCH_NAME],
[$class: 'StringParameterDefinition', description: "Release tag to publish", name: 'RELEASE_TAG', defaultValue: BRANCH_NAME.split('/').last() + "-${BUILD_NUMBER}"],
[$class: 'StringParameterDefinition', description: "Last release, for changelog", name: 'PREV_RELEASE_TAG', defaultValue: ""],
[$class: 'BooleanParameterDefinition', description: "Purge docker images", name: 'PURGE', value: Boolean.valueOf(true)],
[$class: 'BooleanParameterDefinition', description: "Create release if checked", name: 'PUBLISH', value: Boolean.valueOf(false)],
[$class: 'BooleanParameterDefinition', description: "Mark as pre-released software", name: 'PRE_RELEASE', value: Boolean.valueOf(true)],
[$class: 'BooleanParameterDefinition', description: "Perform a gitflow merge", name: 'AUTO_MERGE', defaultValue: Boolean.valueOf(true)],
[$class: 'BooleanParameterDefinition', description: "Send build status to slack", name: 'SLACK_MESSAGE', value: Boolean.valueOf(false)]
])
])

Expand All @@ -39,9 +39,7 @@ node {


// Set Global ENV
env.TAG_BASE = params.BASE_TAG // Build TAG for base set of images
env.TAG_RELEASE = params.RELEASE_TAG // Build TAG for TARGET image
env.TAG_RUN_PLATFORM = env.TAG_BASE // Version of Oasis Platform to use for testing
env.COMPOSE_PROJECT_NAME = UUID.randomUUID().toString().replaceAll("-","")

proxy_docker="docker/Dockerfile.oasisui_proxy"
Expand All @@ -50,11 +48,11 @@ node {
app_docker="docker/Dockerfile.oasisui_app"
app_image="coreoasis/oasisui_app"

//make sure release candidate versions are tagged correctly
if (params.PUBLISH && params.PRE_RELEASE && ! params.RELEASE_TAG.matches('^(\\d+\\.)(\\d+\\.)(\\*|\\d+)rc(\\d+)$')) {
//make sure release candidate versions are tagged correctly
if (params.PUBLISH && params.PRE_RELEASE && ! params.RELEASE_TAG.matches('^(\\d+\\.)(\\d+\\.)(\\*|\\d+)rc(\\d+)$')) {
sh "echo release candidates must be tagged {version}rc{N}, example: 1.0.0rc1"
sh "exit 1"
}
}

try {
// CLONE REPOS
Expand Down Expand Up @@ -118,13 +116,12 @@ node {
if (params.PUBLISH){
parallel(
publish_proxy: {

stage ('Publish: Shiny Proxy') {
dir(source_workspace) {
sh PIPELINE + " push_image ${proxy_image} ${env.TAG_RELEASE}"
if (! params.PRE_RELEASE){
sh PIPELINE + " push_image ${proxy_image} latest"
}
}
}
}
},
Expand All @@ -134,32 +131,56 @@ node {
sh PIPELINE + " push_image ${app_image} ${env.TAG_RELEASE}"
if (! params.PRE_RELEASE){
sh PIPELINE + " push_image ${app_image} latest"
}
}
}
}
}
)

//Git Tag
sshagent (credentials: [git_creds]) {
dir(source_workspace) {
sh "git tag ${env.TAG_RELEASE}"
sh "git push origin ${env.TAG_RELEASE}"
// Build chanagelog image
stage("Create Changelog builder") {
dir(build_workspace) {
sh "docker build -f docker/Dockerfile.release-notes -t release-builder ."
}
}
// Tag OasisUI
stage("Tag release") {
sshagent (credentials: [git_creds]) {
dir(source_workspace) {
sh "git tag ${env.TAG_RELEASE}"
sh "git push origin ${env.TAG_RELEASE}"
}
}
}
// Create release notes
stage('Create Changelog'){
dir(source_workspace){
withCredentials([string(credentialsId: 'github-api-token', variable: 'gh_token')]) {
sh "docker run -v ${env.WORKSPACE}/${source_workspace}:/tmp release-builder build-changelog --repo ${source_name} --from-tag ${params.PREV_RELEASE_TAG} --to-tag ${params.RELEASE_TAG} --github-token ${gh_token} --local-repo-path ./ --output-path ./CHANGELOG.rst --apply-milestone"
sh "docker run -v ${env.WORKSPACE}/${source_workspace}:/tmp release-builder build-release --repo ${source_name} --from-tag ${params.PREV_RELEASE_TAG} --to-tag ${params.RELEASE_TAG} --github-token ${gh_token} --local-repo-path ./ --output-path ./RELEASE.md"
}
sshagent (credentials: [git_creds]) {
sh "git add ./CHANGELOG.rst"
sh "git commit -m 'Update changelog ${params.RELEASE_TAG}'"
sh "git push"
}
}
}

// Create Github release
withCredentials([string(credentialsId: 'github-api-token', variable: 'gh_token')]) {
String repo = "OasisLMF/OasisUI"
def json_request = readJSON text: '{}'
json_request['tag_name'] = RELEASE_TAG
json_request['target_commitish'] = 'master'
json_request['name'] = RELEASE_TAG
json_request['body'] = ""
json_request['draft'] = false
json_request['prerelease'] = params.PRE_RELEASE
writeJSON file: 'gh_request.json', json: json_request
sh 'curl -XPOST -H "Authorization:token ' + gh_token + "\" --data @gh_request.json https://api.github.com/repos/$repo/releases > gh_response.json"
// Create Github release
stage ('Create Release: GitHub') {
withCredentials([string(credentialsId: 'github-api-token', variable: 'gh_token')]) {
String repo = "OasisLMF/OasisUI"
def release_body = readFile(file: "${env.WORKSPACE}/${source_workspace}/RELEASE.md")
def json_request = readJSON text: '{}'
json_request['tag_name'] = RELEASE_TAG
json_request['target_commitish'] = 'master'
json_request['name'] = RELEASE_TAG
json_request['body'] = release_body
json_request['draft'] = false
json_request['prerelease'] = params.PRE_RELEASE
writeJSON file: 'gh_request.json', json: json_request
sh 'curl -XPOST -H "Authorization:token ' + gh_token + "\" --data @gh_request.json https://api.github.com/repos/$repo/releases > gh_response.json"
}
}
}
} catch(hudson.AbortException | org.jenkinsci.plugins.workflow.steps.FlowInterruptedException buildException) {
Expand Down Expand Up @@ -187,7 +208,7 @@ node {
}

// Run merge back if publish
if (params.PUBLISH && params.AUTO_MERGE){
if (params.PUBLISH && params.AUTO_MERGE && ! hasFailed){
dir(source_workspace) {
sshagent (credentials: [git_creds]) {
if (! params.PRE_RELEASE) {
Expand All @@ -202,9 +223,9 @@ node {
sh "git stash"
sh "git checkout develop && git pull"
sh "git merge ${source_branch} && git push"
}
}
}
}
}
}
}
}
}
}