From b06fef8a96e39edba044ef2e9a669dc3455cbdb0 Mon Sep 17 00:00:00 2001 From: Adriano Cunha Date: Tue, 17 Jul 2018 20:21:41 -0700 Subject: [PATCH] Use presubmit-tests.sh helper from prow-tests image We're consolidating the test infrastructure into a single place, so all components gets fixes, updates and new features. --- test/presubmit-tests.sh | 57 +++-------------------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/test/presubmit-tests.sh b/test/presubmit-tests.sh index 205382b..0b3dc2e 100755 --- a/test/presubmit-tests.sh +++ b/test/presubmit-tests.sh @@ -18,17 +18,11 @@ # It is started by prow for each PR. # For convenience, it can also be executed manually. -set -o errexit -set -o pipefail - -# Extensions or file patterns that don't require presubmit tests -readonly NO_PRESUBMIT_FILES=(\.md \.png ^OWNERS) - -[ -f /workspace/library.sh ] && source /workspace/library.sh || eval "$(docker run --entrypoint sh gcr.io/knative-tests/test-infra/prow-tests -c 'cat library.sh')" +[ -f /workspace/presubmit-tests.sh ] \ + && source /workspace/presubmit-tests.sh \ + || eval "$(docker run --entrypoint sh gcr.io/knative-tests/test-infra/prow-tests -c 'cat presubmit-tests.sh')" [ -v KNATIVE_TEST_INFRA ] || exit 1 -# Helper functions. - function build_tests() { header "TODO(#23): write build tests" } @@ -41,47 +35,4 @@ function integration_tests() { ./test/e2e-tests.sh } -# Script entry point. - -# Parse script argument: -# --all-tests or no arguments: run all tests -# --build-tests: run only the build tests -# --unit-tests: run only the unit tests -# --integration-tests: run only the integration tests -RUN_BUILD_TESTS=0 -RUN_UNIT_TESTS=0 -RUN_INTEGRATION_TESTS=0 -[[ -z "$1" || "$1" == "--all-tests" ]] && RUN_BUILD_TESTS=1 && RUN_UNIT_TESTS=1 && RUN_INTEGRATION_TESTS=1 -[[ "$1" == "--build-tests" ]] && RUN_BUILD_TESTS=1 -[[ "$1" == "--unit-tests" ]] && RUN_UNIT_TESTS=1 -[[ "$1" == "--integration-tests" ]] && RUN_INTEGRATION_TESTS=1 -readonly RUN_BUILD_TESTS -readonly RUN_UNIT_TESTS -readonly RUN_INTEGRATION_TESTS - -if ! (( RUN_BUILD_TESTS+RUN_UNIT_TESTS+RUN_INTEGRATION_TESTS )); then - echo "error: unknown argument $1"; - exit 1 -fi - -cd ${REPO_ROOT_DIR} - -# Skip presubmit tests if whitelisted files were changed. -if [[ -n "${PULL_PULL_SHA}" ]]; then - # On a presubmit job - changes="$(git diff --name-only ${PULL_PULL_SHA} ${PULL_BASE_SHA})" - no_presubmit_pattern="${NO_PRESUBMIT_FILES[*]}" - no_presubmit_pattern="\(${no_presubmit_pattern// /\\|}\)$" - echo -e "Changed files in commit ${PULL_PULL_SHA}:\n${changes}" - if [[ -z "$(echo "${changes}" | grep -v ${no_presubmit_pattern})" ]]; then - # Nothing changed other than files that don't require presubmit tests - header "Commit only contains changes that don't affect tests, skipping" - exit 0 - fi -fi - -# Tests to be performed, in the right order if --all-tests is passed. - -if (( RUN_BUILD_TESTS )); then build_tests; fi -if (( RUN_UNIT_TESTS )); then unit_tests; fi -if (( RUN_INTEGRATION_TESTS )); then integration_tests; fi +main $@