xref: /aosp_15_r20/external/sdk-platform-java/.kokoro/release/publish_javadoc11.sh (revision 882aa7c72c3cd3b66e72a261bdd69b93f7de7670)
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
16set -eo pipefail
17
18if [[ -z "${CREDENTIALS}" ]]; then
19  CREDENTIALS=${KOKORO_KEYSTORE_DIR}/73713_docuploader_service_account
20fi
21
22if [[ -z "${STAGING_BUCKET_V2}" ]]; then
23  echo "Need to set STAGING_BUCKET_V2 environment variable"
24  exit 1
25fi
26
27#work from the git root directory
28pushd $(dirname "$0")/../../
29
30root_dir=$(pwd)
31
32python3 --version
33
34# install docuploader package
35python3 -m pip install --require-hashes -r .kokoro/requirements.txt
36
37# If DOCLET_VERSION is passed in (overriding version in shared-config)
38if [ -n "${DOCLET_VERSION}" ]; then
39  doclet_name="java-docfx-doclet-${DOCLET_VERSION}.jar"
40fi
41
42mvn -B -ntp \
43  -DtrimStackTrace=false \
44  -Dclirr.skip=true \
45  -Denforcer.skip=true \
46  -Dcheckstyle.skip=true \
47  -Dflatten.skip=true \
48  -Danimal.sniffer.skip=true \
49  -DskipTests=true \
50  -Djacoco.skip=true \
51  -T 1C \
52  install
53
54if [[ -z "${MODULE_LIST}" ]]; then
55  # Retrieve list of modules from aggregator pom
56  modules=($(mvn help:evaluate -Dexpression=project.modules | grep '<.*>.*</.*>' | sed -e 's/<.*>\(.*\)<\/.*>/\1/g'))
57else
58  modules=($(echo "${MODULE_LIST}" | tr ',' ' '))
59fi
60
61excluded_modules=('gapic-generator-java-pom-parent' 'gapic-generator-java' 'gapic-generator-java-bom' )
62failed_modules=()
63
64declare -A cloud_rad_module_name
65cloud_rad_module_name+=( ["gax-java"]=gax ["api-common-java"]=api-common ["java-common-protos"]=proto-google-common-protos  ["java-iam"]=proto-google-iam-v1 )
66
67for module in "${modules[@]}"; do
68  # Proceed if module is not excluded
69  # Spaces are intentionally added -- Query is regex and array elements are space separated
70  # It tries to match the *exact* `module` text
71  if [[ ! " ${excluded_modules[*]} " =~ " ${module} " ]]; then
72    pushd $module
73
74    NAME=${cloud_rad_module_name[${module}]}
75    # Extract (current) version from root `versions.txt` file and remove `-SNAPSHOT`
76    VERSION=$(grep "^${NAME}:" "${root_dir}/versions.txt" | cut -d: -f3 | sed -e 's/-SNAPSHOT//g')
77    echo "Running for ${NAME}-${VERSION}"
78
79    # Cloud RAD generation
80    if [ -z "${doclet_name}" ]; then
81      mvn clean -B -ntp \
82        -P docFX \
83        -Dclirr.skip=true \
84        -Denforcer.skip=true \
85        -Dcheckstyle.skip=true \
86        -Dflatten.skip=true \
87        -Danimal.sniffer.skip=true \
88        javadoc:aggregate
89    else
90      mvn clean -B -ntp \
91        -P docFX \
92        -DdocletPath=${KOKORO_GFILE_DIR}/${doclet_name} \
93        -Dclirr.skip=true \
94        -Denforcer.skip=true \
95        -Dcheckstyle.skip=true \
96        -Dflatten.skip=true \
97        -Danimal.sniffer.skip=true \
98        javadoc:aggregate
99    fi
100
101    if [ "$?" -ne "0" ]; then
102      failed_modules+=("${module}")
103      continue
104    fi
105    # include CHANGELOG if exists
106    if [ -e CHANGELOG.md ]; then
107      cp CHANGELOG.md target/docfx-yml/history.md
108    fi
109    pushd target/docfx-yml
110
111    echo "Creating metadata for ${module}..."
112    # create metadata
113    python3 -m docuploader create-metadata \
114      --name ${NAME} \
115      --version ${VERSION} \
116      --xrefs devsite://java/gax \
117      --xrefs devsite://java/google-cloud-core \
118      --xrefs devsite://java/api-common \
119      --xrefs devsite://java/proto-google-common-protos \
120      --xrefs devsite://java/google-api-client \
121      --xrefs devsite://java/google-http-client \
122      --xrefs devsite://java/protobuf \
123      --language java
124
125    echo "Uploading tarball for ${module}..."
126    # upload yml to production bucket
127    python3 -m docuploader upload . \
128      --credentials ${CREDENTIALS} \
129      --staging-bucket ${STAGING_BUCKET_V2} \
130      --destination-prefix docfx
131
132    echo "Uploaded tarball for ${module}"
133
134    popd # out of target/docfx-yml
135    popd # out of $module
136  fi
137done
138
139if [ ${#failed_modules[@]} -eq 0 ]; then
140  echo "All modules uploaded to CloudRAD"
141else
142  echo "These modules failed: ${failed_modules[*]}"
143  exit 1
144fi