Skip to content

Commit

Permalink
Allow disabling markdown check steps in the default build test (knati…
Browse files Browse the repository at this point in the history
…ve#391)

* Allow disabling markdown check steps in the default build test

* Update comment in script

* Update documentation
  • Loading branch information
adrcunha authored and knative-prow-robot committed Jan 15, 2019
1 parent 9bb7bc2 commit 3e33c90
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
11 changes: 9 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 25 additions & 9 deletions scripts/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e33c90

Please sign in to comment.