Update presubmit tests (#769)

Fixes #750.

* disable markdown linting
* ignore localhost links when checking for dead links in markdown files

Bonus: fix link in README.md
This commit is contained in:
Adriano Cunha 2019-01-15 10:09:30 -08:00 committed by Knative Prow Robot
parent 97c14659d1
commit b6732c9216
9 changed files with 125 additions and 45 deletions

4
Gopkg.lock generated
View File

@ -91,14 +91,14 @@
[[projects]]
branch = "master"
digest = "1:da39b58557275d30a9340c2e1e13e16691461f9859d3230f59cceed411c04b49"
digest = "1:d16837c32fbdabe592e539ca282bbeeb77faadffa20b4f3bed3bd0916c6c5397"
name = "github.com/knative/test-infra"
packages = [
"scripts",
"tools/dep-collector",
]
pruneopts = "UT"
revision = "722c0465b028a437dbe63458acb8cadae5f28165"
revision = "3e33c90eb30caa1cc11bf90a4cec46165c632c3e"
[[projects]]
digest = "1:5985ef4caf91ece5d54817c11ea25f182697534f8ae6521eadcd628c142ac4b6"

View File

@ -92,7 +92,7 @@ Follow the links below to learn more about Knative.
- [Autoscaling](./serving/samples/autoscale-go/README.md)
- [Source-to-URL deployment](./serving/samples/source-to-url-go/README.md)
- [Binding running services to eventing ecosystems](./eventing/samples/event-flow/README.md)
- [Binding running services to eventing ecosystems](./eventing/samples/kubernetes-event-source)
- [Telemetry](./serving/samples/telemetry-go/README.md)
- [REST API sample](./serving/samples/rest-api-go/README.md)
- [All samples for serving](./serving/samples/)

View File

@ -18,6 +18,9 @@
# It is started by prow for each PR.
# For convenience, it can also be executed manually.
# markdown linting is too picky for our docs; disabling it for now.
DISABLE_MD_LINTING=1
source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh
# We use the default build, unit and integration test runners.

View File

@ -11,10 +11,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
@ -84,6 +97,18 @@ main $@
This is a helper script for Knative E2E test scripts. To use it:
1. [optional] Customize the test cluster. Set the following environment variables
if the default values don't fit your needs:
- `E2E_CLUSTER_REGION`: Cluster region, defaults to `us-central1`.
- `E2E_CLUSTER_ZONE`: Cluster zone (e.g., `a`), defaults to none (i.e. use a regional
cluster).
- `E2E_CLUSTER_MACHINE`: Cluster node machine type, defaults to `n1-standard-4}`.
- `E2E_MIN_CLUSTER_NODES`: Minimum number of nodes in the cluster when autoscaling,
defaults to 1.
- `E2E_MAX_CLUSTER_NODES`: Maximum number of nodes in the cluster when autoscaling,
defaults to 3.
1. Source the script.
1. [optional] Write the `teardown()` function, which will tear down your test
@ -130,9 +155,14 @@ This is a helper script for Knative E2E test scripts. To use it:
This script will test that the latest Knative Serving nightly release works. It
defines a special flag (`--no-knative-wait`) that causes the script not to
wait for Knative Serving to be up before running the tests.
wait for Knative Serving to be up before running the tests. It also requires that
the test cluster is created in a specific region, `us-west2`.
```bash
# This test requires a cluster in LA
E2E_CLUSTER_REGION=us-west2
source vendor/github.com/knative/test-infra/scripts/e2e-tests.sh
function teardown() {

View File

@ -36,18 +36,24 @@ function build_resource_name() {
}
# Test cluster parameters
readonly E2E_BASE_NAME="k${REPO_NAME}"
readonly E2E_CLUSTER_NAME=$(build_resource_name e2e-cls)
readonly E2E_NETWORK_NAME=$(build_resource_name e2e-net)
readonly E2E_CLUSTER_REGION=us-central1
readonly E2E_CLUSTER_MACHINE=n1-standard-4
readonly TEST_RESULT_FILE=/tmp/${E2E_BASE_NAME}-e2e-result
# Configurable parameters
readonly E2E_CLUSTER_REGION=${E2E_CLUSTER_REGION:-us-central1}
# By default we use regional clusters.
readonly E2E_CLUSTER_ZONE=${E2E_CLUSTER_ZONE:-}
readonly E2E_CLUSTER_MACHINE=${E2E_CLUSTER_MACHINE:-n1-standard-4}
# Each knative repository may have a different cluster size requirement here,
# so we allow calling code to set these parameters. If they are not set we
# use some sane defaults.
readonly E2E_MIN_CLUSTER_NODES=${E2E_MIN_CLUSTER_NODES:-1}
readonly E2E_MAX_CLUSTER_NODES=${E2E_MAX_CLUSTER_NODES:-3}
readonly E2E_BASE_NAME="k${REPO_NAME}"
readonly E2E_CLUSTER_NAME=$(build_resource_name e2e-cls)
readonly E2E_NETWORK_NAME=$(build_resource_name e2e-net)
readonly TEST_RESULT_FILE=/tmp/${E2E_BASE_NAME}-e2e-result
# Flag whether test is using a boskos GCP project
IS_BOSKOS=0
@ -148,13 +154,15 @@ function create_test_cluster() {
echo "Cluster will have a minimum of ${E2E_MIN_CLUSTER_NODES} and a maximum of ${E2E_MAX_CLUSTER_NODES} nodes."
# Smallest cluster required to run the end-to-end-tests
local geoflag="--gcp-region=${E2E_CLUSTER_REGION}"
[[ -n "${E2E_CLUSTER_ZONE}" ]] && geoflag="--gcp-zone=${E2E_CLUSTER_REGION}-${E2E_CLUSTER_ZONE}"
local CLUSTER_CREATION_ARGS=(
--gke-create-args="--enable-autoscaling --min-nodes=${E2E_MIN_CLUSTER_NODES} --max-nodes=${E2E_MAX_CLUSTER_NODES} --scopes=cloud-platform --enable-basic-auth --no-issue-client-certificate"
--gke-shape={\"default\":{\"Nodes\":${E2E_MIN_CLUSTER_NODES}\,\"MachineType\":\"${E2E_CLUSTER_MACHINE}\"}}
--provider=gke
--deployment=gke
--cluster="${E2E_CLUSTER_NAME}"
--gcp-region="${E2E_CLUSTER_REGION}"
${geoflag}
--gcp-network="${E2E_NETWORK_NAME}"
--gke-environment=prod
)
@ -237,10 +245,10 @@ function setup_test_cluster() {
if [[ -z ${K8S_CLUSTER_OVERRIDE} ]]; then
USING_EXISTING_CLUSTER=0
export K8S_CLUSTER_OVERRIDE=$(kubectl config current-context)
acquire_cluster_admin_role ${K8S_USER_OVERRIDE} ${E2E_CLUSTER_NAME} ${E2E_CLUSTER_REGION}
acquire_cluster_admin_role ${K8S_USER_OVERRIDE} ${E2E_CLUSTER_NAME} ${E2E_CLUSTER_REGION} ${E2E_CLUSTER_ZONE}
# Make sure we're in the default namespace. Currently kubetest switches to
# test-pods namespace when creating the cluster.
kubectl config set-context $K8S_CLUSTER_OVERRIDE --namespace=default
kubectl config set-context ${K8S_CLUSTER_OVERRIDE} --namespace=default
fi
readonly USING_EXISTING_CLUSTER
@ -308,12 +316,7 @@ E2E_CLUSTER_VERSION=""
# Parse flags and initialize the test cluster.
function initialize() {
# Normalize calling script path; we can't use readlink because it's not available everywhere
E2E_SCRIPT=$0
[[ ${E2E_SCRIPT} =~ ^[\./].* ]] || E2E_SCRIPT="./$0"
E2E_SCRIPT="$(cd ${E2E_SCRIPT%/*} && echo $PWD/${E2E_SCRIPT##*/})"
readonly E2E_SCRIPT
E2E_SCRIPT="$(get_canonical_path $0)"
E2E_CLUSTER_VERSION="${SERVING_GKE_VERSION}"
cd ${REPO_ROOT_DIR}

View File

@ -199,11 +199,14 @@ function get_app_pods() {
# Parameters: $1 - user
# $2 - cluster name
# $3 - cluster region
# $4 - cluster zone, optional
function acquire_cluster_admin_role() {
local geoflag="--region=$3"
[[ -n $4 ]] && geoflag="--zone=$3-$4"
# Get the password of the admin and use it, as the service account (or the user)
# might not have the necessary permission.
local password=$(gcloud --format="value(masterAuth.password)" \
container clusters describe $2 --region=$3)
container clusters describe $2 ${geoflag})
if [[ -n "${password}" ]]; then
# Cluster created with basic authentication
kubectl config set-credentials cluster-admin \
@ -213,9 +216,9 @@ function acquire_cluster_admin_role() {
local key=$(mktemp)
echo "Certificate in ${cert}, key in ${key}"
gcloud --format="value(masterAuth.clientCertificate)" \
container clusters describe $2 --region=$3 | base64 -d > ${cert}
container clusters describe $2 ${geoflag} | base64 -d > ${cert}
gcloud --format="value(masterAuth.clientKey)" \
container clusters describe $2 --region=$3 | base64 -d > ${key}
container clusters describe $2 ${geoflag} | base64 -d > ${key}
kubectl config set-credentials cluster-admin \
--client-certificate=${cert} --client-key=${key}
fi
@ -226,7 +229,7 @@ function acquire_cluster_admin_role() {
--user=$1
# Reset back to the default account
gcloud container clusters get-credentials \
$2 --region=$3 --project $(gcloud config get-value project)
$2 ${geoflag} --project $(gcloud config get-value project)
}
# Runs a go test and generate a junit summary.
@ -269,6 +272,7 @@ function start_latest_knative_serving() {
wait_until_pods_running istio-system || return 1
kubectl label namespace default istio-injection=enabled || return 1
subheader "Installing Knative Build"
echo "Installing Build from ${KNATIVE_BUILD_RELEASE}"
kubectl apply -f ${KNATIVE_BUILD_RELEASE} || return 1
subheader "Installing Knative Serving"
echo "Installing Serving from ${KNATIVE_SERVING_RELEASE}"
@ -281,9 +285,11 @@ function start_latest_knative_serving() {
function start_latest_knative_build() {
header "Starting Knative Build"
subheader "Installing Istio"
echo "Installing Istio from ${KNATIVE_ISTIO_YAML}"
kubectl apply -f ${KNATIVE_ISTIO_YAML} || return 1
wait_until_pods_running istio-system || return 1
subheader "Installing Knative Build"
echo "Installing Build from ${KNATIVE_BUILD_RELEASE}"
kubectl apply -f ${KNATIVE_BUILD_RELEASE} || return 1
wait_until_pods_running knative-build || return 1
}
@ -346,7 +352,9 @@ function run_lint_tool() {
# Parameters: $1...$n - files to inspect
function check_links_in_markdown() {
# https://github.com/tcort/markdown-link-check
run_lint_tool markdown-link-check "checking links in markdown files" -q $@
local config="${REPO_ROOT_DIR}/test/markdown-link-check-config.json"
[[ ! -e ${config} ]] && config="${_TEST_INFRA_SCRIPTS_DIR}/markdown-link-check-config.json"
run_lint_tool markdown-link-check "checking links in markdown files" "-c ${config} -q" $@
}
# Check format of the given markdown files.
@ -356,16 +364,30 @@ function lint_markdown() {
run_lint_tool mdl "linting markdown files" "-r ~MD013" $@
}
# Return 0 if the given parameter is an integer, otherwise 1
# Parameters: $1 - an integer
# Return whether the given parameter is an integer.
# Parameters: $1 - integer to check
function is_int() {
[[ -n $1 && $1 =~ ^[0-9]+$ ]]
}
# Return 0 if the given parameter is the knative release/nightly gcr, 1
# otherwise
# Parameters: $1 - gcr name, e.g. gcr.io/knative-nightly
# Return whether the given parameter is the knative release/nightly GCF.
# Parameters: $1 - full GCR name, e.g. gcr.io/knative-foo-bar
function is_protected_gcr() {
[[ -n $1 && "$1" =~ "^gcr.io/knative-(releases|nightly)/?$" ]]
}
# Returns the canonical path of a filesystem object.
# Parameters: $1 - path to return in canonical form
# $2 - base dir for relative links; optional, defaults to current
function get_canonical_path() {
# We don't use readlink because it's not available on every platform.
local path=$1
local pwd=${2:-.}
[[ ${path} == /* ]] || path="${pwd}/${path}"
echo "$(cd ${path%/*} && echo $PWD/${path##*/})"
}
# Initializations that depend on previous functions.
# These MUST come last.
readonly _TEST_INFRA_SCRIPTS_DIR="$(dirname $(get_canonical_path ${BASH_SOURCE[0]}))"

View File

@ -0,0 +1,7 @@
{
"ignorePatterns": [
{
"pattern": "^https?://localhost($|[:/].*)"
}
]
}

View File

@ -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
@ -134,10 +150,8 @@ function default_build_test_runner() {
./hack/verify-codegen.sh || failed=1
fi
# Check that we don't have any forbidden licenses in our images.
if [[ -d ./cmd ]]; then
subheader "Checking for forbidden licenses"
check_licenses ./cmd/* || failed=1
fi
subheader "Checking for forbidden licenses"
check_licenses $(go list ./...) || failed=1
return ${failed}
}

View File

@ -194,7 +194,8 @@ function parse_flags() {
case ${parameter} in
--github-token)
[[ ! -f "$1" ]] && abort "file $1 doesn't exist"
GITHUB_TOKEN="$(cat $1)"
# Remove any trailing newline/space from token
GITHUB_TOKEN="$(echo -n $(cat $1))"
[[ -n "${GITHUB_TOKEN}" ]] || abort "file $1 is empty"
;;
--release-gcr)