Skip to content

Commit abd93fb

Browse files
author
kmova
committed
chore(build): trigger downstream repo release
This fix will help to trigger the release on the downstream repo from travis. In this case, openebs/libcstor, openebs/jiva builds will be triggered Depending on the release tag, the downstream repo release branch will be determined. The release tag to release branch conversion is done as follows: v1.9.0 => v1.9.x v1.9.0-RC1 => v1.9.x v1.9.1 => v1.9.x v1.9.1-RC1 => v1.9.x v1.9.0-custom => v1.9.x-custom v1.9.0-custom-RC1 => v1.9.x-custom Signed-off-by: kmova <[email protected]>
1 parent 1ce2665 commit abd93fb

File tree

3 files changed

+161
-2
lines changed

3 files changed

+161
-2
lines changed

.travis.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ jobs:
1212
env:
1313
- IMAGE_REPO="linux-utils"
1414
- TRIVYARCH="64bit"
15+
- RELEASE_TAG_DOWNSTREAM=1
1516
- os: linux
1617
arch: arm64
1718
env:
1819
- IMAGE_REPO="linux-utils-arm64"
1920
- TRIVYARCH="ARM64"
21+
- RELEASE_TAG_DOWNSTREAM=0
2022

2123
before_install:
2224
- if [ -z $IMAGE_ORG ]; then
@@ -33,6 +35,42 @@ script:
3335
- make test
3436
- ./trivy --exit-code 0 --severity HIGH --no-progress ${DIMAGE}:ci
3537
- ./trivy --exit-code 1 --severity CRITICAL --no-progress ${DIMAGE}:ci
36-
37-
after_success:
3838
- make push
39+
# If this build is running due to travis release tag, and
40+
# this job indicates to push the release downstream, then
41+
# go ahead and tag the dependent repo.
42+
#
43+
# Convert the TRAVIS_TAG to the corresponding release branch.
44+
# $TRAVIS_BRANCH contains the same value as $TRAVIS_TAG.
45+
# Example: TRAVIS_TAG and TRAVIS_BRANCH will have v1.9.0-RC1,
46+
# when github release tag is v1.9.0-RC1
47+
#
48+
# OpenEBS release are triggered from release branches that are named
49+
# as v1.9.x or v1.9.x-hotfix or v1.9.x-custom
50+
#
51+
# The tag to release branch conversion should be handled as follows:
52+
# v1.9.0-RC1 => should be v1.9.x
53+
# v1.9.0-hotfixid => should be v1.9.x-hotfixid
54+
# v1.9.0 => should be v1.9.x
55+
# v1.9.1 => should be v1.9.x
56+
# v1.9.0-custom-RC1 => should be v1.9.x-custom
57+
# v1.9.0-custom => should be v1.9.x-custom
58+
# v1.9.1-custom => should be v1.9.x-custom
59+
#
60+
# Allow for building forked openebs pipelines.
61+
# Tag the downstream repos under current repo org.
62+
- if [ -z $REPO_ORG ]; then
63+
REPO_ORG=$(echo "$TRAVIS_REPO_SLUG" | cut -d'/' -f1);
64+
export REPO_ORG;
65+
fi
66+
- if [ ! -z $TRAVIS_TAG ] && [ $RELEASE_TAG_DOWNSTREAM = 1 ] && [ "$TRAVIS_REPO_SLUG" == "${REPO_ORG}/linux-utils" ]; then
67+
TAG_SUFFIX=$(echo "$TRAVIS_TAG" | cut -d'-' -f2);
68+
if [ "$TAG_SUFFIX" == "$TRAVIS_TAG" ] || [[ $TAG_SUFFIX =~ ^RC ]]; then
69+
REL_SUFFIX="";
70+
else
71+
REL_SUFFIX="-$TAG_SUFFIX";
72+
fi;
73+
REL_BRANCH=$(echo $(echo "$TRAVIS_TAG" | cut -d'-' -f1 | rev | cut -d'.' -f2- | rev).x$REL_SUFFIX) ;
74+
./buildscripts/git-release "${REPO_ORG}/jiva" "$TRAVIS_TAG" "$REL_BRANCH" || travis_terminate 1;
75+
./buildscripts/git-release "${REPO_ORG}/libcstor" "$TRAVIS_TAG" "$REL_BRANCH" || travis_terminate 1;
76+
fi

buildscripts/git-release

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
if [ "$#" -ne 3 ]; then
19+
echo "Error: Unable to create a new release. Missing required input."
20+
echo "Usage: $0 <github org/repo> <tag-name> <branch-name>"
21+
echo "Example: $0 kmova/bootstrap v1.0.0 master"
22+
exit 1
23+
fi
24+
25+
C_GIT_URL=$(echo "https://api.github.com/repos/$1/releases")
26+
C_GIT_TAG_NAME=$2
27+
C_GIT_TAG_BRANCH=$3
28+
29+
if [ -z ${GIT_NAME} ];
30+
then
31+
echo "Error: Environment variable GIT_NAME not found. Please set it to proceed.";
32+
echo "GIT_NAME should be a valid GitHub username.";
33+
exit 1
34+
fi
35+
36+
if [ -z ${GIT_TOKEN} ];
37+
then
38+
echo "Error: Environment variable GIT_TOKEN not found. Please set it to proceed.";
39+
echo "GIT_TOKEN should be a valid GitHub token associated with GitHub username.";
40+
echo "GIT_TOKEN should be configured with required permissions to create new release.";
41+
exit 1
42+
fi
43+
44+
RELEASE_CREATE_JSON=$(echo \
45+
{ \
46+
\"tag_name\":\"${C_GIT_TAG_NAME}\", \
47+
\"target_commitish\":\"${C_GIT_TAG_BRANCH}\", \
48+
\"name\":\"${C_GIT_TAG_NAME}\", \
49+
\"body\":\"Release created via $0\", \
50+
\"draft\":false, \
51+
\"prerelease\":false \
52+
} \
53+
)
54+
55+
#delete the temporary response file that might
56+
#have been left around by previous run of the command
57+
#using a fixed name means that this script
58+
#is not thread safe. only one execution is permitted
59+
#at a time.
60+
TEMP_RESP_FILE=temp-curl-response.txt
61+
rm -rf ${TEMP_RESP_FILE}
62+
63+
response_code=$(curl -u ${GIT_NAME}:${GIT_TOKEN} \
64+
-w "%{http_code}" \
65+
--silent \
66+
--output ${TEMP_RESP_FILE} \
67+
--url ${C_GIT_URL} \
68+
--request POST --header 'content-type: application/json' \
69+
--data "$RELEASE_CREATE_JSON")
70+
71+
#When embedding this script in other scripts like travis,
72+
#success responses like 200 can mean error. rc_code maps
73+
#the responses to either success (0) or error (1)
74+
rc_code=0
75+
76+
#Github returns 201 Created on successfully creating a new release
77+
#201 means the request has been fulfilled and has resulted in one
78+
#or more new resources being created.
79+
if [ $response_code != "201" ]; then
80+
echo "Error: Unable to create release. See below response for more details"
81+
#The GitHub error response is pretty well formatted.
82+
#Printing the body gives all the details to fix the errors
83+
#Sample response when the branch already exists looks like this:
84+
#{
85+
# "message": "Validation Failed",
86+
# "errors": [
87+
# {
88+
# "resource": "Release",
89+
# "code": "already_exists",
90+
# "field": "tag_name"
91+
# }
92+
# ],
93+
# "documentation_url": "https://developer.github.com/v3/repos/releases/#create-a-release"
94+
#}
95+
rc_code=1
96+
else
97+
#Note. In case of success, lots of details of returned, but just
98+
#knowing that creation worked is all that matters now.
99+
echo "Successfully tagged $1 with release tag ${C_GIT_TAG_NAME} on branch ${C_GIT_TAG_BRANCH}"
100+
fi
101+
cat ${TEMP_RESP_FILE}
102+
103+
#delete the temporary response file
104+
rm -rf ${TEMP_RESP_FILE}
105+
106+
exit ${rc_code}

buildscripts/push

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
#!/bin/bash
2+
3+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
217
set -e
318

419
if [ -z ${DIMAGE} ];

0 commit comments

Comments
 (0)