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