Skip to content

Commit 9459fe0

Browse files
authored
Kokoro Docs Builds (googleapis#5558)
* initial kokoro configs. bring publishing back to update_docs script
1 parent d6c6590 commit 9459fe0

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

.kokoro/build-docs.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
cd ${KOKORO_ARTIFACTS_DIR}/git/google-cloud-python
6+
pwd
7+
ls
8+
env
9+
10+
# Kokoro currently uses 3.6.1
11+
pyenv global 3.6.1
12+
13+
# Kokoro exposes this as a file, but the scripts expect just a plain variable.
14+
export GITHUB_TOKEN=$(cat ${KOKORO_GFILE_DIR}/${GITHUB_TOKEN_FILE})
15+
16+
# Add github to known hosts.
17+
ssh-keyscan github.com >> ~/.ssh/known_hosts
18+
19+
# Activate the ssh key for dpebot. This is used to clone
20+
# repositories using the ssh:// protocol.
21+
eval `ssh-agent -s`
22+
chmod 600 ${KOKORO_GFILE_DIR}/id_rsa
23+
ssh-add ${KOKORO_GFILE_DIR}/id_rsa
24+
25+
# Build and Publish Documentation
26+
bash test_utils/scripts/update_docs.sh kokoro

.kokoro/common.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
# Build logs will be here
3+
action {
4+
define_artifacts {
5+
regex: "**/*sponge_log.xml"
6+
}
7+
}
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.
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/docs.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
build_file: "google-cloud-python/.kokoro/build-docs.sh"

test_utils/scripts/update_docs.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function build_docs {
3232
# Only update docs if we are on CircleCI.
3333
if [[ "${CIRCLE_BRANCH}" == "master" ]] && [[ -z "${CIRCLE_PR_NUMBER}" ]]; then
3434
echo "Building new docs on a merged commit."
35+
elif [[ "$1" == "kokoro" ]]; then
36+
echo "Building and publishing docs on Kokoro."
3537
elif [[ -n "${CIRCLE_TAG}" ]]; then
3638
echo "Building new docs on a tag (but will not deploy)."
3739
build_docs
@@ -43,3 +45,46 @@ else
4345
exit $?
4446
fi
4547

48+
# Adding GitHub pages branch. `git submodule add` checks it
49+
# out at HEAD.
50+
GH_PAGES_DIR='ghpages'
51+
git submodule add -q -b gh-pages \
52+
"git@github.com:${GH_OWNER}/${GH_PROJECT_NAME}" ${GH_PAGES_DIR}
53+
54+
# Determine if we are building a new tag or are building docs
55+
# for master. Then build new docs in docs/_build from master.
56+
if [[ -n "${CIRCLE_TAG}" ]]; then
57+
# Sphinx will use the package version by default.
58+
build_docs
59+
else
60+
SPHINX_RELEASE=$(git log -1 --pretty=%h) build_docs
61+
fi
62+
63+
# Get the current version.
64+
# This is only likely to work from within nox, because the google-cloud
65+
# package must be installed.
66+
CURRENT_VERSION=$(python ${DIR}/get_version.py)
67+
68+
# Update gh-pages with the created docs.
69+
cd ${GH_PAGES_DIR}
70+
git rm -fr latest/
71+
cp -R ../docs/_build/html/ latest/
72+
73+
# Update the files push to gh-pages.
74+
git add .
75+
git status
76+
77+
# If there are no changes, just exit cleanly.
78+
if [[ -z "$(git status --porcelain)" ]]; then
79+
echo "Nothing to commit. Exiting without pushing changes."
80+
exit
81+
fi
82+
83+
# Commit to gh-pages branch to apply changes.
84+
git config --global user.email "dpebot@google.com"
85+
git config --global user.name "dpebot"
86+
git commit -m "Update docs after merge to master."
87+
88+
# NOTE: This may fail if two docs updates (on merges to master)
89+
# happen in close proximity.
90+
git push -q origin HEAD:gh-pages

0 commit comments

Comments
 (0)