From 3e33c90eb30caa1cc11bf90a4cec46165c632c3e Mon Sep 17 00:00:00 2001 From: Adriano Cunha <35786489+adrcunha@users.noreply.github.com> Date: Tue, 15 Jan 2019 08:53:31 -0800 Subject: [PATCH] Allow disabling markdown check steps in the default build test (#391) * Allow disabling markdown check steps in the default build test * Update comment in script * Update documentation --- scripts/README.md | 11 +++++++++-- scripts/presubmit-tests.sh | 34 +++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index ec9f58fbc1..4205f84ab1 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -12,16 +12,23 @@ This is a helper script to run the presubmit tests. To use it: 1. [optional] Define the function `build_tests()`. If you don't define this function, the default action for running the build tests is to: - - lint and link check markdown files + - check markdown files - run `go build` on the entire repo - run `/hack/verify-codegen.sh` (if it exists) - - check licenses in `/cmd` (if it exists) + - check licenses in all go packages The markdown link checker tools doesn't check `localhost` links by default. Its configuration file, `markdown-link-check-config.json`, lives in the `test-infra/scripts` directory. To override it, create a file with the same name, containing the custom config in the `/test` directory. +1. [optional] Customize the default build test runner, if you're using it. Set + the following environment variables if the default values don't fit your needs: + + - `DISABLE_MD_LINTING`: Disable linting markdown files, defaults to 0 (false). + - `DISABLE_MD_LINK_CHECK`: Disable checking links in markdown files, defaults + to 0 (false). + 1. [optional] Define the functions `pre_build_tests()` and/or `post_build_tests()`. These functions will be called before or after the build tests (either your custom one or the default action) and will cause diff --git a/scripts/presubmit-tests.sh b/scripts/presubmit-tests.sh index a2079afa76..576da49cd2 100755 --- a/scripts/presubmit-tests.sh +++ b/scripts/presubmit-tests.sh @@ -19,6 +19,10 @@ source $(dirname ${BASH_SOURCE})/library.sh +# Custom configuration of presubmit tests +readonly DISABLE_MD_LINTING=${DISABLE_MD_LINTING:-0} +readonly DISABLE_MD_LINK_CHECK=${DISABLE_MD_LINK_CHECK:-0} + # Extensions or file patterns that don't require presubmit tests. readonly NO_PRESUBMIT_FILES=(\.png \.gitignore \.gitattributes ^OWNERS ^OWNERS_ALIASES ^AUTHORS) @@ -103,21 +107,33 @@ function run_build_tests() { return ${failed} } -# Default build test runner that: -# * lint and link check markdown files -# * `go build` on the entire repo -# * run `/hack/verify-codegen.sh` (if it exists) -# * check licenses in `/cmd` (if it exists) -function default_build_test_runner() { - local failed=0 - # Ignore markdown files in /vendor +# Perform markdown build tests if necessary, unless disabled. +function markdown_build_tests() { + (( DISABLE_MD_LINTING && DISABLE_MD_LINK_CHECK )) && return 0 + # Get changed markdown files (ignore /vendor) local mdfiles="$(echo "${CHANGED_FILES}" | grep \.md$ | grep -v ^vendor/)" - if [[ -n "${mdfiles}" ]]; then + [[ -z "${mdfiles}" ]] && return 0 + local failed=0 + if (( ! DISABLE_MD_LINTING )); then subheader "Linting the markdown files" lint_markdown ${mdfiles} || failed=1 + fi + if (( ! DISABLE_MD_LINK_CHECK )); then subheader "Checking links in the markdown files" check_links_in_markdown ${mdfiles} || failed=1 fi + return ${failed} +} + +# Default build test runner that: +# * check markdown files +# * `go build` on the entire repo +# * run `/hack/verify-codegen.sh` (if it exists) +# * check licenses in all go packages +function default_build_test_runner() { + local failed=0 + # Perform markdown build checks first + markdown_build_tests || failed=1 # For documentation PRs, just check the md files (( IS_DOCUMENTATION_PR )) && return ${failed} # Ensure all the code builds