xref: /aosp_15_r20/external/google-cloud-java/.kokoro/sync_with_googleapis.sh (revision 55e87721aa1bc457b326496a7ca40f3ea1a63287)
1*55e87721SMatt Gilbride#!/bin/bash
2*55e87721SMatt Gilbride
3*55e87721SMatt Gilbride# This script reads the last googleapis (https://github.com/googleapis/googleapis)
4*55e87721SMatt Gilbride# commit applied to the google-cloud-java repository. It then applies new GAPIC
5*55e87721SMatt Gilbride# library changes to the repository between the commit and the latest master of
6*55e87721SMatt Gilbride# the googleapis repository. (This script uses
7*55e87721SMatt Gilbride# create_commits_from_googleapis_commits.sh to generate the Git commits).
8*55e87721SMatt Gilbride# The caller of this script then can create a pull request to apply the changes
9*55e87721SMatt Gilbride# to google-cloud-java repository.
10*55e87721SMatt Gilbride# The location of google-cloud-java repository is specified by
11*55e87721SMatt Gilbride# GOOGLE_CLOUD_JAVA_DIR environment variable.
12*55e87721SMatt Gilbride
13*55e87721SMatt Gilbrideset -ef
14*55e87721SMatt Gilbride
15*55e87721SMatt GilbrideBASEDIR=$(dirname "$0")
16*55e87721SMatt Gilbride
17*55e87721SMatt Gilbrideif [ -z "${WORKSPACE}" ]; then
18*55e87721SMatt Gilbride  export WORKSPACE=$(mktemp -d -t workspace-XXXXX)
19*55e87721SMatt Gilbridefi
20*55e87721SMatt Gilbride
21*55e87721SMatt Gilbrideif [ -z "${GOOGLE_CLOUD_JAVA_DIR}" ]; then
22*55e87721SMatt Gilbride  echo "GOOGLE_CLOUD_JAVA_DIR is not set"
23*55e87721SMatt Gilbride  exit 1
24*55e87721SMatt Gilbridefi
25*55e87721SMatt Gilbride
26*55e87721SMatt Gilbrideexport GOOGLEAPIS_DIR="${WORKSPACE}/googleapis"
27*55e87721SMatt Gilbride
28*55e87721SMatt Gilbride# TODO: It may be better to read the last googleapis's commit from the Git
29*55e87721SMatt Gilbride# commit messages.
30*55e87721SMatt Gilbrideexport GOOGLEAPIS_COMMIT_FILE=googleapis_commit.txt
31*55e87721SMatt Gilbride
32*55e87721SMatt Gilbridepushd "$WORKSPACE"
33*55e87721SMatt Gilbride
34*55e87721SMatt GilbrideBAZEL_VERSION=5.2.0
35*55e87721SMatt GilbrideBAZEL_DOWNLOAD_URL="https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-x86_64"
36*55e87721SMatt Gilbridecurl "${BAZEL_DOWNLOAD_URL}" --output bazel
37*55e87721SMatt Gilbridechmod 755 bazel
38*55e87721SMatt Gilbrideexport PATH=$WORKSPACE:$PATH
39*55e87721SMatt Gilbrideecho "$(date): Downloaded bazel: $(which bazel)"
40*55e87721SMatt Gilbridebazel version
41*55e87721SMatt Gilbride
42*55e87721SMatt Gilbridegit clone --quiet --branch master https://github.com/googleapis/googleapis
43*55e87721SMatt Gilbride
44*55e87721SMatt Gilbridepushd "${GOOGLE_CLOUD_JAVA_DIR}"
45*55e87721SMatt Gilbridestart_commit=$(cat "${GOOGLEAPIS_COMMIT_FILE}")
46*55e87721SMatt Gilbride
47*55e87721SMatt Gilbrideif [ -z "${start_commit}" ]; then
48*55e87721SMatt Gilbride  echo "Couldn't read start_commit from ${GOOGLEAPIS_COMMIT_FILE}"
49*55e87721SMatt Gilbride  exit 1
50*55e87721SMatt Gilbrideelse
51*55e87721SMatt Gilbride  echo "$(date): start_commit: ${start_commit}"
52*55e87721SMatt Gilbridefi
53*55e87721SMatt Gilbride
54*55e87721SMatt Gilbrideecho "$(date): Creating commits based on googleapis's ${start_commit} to origin/master"
55*55e87721SMatt Gilbride
56*55e87721SMatt Gilbride"${BASEDIR}/create_commits_from_googleapis_commits.sh" "${start_commit}" origin/master
57*55e87721SMatt Gilbride
58*55e87721SMatt Gilbrideecho "$(date): Finished creating commits in ${GOOGLE_CLOUD_JAVA_DIR}"
59