Debian Codegraph @

kokoro/create_github_release_branch.sh

raw
1 #!/bin/bash
2 # Copyright 2023 Google LLC
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
17 set -euo pipefail
18
19 # Fail if RELEASE_VERSION is not set.
20 if [[ -z "${RELEASE_VERSION:-}" ]]; then
21 echo "RELEASE_VERSION must be set" >&2
22 exit 1
23 fi
24
25 IS_KOKORO="false"
26 if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]]; then
27 IS_KOKORO="true"
28 fi
29 readonly IS_KOKORO
30
31 # If not defined, default to /tmp.
32 : "${TMPDIR:="/tmp"}"
33
34 # WARNING: Setting this environment varialble to "true" will cause this script
35 # to actually perform a release.
36 : "${DO_MAKE_RELEASE:="false"}"
37
38 if [[ ! "${DO_MAKE_RELEASE}" =~ ^(false|true)$ ]]; then
39 echo "DO_MAKE_RELEASE must be either \"true\" or \"false\"" >&2
40 exit 1
41 fi
42
43 if [[ "${IS_KOKORO}" == "true" ]] ; then
44 readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)"
45 cd "${TINK_BASE_DIR}/tink_go_gcpkms"
46 fi
47
48 GITHUB_RELEASE_UTIL_OPTS=()
49 if [[ "${IS_KOKORO}" == "true" ]] ; then
50 # Note: KOKORO_GIT_COMMIT is populated by Kokoro.
51 GITHUB_RELEASE_UTIL_OPTS+=(
52 -c "${KOKORO_GIT_COMMIT}"
53 -t "${GITHUB_ACCESS_TOKEN}"
54 )
55 fi
56
57 if [[ "${DO_MAKE_RELEASE}" == "true" ]]; then
58 GITHUB_RELEASE_UTIL_OPTS+=( -r )
59 fi
60
61 readonly GITHUB_RELEASE_UTIL_OPTS
62
63 # If running on Kokoro, TMPDIR is populated with the tmp folder.
64 readonly TMP_DIR="$(mktemp -d "${TMPDIR}/release_XXXXXX")"
65 readonly RELEASE_UTIL_SCRIPT="$(pwd)/kokoro/testutils/github_release_util.sh"
66 if [[ ! -f "${RELEASE_UTIL_SCRIPT}" ]]; then
67 echo "${RELEASE_UTIL_SCRIPT} not found."
68 echo "Make sure you run this script from the root of tink-go-gcpkms."
69 return 1
70 fi
71
72 pushd "${TMP_DIR}"
73 # Create a release branch.
74 "${RELEASE_UTIL_SCRIPT}" "${GITHUB_RELEASE_UTIL_OPTS[@]}" create_branch \
75 "${RELEASE_VERSION}" tink-go-gcpkms
76 popd