Skip to content

Commit 1bb6936

Browse files
committed
chore(hermetic-build): include .kokoro and .github templates
The templates come from https://github.com/googleapis/synthtool/tree/bf182cd41d9a7de56092cafcc7befe6b398332f6 The fix follows from https://setuptools.pypa.io/en/latest/userguide/datafiles.html: ``` Glob patterns do not automatically match dotfiles, i.e., directory or file names starting with a dot (.). To include such files, you must explicitly start the pattern with a dot, e.g. .* to match .gitignore. ```
1 parent 20f2fa4 commit 1bb6936

40 files changed

+1356
-27
lines changed

hermetic_build/DEVELOPMENT.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ as per [POSIX env var definition](https://pubs.opengroup.org/onlinepubs/96999197
7878
2. Move the jar into its well-known location.
7979

8080
```shell
81-
mv /path/to/jar "${HOME}/.library_generation/gapic-generator-java.jar"
81+
mv ~/.m2/repository/com/google/api/gapic-generator-java/{version}/gapic-generator-java-{version}.jar "${HOME}/.library_generation/gapic-generator-java.jar"
8282
```
8383

8484
#### Put the protobuf compiler in its well-known location
@@ -130,6 +130,9 @@ owl-bot copy-code --version
130130
The key step is `npm link`, which will make the command available in you current
131131
shell session.
132132

133+
If you get a permission denied error when running the command `owl-bot`, try
134+
relinking owl-bot by running `npm unlink -g` and re-running the steps above.
135+
133136
## Run the script
134137
The entrypoint script (`hermetic_build/library_generation/cli/entry_point.py`)
135138
allows you to generate a GAPIC repository with a given api definition (proto,
@@ -153,12 +156,14 @@ export path_to_repo="$(pwd)/google-cloud-java"
153156
### Install the scripts
154157

155158
You can skip this step if you've installed the packages in [Install package dependencies](#install-package-dependencies).
159+
Use the `--editable` flag for your changes to take effect as soon as you modify any file inside
160+
the package.
156161

157162
```shell
158163
python -m pip install --require-hashes -r hermetic_build/common/requirements.txt
159-
python -m pip install hermetic_build/common
164+
python -m pip install --editable hermetic_build/common
160165
python -m pip install --require-hashes -r hermetic_build/library_generation/requirements.txt
161-
python -m pip install hermetic_build/library_generation
166+
python -m pip install --editable hermetic_build/library_generation
162167
```
163168

164169
### Run the script

hermetic_build/library_generation/generate_library.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -eo pipefail
3+
set -exo pipefail
44

55
# parse input parameters
66
while [[ $# -gt 0 ]]; do
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
externalManifests:
2+
- type: json
3+
file: 'synth.metadata'
4+
jsonpath: '$.generatedFiles[*]'
5+
- type: json
6+
file: '.github/readme/synth.metadata/synth.metadata'
7+
jsonpath: '$.generatedFiles[*]'
8+
ignoreAuthors:
9+
- 'renovate-bot'
10+
- 'yoshi-automation'
11+
- 'release-please[bot]'
12+
- 'gcf-owl-bot[bot]'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
:: Copyright 2022 Google LLC
2+
::
3+
:: Licensed under the Apache License, Version 2.0 (the "License");
4+
:: you may not use this file except in compliance with the License.
5+
:: You may obtain a copy of the License at
6+
::
7+
:: http://www.apache.org/licenses/LICENSE-2.0
8+
::
9+
:: Unless required by applicable law or agreed to in writing, software
10+
:: distributed under the License is distributed on an "AS IS" BASIS,
11+
:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
:: See the License for the specific language governing permissions and
13+
:: limitations under the License.
14+
:: Github action job to test core java library features on
15+
:: downstream client libraries before they are released.
16+
:: See documentation in type-shell-output.bat
17+
18+
"C:\Program Files\Git\bin\bash.exe" %~dp0build.sh
Lines changed: 117 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/bin/bash
2-
3-
# Copyright 2018 Google LLC
2+
# Copyright 2019 Google LLC
43
#
54
# Licensed under the Apache License, Version 2.0 (the "License");
65
# you may not use this file except in compliance with the License.
76
# You may obtain a copy of the License at
87
#
9-
# https://www.apache.org/licenses/LICENSE-2.0
8+
# http://www.apache.org/licenses/LICENSE-2.0
109
#
1110
# Unless required by applicable law or agreed to in writing, software
1211
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,13 +15,121 @@
1615

1716
set -eo pipefail
1817

19-
cd github/synthtool
18+
## Get the directory of the build script
19+
scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}"))
20+
## cd to the parent directory, i.e. the root of the git repo
21+
cd ${scriptDir}/..
22+
23+
# include common functions
24+
source ${scriptDir}/common.sh
25+
26+
# Print out Maven & Java version
27+
mvn -version
28+
echo ${JOB_TYPE}
29+
30+
# attempt to install 3 times with exponential backoff (starting with 10 seconds)
31+
retry_with_backoff 3 10 \
32+
mvn install -B -V -ntp \
33+
-DskipTests=true \
34+
-Dclirr.skip=true \
35+
-Denforcer.skip=true \
36+
-Dmaven.javadoc.skip=true \
37+
-Dgcloud.download.skip=true \
38+
-T 1C
39+
40+
# if GOOGLE_APPLICATION_CREDENTIALS is specified as a relative path, prepend Kokoro root directory onto it
41+
if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then
42+
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS})
43+
fi
44+
45+
RETURN_CODE=0
46+
set +e
47+
48+
case ${JOB_TYPE} in
49+
test)
50+
echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}"
51+
mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT}
52+
RETURN_CODE=$?
53+
;;
54+
lint)
55+
mvn com.coveo:fmt-maven-plugin:check -B -ntp
56+
RETURN_CODE=$?
57+
;;
58+
javadoc)
59+
mvn javadoc:javadoc javadoc:test-javadoc -B -ntp
60+
RETURN_CODE=$?
61+
;;
62+
integration)
63+
mvn -B ${INTEGRATION_TEST_ARGS} \
64+
-ntp \
65+
-Penable-integration-tests \
66+
-DtrimStackTrace=false \
67+
-Dclirr.skip=true \
68+
-Denforcer.skip=true \
69+
-fae \
70+
verify
71+
RETURN_CODE=$?
72+
;;
73+
graalvm)
74+
# Run Unit and Integration Tests with Native Image
75+
mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative test
76+
RETURN_CODE=$?
77+
;;
78+
graalvm17)
79+
# Run Unit and Integration Tests with Native Image
80+
mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative test
81+
RETURN_CODE=$?
82+
;;
83+
samples)
84+
SAMPLES_DIR=samples
85+
# only run ITs in snapshot/ on presubmit PRs. run ITs in all 3 samples/ subdirectories otherwise.
86+
if [[ ! -z ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ]]
87+
then
88+
SAMPLES_DIR=samples/snapshot
89+
fi
90+
91+
if [[ -f ${SAMPLES_DIR}/pom.xml ]]
92+
then
93+
for FILE in ${KOKORO_GFILE_DIR}/secret_manager/*-samples-secrets; do
94+
[[ -f "$FILE" ]] || continue
95+
source "$FILE"
96+
done
97+
98+
pushd ${SAMPLES_DIR}
99+
mvn -B \
100+
-ntp \
101+
-DtrimStackTrace=false \
102+
-Dclirr.skip=true \
103+
-Denforcer.skip=true \
104+
-fae \
105+
verify
106+
RETURN_CODE=$?
107+
popd
108+
else
109+
echo "no sample pom.xml found - skipping sample tests"
110+
fi
111+
;;
112+
clirr)
113+
mvn -B -ntp -Denforcer.skip=true clirr:check
114+
RETURN_CODE=$?
115+
;;
116+
*)
117+
;;
118+
esac
119+
120+
if [ "${REPORT_COVERAGE}" == "true" ]
121+
then
122+
bash ${KOKORO_GFILE_DIR}/codecov.sh
123+
fi
20124

21-
# Disable buffering, so that the logs stream through.
22-
export PYTHONUNBUFFERED=1
125+
# fix output location of logs
126+
bash .kokoro/coerce_logs.sh
23127

24-
# Run tests
25-
nox -s lint test
128+
if [[ "${ENABLE_FLAKYBOT}" == "true" ]]
129+
then
130+
chmod +x ${KOKORO_GFILE_DIR}/linux_amd64/flakybot
131+
${KOKORO_GFILE_DIR}/linux_amd64/flakybot -repo={{metadata['repo']['repo']}}
132+
fi
26133

27-
# remove all files, preventing kokoro from trying to sync them.
28-
rm -rf *
134+
echo "exiting with ${RETURN_CODE}"
135+
exit ${RETURN_CODE}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# Copyright 2019 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+
# This script finds and moves sponge logs so that they can be found by placer
17+
# and are not flagged as flaky by sponge.
18+
19+
set -eo pipefail
20+
21+
## Get the directory of the build script
22+
scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}"))
23+
## cd to the parent directory, i.e. the root of the git repo
24+
cd ${scriptDir}/..
25+
26+
job=$(basename ${KOKORO_JOB_NAME})
27+
28+
echo "coercing sponge logs..."
29+
for xml in `find . -name *-sponge_log.xml`
30+
do
31+
class=$(basename ${xml} | cut -d- -f2)
32+
dir=$(dirname ${xml})/${job}/${class}
33+
text=$(dirname ${xml})/${class}-sponge_log.txt
34+
mkdir -p ${dir}
35+
mv ${xml} ${dir}/sponge_log.xml
36+
mv ${text} ${dir}/sponge_log.txt
37+
done
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# Format: //devtools/kokoro/config/proto/build.proto
22

3-
# Download trampoline resources.
3+
# Download trampoline resources. These will be in ${KOKORO_GFILE_DIR}
44
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
55

6-
# Use the trampoline script to run in docker.
7-
build_file: "synthtool/.kokoro/trampoline.sh"
8-
9-
# Configure the docker image for kokoro-trampoline.
10-
env_vars: {
11-
key: "TRAMPOLINE_IMAGE"
12-
value: "gcr.io/cloud-devrel-kokoro-resources/python"
13-
}
6+
# All builds use the trampoline script to run in docker.
7+
build_file: "{{ metadata['repo']['repo_short'] }}/.kokoro/trampoline.sh"
148

159
# Tell the trampoline which build file to use.
1610
env_vars: {
17-
key: "TRAMPOLINE_BUILD_FILE"
18-
value: "github/synthtool/.kokoro/build.sh"
11+
key: "TRAMPOLINE_BUILD_FILE"
12+
value: "github/{{ metadata['repo']['repo_short'] }}/.kokoro/build.sh"
1913
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# Copyright 2020 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+
function retry_with_backoff {
17+
attempts_left=$1
18+
sleep_seconds=$2
19+
shift 2
20+
command=$@
21+
22+
23+
# store current flag state
24+
flags=$-
25+
26+
# allow a failures to continue
27+
set +e
28+
${command}
29+
exit_code=$?
30+
31+
# restore "e" flag
32+
if [[ ${flags} =~ e ]]
33+
then set -e
34+
else set +e
35+
fi
36+
37+
if [[ $exit_code == 0 ]]
38+
then
39+
return 0
40+
fi
41+
42+
# failure
43+
if [[ ${attempts_left} > 0 ]]
44+
then
45+
echo "failure (${exit_code}), sleeping ${sleep_seconds}..."
46+
sleep ${sleep_seconds}
47+
new_attempts=$((${attempts_left} - 1))
48+
new_sleep=$((${sleep_seconds} * 2))
49+
retry_with_backoff ${new_attempts} ${new_sleep} ${command}
50+
fi
51+
52+
return $exit_code
53+
}
54+
55+
## Helper functionss
56+
function now() { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n'; }
57+
function msg() { println "$*" >&2; }
58+
function println() { printf '%s\n' "$(now) $*"; }
59+
60+
## Helper comment to trigger updated repo dependency release
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Build logs will be here
4+
action {
5+
define_artifacts {
6+
regex: "**/*sponge_log.xml"
7+
regex: "**/*sponge_log.txt"
8+
}
9+
}
10+
11+
# Download trampoline resources.
12+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
13+
14+
# Use the trampoline script to run in docker.
15+
build_file: "{{ metadata['repo']['repo_short'] }}/.kokoro/trampoline.sh"
16+
17+
env_vars: {
18+
key: "TRAMPOLINE_BUILD_FILE"
19+
value: "github/{{ metadata['repo']['repo_short'] }}/.kokoro/build.sh"
20+
}
21+
22+
env_vars: {
23+
key: "JOB_TYPE"
24+
value: "test"
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "REPORT_COVERAGE"
11+
value: "true"
12+
}

0 commit comments

Comments
 (0)