From d179a8b3357ad7b8150b6f5f6f848263c4c7e770 Mon Sep 17 00:00:00 2001 From: Sam Gamble Date: Fri, 14 May 2021 11:02:10 +0100 Subject: [PATCH] Update build script --- jenkins/oasisui.groovy | 101 +++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/jenkins/oasisui.groovy b/jenkins/oasisui.groovy index 1ee8a490..483095b5 100644 --- a/jenkins/oasisui.groovy +++ b/jenkins/oasisui.groovy @@ -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)] ]) ]) @@ -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" @@ -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 @@ -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" - } + } } } }, @@ -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) { @@ -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) { @@ -202,9 +223,9 @@ node { sh "git stash" sh "git checkout develop && git pull" sh "git merge ${source_branch} && git push" - } - } - } - } + } + } + } + } } }