Skip to content

Commit ed4309e

Browse files
SylvainJugev1v
andauthored
[release] fix+refactor major branch update (#2302)
* fix all the things * fix typos * fix another typo * re-enable disabled steps * refactor few other steps + re-enable steps * fix typo * further cleanup * Update .ci/release/Jenkinsfile Co-authored-by: Victor Martinez <[email protected]> Co-authored-by: Victor Martinez <[email protected]>
1 parent 98d739f commit ed4309e

7 files changed

+151
-70
lines changed

.ci/release/Jenkinsfile

+7-53
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ pipeline {
6464
options { skipDefaultCheckout () }
6565
stages{
6666
stage('Check oss.sonatype.org') {
67-
when {expression { return false }}
6867
steps {
6968
// If this fails, an exception should be thrown and execution will halt
7069
dir("${BASE_DIR}"){
@@ -80,7 +79,6 @@ pipeline {
8079
stage('Check build status') {
8180
when {
8281
allOf {
83-
expression { return false }
8482
expression { params.check_branch_ci_status }
8583
expression { env.BRANCH_SPECIFIER != 'stable' }
8684
}
@@ -95,7 +93,6 @@ pipeline {
9593
}
9694
}
9795
stage('Require confirmation that CHANGELOG.asciidoc has been updated') {
98-
when {expression { return false }}
9996
steps {
10097
input(message: """
10198
Update CHANGELOG.asciidoc to reflect the new version release:
@@ -139,67 +136,30 @@ pipeline {
139136
}
140137
}
141138
}
142-
143-
// temporary allow to override version
144-
stage('Set release version manually') {
145-
steps {
146-
dir("${BASE_DIR}"){
147-
script {
148-
def user_release_version = input(message: "Please enter version to release:", parameters: [[
149-
$class: 'StringParameterDefinition',
150-
name: 'Release version',
151-
defaultValue: "",
152-
description: "Input release version without '-SNAPSHOT' suffix"
153-
]])
154-
155-
env.RELEASE_TAG = "v" + user_release_version
156-
env.RELEASE_VERSION = user_release_version
157-
env.BRANCH_DOT_X = user_release_version.substring(0, user_release_version.indexOf('.'))+'.x'
158-
}
159-
}
160-
}
161-
}
162-
163139
stage('Wait on internal CI') {
164-
when {expression { return false }}
165140
steps {
166141
notifyStatus(slackStatus: 'warning', subject: "[${env.REPO}] Release ready to be pushed",
167142
body: "Please go to (<${env.BUILD_URL}input|here>) to approve or reject within 12 hours.")
168143
input(message: "Start the release job on the internal CI. Click 'Proceed' once the job has succeeded or click 'Abort' if the release has failed and then manually undo the release.")
169144
}
170145
}
171146
stage('Nexus release') {
172-
when {expression { return false }}
173147
steps {
174148
notifyStatus(slackStatus: 'warning', subject: "[${env.REPO}] Release ready to be published in Nexus",
175149
body: "Please go to (<https://oss.sonatype.org/|here>) to proceed with the manual nexus release. Login details in LastPass")
176150
input(message: "Go to https://oss.sonatype.org and proceed with the steps to close and release the staging artifact.")
177151
}
178152
}
179153
stage('Major Branch create/update') {
180-
when {expression { return false }}
181154
steps {
182155
dir("${BASE_DIR}") {
183156
script {
157+
sh(script: ".ci/release/update_major_branch.sh ${RELEASE_VERSION}")
158+
gitPush(args: "-f ${BRANCH_DOT_X}")
159+
184160
def isMajor = env.RELEASE_VERSION.endsWith(".0.0")
185161
if (isMajor) {
186-
// major release, create '.x' branch
187-
sh(label: "remote tag is fetched for local checkout", script: "git fetch origin ${RELEASE_TAG}")
188-
sh(label: "create .x branch from ${RELEASE_TAG}", script: """
189-
git checkout ${RELEASE_TAG} --force
190-
git checkout -b ${BRANCH_DOT_X} --force""")
191-
gitPush()
192162
input message: "This was a major version release. Please update the conf.yml in the docs repo before continuing", ok "Continue"
193-
} else {
194-
// minor release, force-update existing '.x' branch. any change applied to '.x' branch, for example to
195-
// fix doc or release notes should also have been applied to master/stable branch we are releasing from
196-
sh(label: "remote tag and branch are fetched for local checkout", script: """
197-
git fetch origin ${BRANCH_DOT_X}
198-
git fetch origin ${RELEASE_TAG}""")
199-
sh(label: "force-update .x branch from ${RELEASE_TAG}", script: """
200-
git checkout --track origin/${BRANCH_DOT_X} --force
201-
git reset --hard origin/${RELEASE_TAG}""")
202-
gitPush(args: "-f ${BRANCH_DOT_X}")
203163
}
204164
}
205165
}
@@ -228,10 +188,9 @@ pipeline {
228188
steps {
229189
dir("${BASE_DIR}"){
230190
script {
231-
def fullUrl = "https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/${RELEASE_VERSION}/elastic-apm-agent-${RELEASE_VERSION}.pom"
232191
waitUntil(initialRecurrencePeriod: 60000) {
233192
script {
234-
def ret = sh(script: "curl -fs '${fullUrl}' >/dev/null 2>&1", returnStatus: true)
193+
def ret = sh(script: ".ci/release/wait_maven_artifact_published.sh ${RELEASE_VERSION}", returnStatus: true)
235194
echo "Waiting for the artifacts to be published on Sonatype"
236195
return ret == 0
237196
}
@@ -243,12 +202,7 @@ pipeline {
243202
stage('Update Cloudfoundry') {
244203
steps {
245204
dir("${BASE_DIR}"){
246-
// ensure that we don't rely on side effect of another step
247-
sh(label: "restore to previous updating version", script: """
248-
git fetch origin master
249-
git checkout master
250-
git reset --hard origin/master""")
251-
sh(script: "./scripts/jenkins/update_cloudfoundry.sh ${RELEASE_VERSION}")
205+
sh(script: ".ci/release/update_cloudfoundry.sh ${RELEASE_VERSION}")
252206
gitPush()
253207
}
254208
}
@@ -259,7 +213,7 @@ pipeline {
259213
waitUntil(initialRecurrencePeriod: 60000) {
260214
script {
261215
echo "Waiting for the release notes to be available"
262-
def ret = sh(script: "curl -fs https://www.elastic.co/guide/en/apm/agent/java/current/release-notes-${BRANCH_DOT_X}.html | grep ${RELEASE_VERSION}", returnStatus: true)
216+
def ret = sh(script: ".ci/release/wait_release_notes_published.sh ${RELEASE_VERSION}", returnStatus: true)
263217
return ret == 0
264218
}
265219
}
@@ -282,7 +236,7 @@ pipeline {
282236
}
283237
post {
284238
success {
285-
notifyStatus(slackStatus: 'good', subject: "[${env.REPO}] Release published", body: "Great news! The release has completed successfully. (<${env.RUN_DISPLAY_URL}|Open>).")
239+
notifyStatus(slackStatus: 'good', subject: "[${env.REPO}] Release published", body: "Great news! The release ${env.RELEASE_VERSION} has completed successfully. (<${env.RUN_DISPLAY_URL}|Open>).")
286240
}
287241
}
288242
}

.ci/release/update_cloudfoundry.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
REMOTE_NAME=origin
7+
BRANCH_NAME=master
8+
BASE_URL=https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent
9+
CF_FILE=cloudfoundry/index.yml
10+
11+
check_version "${1:-}"
12+
v="${1:-}"
13+
14+
echo -e "\n--- fetch & ensure clean state of ${REMOTE_NAME}/${BRANCH_NAME}"
15+
git fetch ${REMOTE_NAME} ${BRANCH_NAME}
16+
git checkout ${BRANCH_NAME}
17+
git reset --hard ${REMOTE_NAME}/${BRANCH_NAME}
18+
19+
echo -e "\n--- update ${CF_FILE} if required"
20+
21+
# make script idempotent if release is already in CF descriptor
22+
set +e
23+
grep -e "^${v}:" ${CF_FILE}
24+
[[ $? == 0 ]] && exit 0
25+
set -e
26+
27+
echo "${v}: ${BASE_URL}/${v}/elastic-apm-agent-${v}.jar" >> ${CF_FILE}
28+
git commit ${CF_FILE} -m "Update cloudfoundry for ${v} release"

.ci/release/update_major_branch.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
REMOTE_NAME=origin
7+
8+
# Final state (when there is no error): local checkout in the major branch '1.x' that matches the release tag
9+
# Pushing to remote repository is managed by the caller
10+
11+
check_version "${1:-}"
12+
v="${1:-}"
13+
14+
tag=$(version_tag ${v})
15+
major_branch="$(version_major_branch "${v}")"
16+
17+
echo ""
18+
echo "release version: ${v}"
19+
echo "release tag: ${tag}"
20+
echo "major branch: ${major_branch}"
21+
22+
check_ref_exists () {
23+
set +e
24+
git show-ref --verify --quiet "${1}" \
25+
&& echo 1 \
26+
|| echo 0
27+
set -e
28+
}
29+
30+
31+
# shallow clone does not allow to use other branches by default
32+
# found in https://stackoverflow.com/questions/23708231/git-shallow-clone-clone-depth-misses-remote-branches
33+
git remote set-branches ${REMOTE_NAME} '*'
34+
35+
echo -e "\n--- delete any local ${major_branch} branch if it exists"
36+
set +e
37+
git rev-parse --verify ${major_branch} 2>/dev/null && git branch -D ${major_branch}
38+
set -e
39+
40+
echo -e "\n--- ensure remote tag ${tag} and branch ${major_branch} are fetched for local checkout"
41+
git fetch --tags ${REMOTE_NAME}
42+
43+
if [[ '1' != $(check_ref_exists "refs/tags/${tag}") ]]; then
44+
echo "ERROR remote tag '${tag}' does not exists on remote '${REMOTE_NAME}'"
45+
exit 1
46+
fi
47+
48+
checkout_options=''
49+
50+
echo -e "\n--- checkout or create ${major_branch} branch"
51+
if [[ "0" == "$(check_ref_exists "refs/remotes/${REMOTE_NAME}/${major_branch}")" ]]; then
52+
# remote branch does not exists, creating new local branch
53+
checkout_options="-b ${major_branch}"
54+
else
55+
# remote branch exists, create local branch to update it
56+
checkout_options="--track ${REMOTE_NAME}/${major_branch}"
57+
fi
58+
set -e
59+
60+
echo -e "\n--- checkout local ${major_branch} branch"
61+
git checkout --force ${checkout_options}
62+
63+
echo -e "\n--- move local branch ${major_branch} to match tag ${tag}"
64+
git reset --hard ${tag}

.ci/release/util.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
check_version() {
4+
v=${1:-}
5+
6+
if [[ "${v}" == "" ]]; then
7+
echo "usage $0 <version>" # here $0 will be the calling script
8+
echo "where <version> in format '1.2.3'"
9+
exit 1
10+
fi
11+
12+
if [[ ! "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
13+
echo "invalid version format '${v}'"
14+
exit 1
15+
fi
16+
}
17+
18+
version_tag() {
19+
echo "v${1:?usage version_tag <version>}"
20+
}
21+
22+
version_major_branch() {
23+
v="${1:?usage version_major_branch <version>}"
24+
echo "${v%%.*}.x"
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
# returns '0' (zero) status code when artifact exists
7+
# return non-zero status when artifact does not exists or unable to execute request
8+
9+
check_version "${1:-}"
10+
v="${1:-}"
11+
12+
full_url="https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/${v}/elastic-apm-agent-${v}.pom"
13+
curl -fs "${full_url}" 2>&1 > /dev/null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
# returns '0' (zero) status code when release notes have been published
7+
# return non-zero status when they haven't been published yet or unable to execute request
8+
9+
check_version "${1:-}"
10+
v="${1:-}"
11+
major_branch="$(version_major_branch "${v}")"
12+
13+
full_url="https://www.elastic.co/guide/en/apm/agent/java/current/release-notes-${major_branch}.html"
14+
curl -fs "${full_url}" | grep "${v}"

scripts/jenkins/update_cloudfoundry.sh

-17
This file was deleted.

0 commit comments

Comments
 (0)