Skip to content

Commit

Permalink
build: add Kokoro release jobs (#3247)
Browse files Browse the repository at this point in the history
* build: add Kokoro release jobs

* chore: quoting
  • Loading branch information
chingor13 authored Aug 2, 2022
1 parent 5366d2a commit 7d7295b
Show file tree
Hide file tree
Showing 13 changed files with 907 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .kokoro/common.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Build logs will be here
action {
define_artifacts {
regex: "**/*sponge_log.xml"
}
}

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "google-cloud-node/.kokoro/trampoline_v2.sh"

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/node:12-user"
}
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-cloud-node/.kokoro/test.sh"
}
76 changes: 76 additions & 0 deletions .kokoro/populate-secrets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
# Copyright 2022 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is called in the early stage of `trampoline_v2.sh` to
# populate secrets needed for the CI builds.

set -eo pipefail

function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
function msg { println "$*" >&2 ;}
function println { printf '%s\n' "$(now) $*" ;}

# Populates requested secrets set in SECRET_MANAGER_KEYS

# In Kokoro CI builds, we use the service account attached to the
# Kokoro VM. This means we need to setup auth on other CI systems.
# For local run, we just use the gcloud command for retrieving the
# secrets.

if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then
GCLOUD_COMMANDS=(
"docker"
"run"
"--entrypoint=gcloud"
"--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR}"
"gcr.io/google.com/cloudsdktool/cloud-sdk"
)
if [[ "${TRAMPOLINE_CI:-}" == "kokoro" ]]; then
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
else
echo "Authentication for this CI system is not implemented yet."
exit 2
# TODO: Determine appropriate SECRET_LOCATION and the GCLOUD_COMMANDS.
fi
else
# For local run, use /dev/shm or temporary directory for
# KOKORO_GFILE_DIR.
if [[ -d "/dev/shm" ]]; then
export KOKORO_GFILE_DIR=/dev/shm
else
export KOKORO_GFILE_DIR=$(mktemp -d -t ci-XXXXXXXX)
fi
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
GCLOUD_COMMANDS=("gcloud")
fi

msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
mkdir -p ${SECRET_LOCATION}

for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
do
msg "Retrieving secret ${key}"
"${GCLOUD_COMMANDS[@]}" \
secrets versions access latest \
--project cloud-devrel-kokoro-resources \
--secret $key > \
"$SECRET_LOCATION/$key"
if [[ $? == 0 ]]; then
msg "Secret written to ${SECRET_LOCATION}/${key}"
else
msg "Error retrieving secret ${key}"
exit 2
fi
done
24 changes: 24 additions & 0 deletions .kokoro/release/docs-devsite-single.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to the rightmost comment to exit
# with a non-zero
set -eo pipefail

npm install

# publish docs to devsite
npx @google-cloud/[email protected]
23 changes: 23 additions & 0 deletions .kokoro/release/docs-devsite.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# service account used to publish up-to-date docs.
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "docuploader_service_account"
}
}
}

# doc publications use a Python image.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user"
}

# Use the trampoline script to run in docker.
build_file: "google-cloud-node/.kokoro/trampoline_v2.sh"

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-cloud-node/.kokoro/release/docs-devsite.sh"
}
29 changes: 29 additions & 0 deletions .kokoro/release/docs-devsite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to the rightmost comment to exit
# with a non-zero
set -eo pipefail

if [ -z "${AUTORELEASE_PR}" ]
then
echo "Need to provide URL to release PR via AUTORELEASE_PR environment variable"
exit 1
fi

SCRIPT=$(realpath $(dirname $0)/./docs-devsite-single.sh)
npx @google-cloud/mono-repo-publish custom --script="${SCRIPT}" --pr-url="${AUTORELEASE_PR}"
46 changes: 46 additions & 0 deletions .kokoro/release/docs-single.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to the rightmost comment to exit
# with a non-zero
set -eo pipefail

# build jsdocs (Python is installed on the Node 10 docker image).
npm install
npm run docs

# create docs.metadata, based on package.json and .repo-metadata.json.
npm i [email protected] -g
python3 -m pip install --user gcp-docuploader
python3 -m docuploader create-metadata \
--name=$(cat .repo-metadata.json | json name) \
--version=$(cat package.json | json version) \
--language=$(cat .repo-metadata.json | json language) \
--distribution-name=$(cat .repo-metadata.json | json distribution_name) \
--product-page=$(cat .repo-metadata.json | json product_documentation) \
--github-repository=$(cat .repo-metadata.json | json repo) \
--issue-tracker=$(cat .repo-metadata.json | json issue_tracker)
cp docs.metadata ./docs/docs.metadata

# deploy the docs.
if [[ -z "${CREDENTIALS}" ]]; then
CREDENTIALS="${KOKORO_KEYSTORE_DIR}/73713_docuploader_service_account"
fi
if [[ -z "${BUCKET}" ]]; then
BUCKET=docs-staging
fi
python3 -m docuploader upload ./docs --credentials "${CREDENTIALS}" --staging-bucket "${BUCKET}"
23 changes: 23 additions & 0 deletions .kokoro/release/docs.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# service account used to publish up-to-date docs.
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "docuploader_service_account"
}
}
}

# doc publications use a Python image.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/node:12-user"
}

# Use the trampoline script to run in docker.
build_file: "google-cloud-node/.kokoro/trampoline_v2.sh"

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-cloud-node/.kokoro/release/docs.sh"
}
29 changes: 29 additions & 0 deletions .kokoro/release/docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to the rightmost comment to exit
# with a non-zero
set -eo pipefail

if [ -z "${AUTORELEASE_PR}" ]
then
echo "Need to provide URL to release PR via AUTORELEASE_PR environment variable"
exit 1
fi

SCRIPT=$(realpath $(dirname $0)/./docs-single.sh)
npx @google-cloud/mono-repo-publish custom --script="${SCRIPT}" --pr-url="${AUTORELEASE_PR}"
26 changes: 26 additions & 0 deletions .kokoro/release/publish-single.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to the rightmost comment to exit
# with a non-zero
set -eo pipefail

pwd

npm install

# publish library to npm
npm publish --access=public --registry=https://wombat-dressing-room.appspot.com
27 changes: 27 additions & 0 deletions .kokoro/release/publish.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
before_action {
fetch_keystore {
keystore_resource {
keystore_config_id: 73713
keyname: "google-cloud-npm-token-1"
}
}
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem"
}

# Use the trampoline script to run in docker.
build_file: "google-cloud-node/.kokoro/trampoline_v2.sh"

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/node:12-user"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/google-cloud-node/.kokoro/release/publish.sh"
}
38 changes: 38 additions & 0 deletions .kokoro/release/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# `-e` enables the script to automatically fail when a command fails
# `-o pipefail` sets the exit code to the rightmost comment to exit
# with a non-zero
set -eo pipefail

if [ -z "${AUTORELEASE_PR}" ]
then
echo "Need to provide URL to release PR via AUTORELEASE_PR environment variable"
exit 1
fi

export NPM_CONFIG_PREFIX=/home/node/.npm-global

# Start the releasetool reporter
python3 -m pip install gcp-releasetool
python3 -m releasetool publish-reporter-script > /tmp/publisher-script; source /tmp/publisher-script

NPM_TOKEN=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-npm-token-1")
echo "//wombat-dressing-room.appspot.com/:_authToken=${NPM_TOKEN}" > ~/.npmrc

SCRIPT=$(realpath $(dirname $0)/./publish-single.sh)
npx @google-cloud/mono-repo-publish custom --script="${SCRIPT}" --pr-url="${AUTORELEASE_PR}"
Loading

0 comments on commit 7d7295b

Please sign in to comment.