Skip to content

Commit 306efd9

Browse files
authored
Add basic Kokoro config for api_core. (googleapis#5688)
1 parent d64fb53 commit 306efd9

File tree

7 files changed

+176
-13
lines changed

7 files changed

+176
-13
lines changed

.kokoro/api_core-continuous.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Tell the trampoline which build file to use.
4+
env_vars: {
5+
key: "PACKAGE"
6+
value: "api_core"
7+
}

.kokoro/api_core-presubmit.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Tell the trampoline which build file to use.
4+
env_vars: {
5+
key: "PACKAGE"
6+
value: "api_core"
7+
}

.kokoro/build.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Copyright 2018 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eo pipefail
18+
19+
cd github/google-cloud-python
20+
21+
# Disable buffering, so that the logs stream through.
22+
export PYTHONUNBUFFERED=1
23+
24+
# Find out if this package was modified.
25+
python3.6 -m pip install git+https://github.com/tswast/ci-diff-helper.git
26+
python3.6 test_utils/scripts/get_target_packages_kokoro.py > ~/target_packages
27+
cat ~/target_packages
28+
29+
if [[ ! -n $(grep -x "$PACKAGE" ~/target_packages) ]]; then
30+
echo "$PACKAGE was not modified, returning."
31+
exit;
32+
fi
33+
34+
cd "$PACKAGE"
35+
36+
python3.6 -m pip install --quiet nox-automation
37+
38+
nox

.kokoro/common.cfg

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
# Format: //devtools/kokoro/config/proto/build.proto
2+
23
# Build logs will be here
34
action {
45
define_artifacts {
56
regex: "**/*sponge_log.xml"
67
}
78
}
8-
# The github token is stored here.
9-
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/dpebot"
10-
# Common env vars for all repositories and builds.
9+
10+
# Download trampoline resources.
11+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
12+
13+
# Use the trampoline script to run in docker.
14+
build_file: "synthtool/.kokoro/trampoline.sh"
15+
16+
# Configure the docker image for kokoro-trampoline.
1117
env_vars: {
12-
key: "GITHUB_TOKEN_FILE"
13-
value: "github-token.txt"
14-
}
15-
env_vars: {
16-
key: "GITHUB_USER"
17-
value: "dpebot"
18-
}
19-
env_vars: {
20-
key: "GITHUB_EMAIL"
21-
value: "dpebot@google.com"
18+
key: "TRAMPOLINE_IMAGE"
19+
value: "gcr.io/cloud-devrel-kokoro-resources/python"
2220
}

.kokoro/docs.cfg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Don't bother with trampoline, we can use the Python in the Kokoro VM to build
4+
# the docs.
25
build_file: "google-cloud-python/.kokoro/build-docs.sh"
6+
7+
# The github token is stored here.
8+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/dpebot"
9+
10+
# Common env vars for all and builds.
11+
env_vars: {
12+
key: "GITHUB_TOKEN_FILE"
13+
value: "github-token.txt"
14+
}
15+
env_vars: {
16+
key: "GITHUB_USER"
17+
value: "dpebot"
18+
}
19+
env_vars: {
20+
key: "GITHUB_EMAIL"
21+
value: "dpebot@google.com"
22+
}

.kokoro/trampoline.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Copyright 2017 Google Inc.
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+
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2017 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+
15+
"""Print a list of packages which require testing."""
16+
17+
import subprocess
18+
import pathlib
19+
20+
import ci_diff_helper
21+
22+
23+
def print_environment(environment):
24+
print("-> CI environment:")
25+
print('Branch', environment.branch)
26+
print('PR', environment.pr)
27+
print('In PR', environment.in_pr)
28+
print('Repo URL', environment.repo_url)
29+
if environment.in_pr:
30+
print('PR Base', environment.base)
31+
32+
33+
def get_base(environment):
34+
if environment.in_pr:
35+
return environment.base
36+
else:
37+
# If we're not in a PR, just calculate the changes between this commit
38+
# and its parent.
39+
return 'HEAD~1'
40+
41+
42+
def get_changed_files(base):
43+
return subprocess.check_output([
44+
'git', 'diff', '--name-only', f'{base}..HEAD',
45+
], stderr=subprocess.DEVNULL).decode('utf8').strip().split('\n')
46+
47+
48+
def determine_changed_packages(changed_files):
49+
packages = [
50+
path.parent for path in pathlib.Path('.').glob('*/nox.py')
51+
]
52+
53+
changed_packages = set()
54+
for file in changed_files:
55+
file = pathlib.Path(file)
56+
for package in packages:
57+
if package in file.parents:
58+
changed_packages.add(package)
59+
60+
return changed_packages
61+
62+
63+
def main():
64+
environment = ci_diff_helper.get_config()
65+
print_environment(environment)
66+
base = get_base(environment)
67+
changed_files = get_changed_files(base)
68+
packages = determine_changed_packages(changed_files)
69+
70+
print(f"Comparing against {base}.")
71+
print("-> Changed packages:")
72+
73+
for package in packages:
74+
print(package)
75+
76+
77+
main()

0 commit comments

Comments
 (0)