Add scripts to generate release Yaml files
[policy/parent.git] / integration / src / release_scripts / mkart.sh
1 #!/bin/bash
2
3 #
4 # ============LICENSE_START================================================
5 # ONAP
6 # =========================================================================
7 # Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
8 # =========================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END==================================================
21 #
22
23 #
24 # This creates the x.y.z.yaml file for releasing (java) artifacts.
25 # It should be executed from somewhere within the "git" repo to be
26 # released.  Assumes the following:
27 #   - the branch to be released is currently checked out
28 #   - the latest maven-stage jenkins job is the one to be released
29 #   - the defaultbranch within the .gitreview file is set to the
30 #     branch to be released
31 #
32 # This uses xmllint, which is part of the libxml2-utils package.
33 #
34 # If behind a firewall, then http_proxy must be set so that curl
35 # can get through the firewall.
36 #
37
38 has_docker_images=false
39
40 if [ "$1" == "-d" ]
41 then
42     has_docker_images=true
43     shift
44 fi
45
46 TOPDIR=$(git rev-parse --show-toplevel)
47 if [ -z "${TOPDIR}" ]; then
48     echo "cannot determine top of 'git' repo" >&2
49     exit 1
50 fi
51
52 BRANCH=$(awk -F= '$1 == "defaultbranch" { print $2 }' "${TOPDIR}/.gitreview")
53 if [ -z "${BRANCH}" ]; then
54     echo "cannot extract default branch from ${TOPDIR}/.gitreview" >&2
55     exit 1
56 fi
57 echo Branch: ${BRANCH}
58
59 PROJECT=$(awk -F= '$1 == "project" { print $2 }' "${TOPDIR}/.gitreview" |
60             sed 's/.git$//')
61 if [ -z "${PROJECT}" ]; then
62     echo "cannot extract project from ${TOPDIR}/.gitreview" >&2
63     exit 1
64 fi
65 echo Project: ${PROJECT}
66 TPROJ=$(echo ${PROJECT} | sed 's!/!%2F!')
67 DPROJ=$(echo ${PROJECT} | sed 's!/!-!')
68
69 VERSION=$(
70     xmllint --xpath \
71         '/*[local-name()="project"]/*[local-name()="version"]/text()' \
72         "${TOPDIR}/pom.xml" |
73     sed 's!-SNAPSHOT!!'
74     )
75 if [ -z "${VERSION}" ]; then
76     echo "cannot extract version from ${TOPDIR}/pom.xml" >&2
77     exit 1
78 fi
79 echo Version: ${VERSION}
80
81 prefix='https://jenkins.onap.org/view/policy/job/'
82 STAGE_ID=$(
83     curl --silent ${prefix}${DPROJ}-maven-stage-${BRANCH}/ |
84     grep "Last completed build" |
85     sed -e 's!.*Last completed build .#!!' -e 's!).*!!' |
86     head -1
87     )
88 if [ -z "${STAGE_ID}" ]; then
89     echo "cannot extract last maven stage ID from jenkins" >&2
90     exit 1
91 fi
92 STAGE_ID=${DPROJ}-maven-stage-${BRANCH}/${STAGE_ID}/
93 echo Stage ID: ${STAGE_ID}
94
95 prefix='https://jenkins.onap.org/view/policy/job/'
96 JOB_OUT=$(curl --silent ${prefix}${STAGE_ID}/console)
97 echo "${JOB_OUT}" | grep -q "Finished: SUCCESS"
98 if [ $? -ne 0 ]; then
99     echo "last jenkins build has not completed successfully" >&2
100     exit 1
101 fi
102
103 echo Creating ${TOPDIR}/releases/${VERSION}.yaml
104
105 echo "distribution_type: 'maven'"  > "${TOPDIR}/releases/${VERSION}.yaml"
106 echo "version: '${VERSION}'"      >> "${TOPDIR}/releases/${VERSION}.yaml"
107 echo "project: '${DPROJ}'"        >> "${TOPDIR}/releases/${VERSION}.yaml"
108
109 if [ $has_docker_images = true ]
110 then
111     echo "tag_release: false" >> "${TOPDIR}/releases/${VERSION}.yaml"
112 fi
113
114 echo "log_dir: '${STAGE_ID}'" >> "${TOPDIR}/releases/${VERSION}.yaml"