Skip to content

testing: various cleanups #3879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .kokoro/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ cd github/python-docs-samples
pip install -q nox

# Use secrets acessor service account to get secrets
gcloud auth activate-service-account \
--key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \
--project="cloud-devrel-kokoro-resources"
if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then
gcloud auth activate-service-account \
--key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \
--project="cloud-devrel-kokoro-resources"
fi

# This script will create 3 files:
# - testing/test-env.sh
# - testing/service-account.json
# - testing/client-secrets.json
./scripts/decrypt-secrets.sh

source ./testing/test-env.sh
Expand All @@ -51,12 +58,9 @@ gcloud auth activate-service-account \
--key-file "${GOOGLE_APPLICATION_CREDENTIALS}"

export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json
source "${KOKORO_GFILE_DIR}/automl_secrets.txt"

# For Datalabeling samples to hit the testing endpoint
export DATALABELING_ENDPOINT="test-datalabeling.sandbox.googleapis.com:443"
# Required for "run/image-processing" && "functions/imagemagick"
apt-get -qq update && apt-get -qq install libmagickwand-dev > /dev/null

# Run Cloud SQL proxy (background process exit when script does)
wget --quiet https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy && chmod +x cloud_sql_proxy
Expand All @@ -70,6 +74,17 @@ set +e
# Use RTN to return a non-zero value if the test fails.
RTN=0
ROOT=$(pwd)

# If some files in .kokoro directory have any changes, we will test everything.
test_all="true"
if [[ -n "${DIFF_FROM:-}" ]]; then
git diff --quiet "$DIFF_FROM" .kokoro/docker .kokoro/tests
CHANGED=$?
if [[ "$CHANGED" -eq 0 ]]; then
test_all="false"
fi
fi

# Find all requirements.txt in the repository (may break on whitespace).
for file in **/requirements.txt; do
cd "$ROOT"
Expand All @@ -78,7 +93,7 @@ for file in **/requirements.txt; do
cd "$file"

# If $DIFF_FROM is set, use it to check for changes in this directory.
if [[ "$DIFF_FROM" != "" ]]; then
if [[ -n "${DIFF_FROM:-}" ]] && [[ "${test_all}" == "false" ]]; then
git diff --quiet "$DIFF_FROM" .
CHANGED=$?
if [[ "$CHANGED" -eq 0 ]]; then
Expand Down
14 changes: 11 additions & 3 deletions scripts/decrypt-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ ROOT=$( dirname "$DIR" )
# Work from the project root.
cd $ROOT

gcloud secrets versions access latest --secret="python-docs-samples-test-env" > testing/test-env.sh
gcloud secrets versions access latest --secret="python-docs-samples-service-account" > testing/service-account.json
gcloud secrets versions access latest --secret="python-docs-samples-client-secrets" > testing/client-secrets.json
# Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources.
PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}"

gcloud secrets versions access latest --secret="python-docs-samples-test-env" \
> testing/test-env.sh
gcloud secrets versions access latest \
--secret="python-docs-samples-service-account" \
> testing/service-account.json
gcloud secrets versions access latest \
--secret="python-docs-samples-client-secrets" \
> testing/client-secrets.json
17 changes: 14 additions & 3 deletions scripts/encrypt-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ ROOT=$( dirname "$DIR" )
# Work from the project root.
cd $ROOT

gcloud secrets versions add "python-docs-samples-test-env" --data-file="testing/test-env.sh"
gcloud secrets versions add "python-docs-samples-service-account" --data-file="testing/service-account.json"
gcloud secrets versions add "python-docs-samples-client-secrets" --data-file="testing/client-secrets.json"
# Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources.
PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}"

gcloud secrets versions add "python-docs-samples-test-env" \
--project="${PROJECT_ID}" \
--data-file="testing/test-env.sh"

gcloud secrets versions add "python-docs-samples-service-account" \
--project="${PROJECT_ID}" \
--data-file="testing/service-account.json"

gcloud secrets versions add "python-docs-samples-client-secrets" \
--project="${PROJECT_ID}" \
--data-file="testing/client-secrets.json"