Skip to content

Commit

Permalink
testing: skip unrelated Cloud Run testing on PR checks (#2870)
Browse files Browse the repository at this point in the history
  • Loading branch information
grayside authored Nov 28, 2022
1 parent 656ed7f commit e252bdf
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .kokoro/build-with-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,59 @@ popd
export GOOGLE_CLOUD_PROJECT=nodejs-docs-samples-tests
pushd github/nodejs-docs-samples/${PROJECT}

# Verify changes are worth testing.
# Identify changes excluding files that have no bearing on sample functionality.
ignore_pattern='\.md$|^\.github|\.gitignore|^LICENSE|^CODEOWNERS|^\.eslint|\.prettier|^linkinator|^renovate'
SIGNIFICANT_CHANGES="$(git --no-pager diff --name-only main..HEAD | grep -Ev ${ignore_pattern} || true)"

# If this is a PR with only insignificant changes, don't run any tests.
if [[ -n ${KOKORO_GITHUB_PULL_REQUEST_NUMBER:-} ]] && [[ -z "$SIGNIFICANT_CHANGES" ]]; then
echo "No significant changes. Skipping ${PROJECT} tests."
exit 0
fi

# CHANGED_DIRS is the list of directories that changed.
# CHANGED_DIRS will be empty when run on main.
CHANGED_DIRS=$(echo "$SIGNIFICANT_CHANGES" | tr ' ' '\n' | xargs dirname 2>/dev/null || true)

# Default to not running the test.
match=0

# If CHANGED_DIRS is empty, default to running the tests.
# This ensures nightly tests will run.
if [[ "$CHANGED_DIRS" == "" ]]; then
echo "Running the test: Run all tests on the main branch."
match=1
fi

# PROJECT is set by Kokoro to the path of the Cloud Run sample under test.
# If any of our changed directories starts with that path, run the tests.
# Otherwise, skip running the tests.
# The asterisk in "$PROJECT"* is what causes the tests to run if any
# sub-directory carries a change.
for c in ${CHANGED_DIRS}; do
if [[ "$c" == "$PROJECT"* ]]; then
echo "Running the test: Changes found inside '{$PROJECT}'"
match=1
fi
done

# If Cloud Run related Kokoro config is changed, run the tests.
# This matches on all Cloud Run tests if any config is modified.
for k in '.kokoro/build-with-run.sh' '.kokoro/common.cfg' '.kokoro/.mocharc.js' '.kokoro/run'; do
for s in ${SIGNIFICANT_CHANGES}; do
if [[ "$s" == "$k"* ]]; then
echo "Running the test: Changes to Cloud Run .kokoro configuration detected"
match=1
fi
done
done

if [[ $match == 0 ]]; then
echo "Project ${PROJECT} had no changes."
exit 0
fi

# Update gcloud
gcloud --quiet components update
gcloud --quiet components install beta
Expand Down

0 comments on commit e252bdf

Please sign in to comment.