• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2022 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
17set -euo pipefail
18
19# Fail if RELEASE_VERSION is not set.
20if [[ -z "${RELEASE_VERSION:-}" ]]; then
21  echo "RELEASE_VERSION must be set" >&2
22  exit 1
23fi
24
25IS_KOKORO="false"
26if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]]; then
27  IS_KOKORO="true"
28fi
29readonly 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
38if [[ ! "${DO_MAKE_RELEASE}" =~ ^(false|true)$ ]]; then
39  echo "DO_MAKE_RELEASE must be either \"true\" or \"false\"" >&2
40  exit 1
41fi
42
43if [[ "${IS_KOKORO}" == "true" ]] ; then
44  readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)"
45  cd "${TINK_BASE_DIR}/tink_java"
46fi
47
48GITHUB_RELEASE_UTIL_OPTS=()
49if [[ "${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  )
55fi
56
57if [[ "${DO_MAKE_RELEASE}" == "true" ]]; then
58  GITHUB_RELEASE_UTIL_OPTS+=( -r )
59fi
60
61readonly GITHUB_RELEASE_UTIL_OPTS
62
63# If running on Kokoro, TMPDIR is populated with the tmp folder.
64readonly TMP_DIR="$(mktemp -d "${TMPDIR}/release_XXXXXX")"
65readonly RELEASE_UTIL_SCRIPT="$(pwd)/kokoro/testutils/github_release_util.sh"
66if [[ ! -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-java."
69  return 1
70fi
71
72pushd "${TMP_DIR}"
73# Create a release branch.
74"${RELEASE_UTIL_SCRIPT}" "${GITHUB_RELEASE_UTIL_OPTS[@]}" create_branch \
75  "${RELEASE_VERSION}" tink-java
76popd
77