• 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
25readonly TINK_JAVA_GITHUB_URL="github.com/tink-crypto/tink-java"
26IS_KOKORO="false"
27if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]]; then
28  IS_KOKORO="true"
29fi
30readonly IS_KOKORO
31
32# WARNING: Setting this environment varialble to "true" will cause this script
33# to actually perform a release.
34: "${DO_MAKE_RELEASE:="false"}"
35# By default, release both tink and tink-android.
36: "${TINK_JAVA_ARTIFACT:="all"}"
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
43#######################################
44# Create a Maven release on Sonatype.
45#
46# Globals:
47#   GITHUB_ACCESS_TOKEN (optional from Kokoro)
48#   IS_KOKORO
49#   RELEASE_VERSION
50#   TINK_JAVA_GITHUB_URL
51#
52#######################################
53create_maven_release() {
54  local gitub_protocol_and_auth="ssh://git"
55  if [[ "${IS_KOKORO}" == "true" ]] ; then
56    gitub_protocol_and_auth="https://ise-crypto:${GITHUB_ACCESS_TOKEN}"
57  fi
58  readonly gitub_protocol_and_auth
59  local -r github_url="${gitub_protocol_and_auth}@${TINK_JAVA_GITHUB_URL}"
60
61  local maven_deploy_library_options=( -u "${github_url}" )
62  if [[ "${DO_MAKE_RELEASE}" == "false" ]]; then
63    maven_deploy_library_options+=( -d )
64  fi
65  readonly maven_deploy_library_options
66
67  if [[ "${IS_KOKORO}" == "true" ]]; then
68    # Import the PGP signing key and make the passphrase available as an env
69    # variable.
70    gpg --import --pinentry-mode loopback \
71      --passphrase-file \
72      "${KOKORO_KEYSTORE_DIR}/70968_tink_dev_maven_pgp_passphrase" \
73      --batch "${KOKORO_KEYSTORE_DIR}/70968_tink_dev_maven_pgp_secret_key"
74    export TINK_DEV_MAVEN_PGP_PASSPHRASE="$(cat \
75      "${KOKORO_KEYSTORE_DIR}/70968_tink_dev_maven_pgp_passphrase")"
76  fi
77
78  if [[ "${TINK_JAVA_ARTIFACT}" == "tink" \
79        || "${TINK_JAVA_ARTIFACT}" == "all" ]]; then
80    ./maven/maven_deploy_library.sh "${maven_deploy_library_options[@]}" \
81      release tink maven/tink-java.pom.xml "${RELEASE_VERSION}"
82  fi
83  if [[ "${TINK_JAVA_ARTIFACT}" == "tink-android" \
84        || "${TINK_JAVA_ARTIFACT}" == "all" ]]; then
85    ./maven/maven_deploy_library.sh "${maven_deploy_library_options[@]}" \
86      release tink-android maven/tink-java-android.pom.xml "${RELEASE_VERSION}"
87  fi
88}
89
90main() {
91  if [[ "${IS_KOKORO}" == "true" ]] ; then
92    readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)"
93    cd "${TINK_BASE_DIR}/tink_java"
94  fi
95  create_maven_release
96}
97
98main "$@"
99