From 4f8f4e5171ca56d18545033ec2f880e853b0456d Mon Sep 17 00:00:00 2001 From: Allen Bai Date: Tue, 11 Aug 2020 17:29:32 -0400 Subject: [PATCH] fcos-release-notes: add job for generating release notes Adds a job for generating `release-notes.yaml` from `release-notes.d/` in `testing-devel` and `next-devel` and puts the output `release-notes.yaml` file to `testing` and `next` branch correspondingly. Also adds the functionality in `Jenkinsfile` such that after building the image, replaces the premature `next-release` placeholder key with the real build id. Then it uploads the final `release-notes.yaml` to the S3 bucket as well as pushing to `fedora-coreos-config` repo. Related: https://github.com/coreos/fedora-coreos-tracker/issues/194 Signed-off-by: Allen Bai --- Jenkinsfile | 32 +++++++++++ jobs/generate-release-notes.Jenkinsfile | 70 +++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 jobs/generate-release-notes.Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile index cda725fef..289b2690e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -500,6 +500,38 @@ lock(resource: "build-${params.STREAM}") { /var/tmp/fcos-releng/coreos-meta-translator/trans.py --workdir . """) + // Replace the 'next-release' field in 'release-notes.yaml' field + // with the real build id + botCreds = "github-coreosbot-token" + config_repo = "coreos/fedora-coreos-config" + release_notes_yaml = "src/config/release-notes.yaml" + utils.shwrap(""" + /var/tmp/fcos-releng/coreos-release-note-generator/release-note-generator.py update \ + --release-notes-file ${release_notes_yaml} \ + --build-id ${buildID} \ + --output-dir src/config + """) + shwrap(""" + cd src/config + git commit -am "release-notes.yaml: replace 'next-release' with build id" + """) + withCredentials([usernamePassword(credentialsId: botCreds, + usernameVariable: 'GHUSER', + passwordVariable: 'GHTOKEN')]) { + // should gracefully handle race conditions here + sh("git push https://\${GHUSER}:\${GHTOKEN}@github.com/${config_repo} ${params.STREAM}") + } + + // Push 'release-notes.yaml' to S3 bucket for website consumption + withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-fcos-builds-bot']]) { + shwrap(""" + cd src/config + aws s3 sync --acl public-read --cache-control 'max-age=60' \ + --exclude '*' --include 'release-notes.yaml' \ + ./ s3://fcos-builds + """) + } + if (s3_stream_dir) { // just upload as public-read for now, but see discussions in // https://github.com/coreos/fedora-coreos-tracker/issues/189 diff --git a/jobs/generate-release-notes.Jenkinsfile b/jobs/generate-release-notes.Jenkinsfile new file mode 100644 index 000000000..e0ad4c878 --- /dev/null +++ b/jobs/generate-release-notes.Jenkinsfile @@ -0,0 +1,70 @@ +@Library('github.com/coreos/coreos-ci-lib@master') _ + +config_repo = "coreos/fedora-coreos-config" +releng_script_repo = "coreos/fedora-coreos-releng-automation" +branches = [ + "testing-devel" + "next-devel" +] +botCreds = "github-coreosbot-token" + +cosaPod { + // set up fedora-coreos-releng-automation repository + shwrap(""" + mkdir fcos-releng + git clone --branch master https://github.com/${releng_script_repo} fcos-releng" + git config --global user.name "CoreOS Bot" + git config --global user.email "coreosbot@fedoraproject.org" + """) + + parallel branches.collectEntries { branch -> [branch, { + // build 'release-notes.yaml' using 'release-notes.d/' under testing-devel and next-devel + stage("Build 'release-notes.yaml'") { + shwrap("mkdir ${branch}") + + dir(branch) { + shwrap("cosa init --branch ${branch} https://github.com/${config_repo}") + } + + // generate 'release-notes.yaml' from yaml snippets under 'config/release-notes.d/' + dir("fcos-releng") { + shwrap("python3 coreos-release-note-generator/release-note-generator.py build \ + --config-dir ~/${branch}/src/config \ + --output-dir ~/${branch}/src/config") + } + } + + // delete all 'release-notes.d/*.yaml' files for next release version + stage("Clean up 'release-notes.d/'") { + shwrap(""" + cd ${branch}/src/config + git checkout ${branch} + rm -rf release-notes.d/*.yaml + git commit -am "release-notes.d: clean up release-notes.d for next release" + """) + withCredentials([usernamePassword(credentialsId: botCreds, + usernameVariable: 'GHUSER', + passwordVariable: 'GHTOKEN')]) { + // should gracefully handle race conditions here + sh("git push https://\${GHUSER}:\${GHTOKEN}@github.com/${config_repo} ${branch}") + } + } + + // push 'release-notes.yaml' from testing-devel and next-devel to testing and next branch correspondingly + stage("Push 'release-notes.yaml'") { + target_branch = branch.replace("-devel", "") + shwrap(""" + cd ${branch}/src/config + git checkout ${target_branch} + git add release-notes.yaml + git commit -am "release-notes.yaml: generate latest release notes" + """) + withCredentials([usernamePassword(credentialsId: botCreds, + usernameVariable: 'GHUSER', + passwordVariable: 'GHTOKEN')]) { + // should gracefully handle race conditions here + sh("git push https://\${GHUSER}:\${GHTOKEN}@github.com/${config_repo} ${target_branch}") + } + } + }] } +}