diff --git a/.gitignore b/.gitignore index 30885d5a4..429ae5e77 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,12 @@ tags # VSCode specific .vscode +# Ignore everything in vendor except github.com/knative/test-infra +# (we need that to make our automated tests go) + +vendor/* +!vendor/github.com/ +vendor/github.com/* +!vendor/github.com/knative/ +vendor/github.com/knative/* +!vendor/github.com/knative/test-infra/ diff --git a/go.mod b/go.mod index 0ba754a14..4e674da37 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,7 @@ require ( github.com/onsi/gomega v1.4.3 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.8.1 // indirect + github.com/sergi/go-diff v1.0.0 // indirect github.com/spf13/afero v1.2.0 // indirect github.com/spf13/cobra v0.0.3 github.com/spf13/viper v1.3.1 diff --git a/go.sum b/go.sum index 8feefd6ac..4044b6a61 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4= github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= @@ -33,7 +32,6 @@ github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -53,11 +51,9 @@ github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCO github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -67,10 +63,8 @@ github.com/knative/pkg v0.0.0-20190110005142-b6044a7d1795 h1:mTaIClRJEjRuTFOc4Gs github.com/knative/pkg v0.0.0-20190110005142-b6044a7d1795/go.mod h1:7Ijfhw7rfB+H9VtosIsDYvZQ+qYTz7auK3fHW/5z4ww= github.com/knative/serving v0.3.0 h1:kALSwD+P5GLdRj2mtZ2W4ZRRD//Q7nKjLqCPSpihkTY= github.com/knative/serving v0.3.0/go.mod h1:ljvMfwQy2qanaM/8xnBSK4Mz3Vv2NawC2fo5kFRJS1A= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -87,9 +81,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -97,8 +89,8 @@ github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+v github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.0 h1:O9FblXGxoTc51M+cqr74Bm2Tmt4PvkA5iu/j8HrkNuY= github.com/spf13/afero v1.2.0/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= @@ -114,7 +106,6 @@ github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38= github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= @@ -129,7 +120,6 @@ golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 h1:uESlIz09WIHT2I+pasSXcpLYqYK8wHcdCetU3VuMBJE= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -139,16 +129,12 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= diff --git a/pkg/dummy_test.go b/pkg/dummy_test.go new file mode 100644 index 000000000..754b25b17 --- /dev/null +++ b/pkg/dummy_test.go @@ -0,0 +1,24 @@ +// Copyright © 2018 The Knative Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pkg + +import ( + "testing" + + _ "github.com/knative/test-infra/scripts" +) + +func TestDummy(t *testing.T) { +} diff --git a/test/presubmit-tests.sh b/test/presubmit-tests.sh new file mode 100755 index 000000000..806224ec2 --- /dev/null +++ b/test/presubmit-tests.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# Copyright 2018 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script runs the presubmit tests; it is started by prow for each PR. +# For convenience, it can also be executed manually. +# Running the script without parameters, or with the --all-tests +# flag, causes all tests to be executed, in the right order. +# Use the flags --build-tests, --unit-tests and --integration-tests +# to run a specific set of tests. + +# Markdown linting failures don't show up properly in Gubernator resulting +# in a net-negative contributor experience. +export DISABLE_MD_LINTING=1 + +source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh + +# Checking licenses doesn't work yet with go mods. +# This is mostly the default runner but doesn't check them. + +function build_tests() { + 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} + # Skip build test if there is no go code + local go_pkg_dirs="$(go list ./...)" + [[ -z "${go_pkg_dirs}" ]] && return ${failed} + # Ensure all the code builds + subheader "Checking that go code builds" + go build -v ./... || failed=1 + # Get all build tags in go code (ignore /vendor) + local tags="$(grep -r '// +build' . \ + | grep -v '^./vendor/' | cut -f3 -d' ' | sort | uniq | tr '\n' ' ')" + if [[ -n "${tags}" ]]; then + go test -run=^$ -tags="${tags}" ./... || failed=1 + fi + if [[ -f ./hack/verify-codegen.sh ]]; then + subheader "Checking autogenerated code is up-to-date" + ./hack/verify-codegen.sh || failed=1 + fi + subheader "Skipping license test" + return ${failed} +} + +main $@ diff --git a/vendor/github.com/knative/test-infra/LICENSE b/vendor/github.com/knative/test-infra/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/vendor/github.com/knative/test-infra/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/knative/test-infra/scripts/README.md b/vendor/github.com/knative/test-infra/scripts/README.md new file mode 100644 index 000000000..498fe0ad0 --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/README.md @@ -0,0 +1,260 @@ +# Helper scripts + +This directory contains helper scripts used by Prow test jobs, as well and +local development scripts. + +## Using the `presubmit-tests.sh` helper script + +This is a helper script to run the presubmit tests. To use it: + +1. Source this script. + +1. [optional] Define the function `build_tests()`. If you don't define this + function, the default action for running the build tests is to: + + - check markdown files + - run `go build` on the entire repo + - run `/hack/verify-codegen.sh` (if it exists) + - check licenses in all go packages + + The markdown link checker tool 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. + + The markdown lint tool ignores long lines by default. Its configuration file, + `markdown-lint-config.rc`, 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 + the test to fail if they don't return success. + +1. [optional] Define the function `unit_tests()`. If you don't define this + function, the default action for running the unit tests is to run all go tests + in the repo. + +1. [optional] Define the functions `pre_unit_tests()` and/or + `post_unit_tests()`. These functions will be called before or after the + unit tests (either your custom one or the default action) and will cause + the test to fail if they don't return success. + +1. [optional] Define the function `integration_tests()`. If you don't define + this function, the default action for running the integration tests is to run + all run all `./test/e2e-*tests.sh` scripts, in sequence. + +1. [optional] Define the functions `pre_integration_tests()` and/or + `post_integration_tests()`. These functions will be called before or after the + integration tests (either your custom one or the default action) and will cause + the test to fail if they don't return success. + +1. Call the `main()` function passing `$@` (without quotes). + +Running the script without parameters, or with the `--all-tests` flag causes +all tests to be executed, in the right order (i.e., build, then unit, then +integration tests). + +Use the flags `--build-tests`, `--unit-tests` and `--integration-tests` to run +a specific set of tests. The flag `--emit-metrics` is used to emit metrics when +running the tests, and is automatically handled by the default action for +integration tests (see above). + +The script will automatically skip all presubmit tests for PRs where all changed +files are exempt of tests (e.g., a PR changing only the `OWNERS` file). + +Also, for PRs touching only markdown files, the unit and integration tests are +skipped. + +### Sample presubmit test script + +```bash +source vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh + +function post_build_tests() { + echo "Cleaning up after build tests" + rm -fr ./build-cache +} + +function unit_tests() { + make -C tests test +} + +function pre_integration_tests() { + echo "Cleaning up before integration tests" + rm -fr ./staging-area +} + +# We use the default integration test runner. + +main $@ +``` + +## Using the `e2e-tests.sh` helper script + +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 `knative_setup()` function, which will set up your + system under test (e.g., Knative Serving). This function won't be called if you + use the `--skip-knative-setup` flag. + +1. [optional] Write the `knative_teardown()` function, which will tear down your + system under test (e.g., Knative Serving). This function won't be called if you + use the `--skip-knative-setup` flag. + +1. [optional] Write the `test_setup()` function, which will set up the test + resources. + +1. [optional] Write the `test_teardown()` function, which will tear down the test + resources. + +1. [optional] Write the `dump_extra_cluster_state()` function. It will be + called when a test fails, and can dump extra information about the current state + of the cluster (tipically using `kubectl`). + +1. [optional] Write the `parse_flags()` function. It will be called whenever an + unrecognized flag is passed to the script, allowing you to define your own flags. + The function must return 0 if the flag is unrecognized, or the number of items + to skip in the command line if the flag was parsed successfully. For example, + return 1 for a simple flag, and 2 for a flag with a parameter. + +1. Call the `initialize()` function passing `$@` (without quotes). + +1. Write logic for the end-to-end tests. Run all go tests using `go_test_e2e()` + (or `report_go_test()` if you need a more fine-grained control) and call + `fail_test()` or `success()` if any of them failed. The environment variable + `KO_DOCKER_REPO` will be set according to the test cluster. You can also use + the following boolean (0 is false, 1 is true) environment variables for the logic: + + - `EMIT_METRICS`: true if `--emit-metrics` was passed. + + All environment variables above are marked read-only. + +**Notes:** + +1. Calling your script without arguments will create a new cluster in the GCP + project `$PROJECT_ID` and run the tests against it. + +1. Calling your script with `--run-tests` and the variable `KO_DOCKER_REPO` set + will immediately start the tests against the cluster currently configured for + `kubectl`. + +1. You can force running the tests against a specific GKE cluster version by using + the `--cluster-version` flag and passing a full version as the flag value. + +### Sample end-to-end test script + +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. 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 knative_setup() { + start_latest_knative_serving + if (( WAIT_FOR_KNATIVE )); then + wait_until_pods_running knative-serving || fail_test "Knative Serving not up" + fi +} + +function parse_flags() { + if [[ "$1" == "--no-knative-wait" ]]; then + WAIT_FOR_KNATIVE=0 + return 1 + fi + return 0 +} + +WAIT_FOR_KNATIVE=1 + +initialize $@ + +# TODO: use go_test_e2e to run the tests. +kubectl get pods || fail_test + +success +``` + +## Using the `release.sh` helper script + +This is a helper script for Knative release scripts. To use it: + +1. Source the script. + +1. [optional] By default, the release script will run `./test/presubmit-tests.sh` + as the release validation tests. If you need to run something else, set the + environment variable `VALIDATION_TESTS` to the executable to run. + +1. Write logic for building the release in a function named `build_release()`. + Set the environment variable `YAMLS_TO_PUBLISH` to the list of yaml files created, + space separated. Use the following boolean (0 is false, 1 is true) and string + environment variables for the logic: + + - `RELEASE_VERSION`: contains the release version if `--version` was passed. This + also overrides the value of the `TAG` variable as `v`. + - `RELEASE_BRANCH`: contains the release branch if `--branch` was passed. Otherwise + it's empty and `master` HEAD will be considered the release branch. + - `RELEASE_NOTES`: contains the filename with the release notes if `--release-notes` + was passed. The release notes is a simple markdown file. + - `RELEASE_GCS_BUCKET`: contains the GCS bucket name to store the manifests if + `--release-gcs` was passed, otherwise the default value `knative-nightly/` + will be used. It is empty if `--publish` was not passed. + - `KO_DOCKER_REPO`: contains the GCR to store the images if `--release-gcr` was + passed, otherwise the default value `gcr.io/knative-nightly` will be used. It + is set to `ko.local` if `--publish` was not passed. + - `SKIP_TESTS`: true if `--skip-tests` was passed. This is handled automatically. + - `TAG_RELEASE`: true if `--tag-release` was passed. In this case, the environment + variable `TAG` will contain the release tag in the form `vYYYYMMDD-`. + - `PUBLISH_RELEASE`: true if `--publish` was passed. In this case, the environment + variable `KO_FLAGS` will be updated with the `-L` option. + - `PUBLISH_TO_GITHUB`: true if `--version`, `--branch` and `--publish-release` + were passed. + + All boolean environment variables default to false for safety. + + All environment variables above, except `KO_FLAGS`, are marked read-only once + `main()` is called (see below). + +1. Call the `main()` function passing `$@` (without quotes). + +### Sample release script + +```bash +source vendor/github.com/knative/test-infra/scripts/release.sh + +function build_release() { + # config/ contains the manifests + ko resolve ${KO_FLAGS} -f config/ > release.yaml + YAMLS_TO_PUBLISH="release.yaml" +} + +main $@ +``` diff --git a/vendor/github.com/knative/test-infra/scripts/dummy.go b/vendor/github.com/knative/test-infra/scripts/dummy.go new file mode 100644 index 000000000..e6cc380fd --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/dummy.go @@ -0,0 +1,26 @@ +/* +Copyright 2018 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package scripts + +import ( + "fmt" +) + +func main() { + fmt.Println("This is a dummy go file so `go dep` can be used with knative/test-infra/scripts") + fmt.Println("This file can be safely removed if one day this directory contains real, useful go code") +} diff --git a/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh b/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh new file mode 100644 index 000000000..c6879a0da --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/e2e-tests.sh @@ -0,0 +1,362 @@ +#!/bin/bash + +# Copyright 2018 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is a helper script for Knative E2E test scripts. +# See README.md for instructions on how to use it. + +source $(dirname ${BASH_SOURCE})/library.sh + +# Build a resource name based on $E2E_BASE_NAME, a suffix and $BUILD_NUMBER. +# Restricts the name length to 40 chars (the limit for resource names in GCP). +# Name will have the form $E2E_BASE_NAME-$BUILD_NUMBER. +# Parameters: $1 - name suffix +function build_resource_name() { + local prefix=${E2E_BASE_NAME}-$1 + local suffix=${BUILD_NUMBER} + # Restrict suffix length to 20 chars + if [[ -n "${suffix}" ]]; then + suffix=${suffix:${#suffix}<20?0:-20} + fi + local name="${prefix:0:20}${suffix}" + # Ensure name doesn't end with "-" + echo "${name%-}" +} + +# Test cluster parameters + +# 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} +readonly E2E_GKE_ENVIRONMENT=${E2E_GKE_ENVIRONMENT:-prod} +readonly E2E_GKE_COMMAND_GROUP=${E2E_GKE_COMMAND_GROUP:-beta} + +# 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 + +# Tear down the test resources. +function teardown_test_resources() { + header "Tearing down test environment" + function_exists test_teardown && test_teardown + (( ! SKIP_KNATIVE_SETUP )) && function_exists knative_teardown && knative_teardown + # Delete the kubernetes source downloaded by kubetest + rm -fr kubernetes kubernetes.tar.gz +} + +# Run the given E2E tests. Assume tests are tagged e2e, unless `-tags=XXX` is passed. +# Parameters: $1..$n - any go test flags, then directories containing the tests to run. +function go_test_e2e() { + local test_options="" + local go_options="" + (( EMIT_METRICS )) && test_options="-emitmetrics" + [[ ! " $@" == *" -tags="* ]] && go_options="-tags=e2e" + report_go_test -v -count=1 ${go_options} $@ ${test_options} +} + +# Dump info about the test cluster. If dump_extra_cluster_info() is defined, calls it too. +# This is intended to be called when a test fails to provide debugging information. +function dump_cluster_state() { + echo "***************************************" + echo "*** E2E TEST FAILED ***" + echo "*** Start of information dump ***" + echo "***************************************" + echo ">>> All resources:" + kubectl get all --all-namespaces + echo ">>> Services:" + kubectl get services --all-namespaces + echo ">>> Events:" + kubectl get events --all-namespaces + function_exists dump_extra_cluster_state && dump_extra_cluster_state + echo "***************************************" + echo "*** E2E TEST FAILED ***" + echo "*** End of information dump ***" + echo "***************************************" +} + +# On a Prow job, save some metadata about the test for Testgrid. +function save_metadata() { + (( ! IS_PROW )) && return + local geo_key="Region" + local geo_value="${E2E_CLUSTER_REGION}" + if [[ -n "${E2E_CLUSTER_ZONE}" ]]; then + geo_key="Zone" + geo_value="${E2E_CLUSTER_REGION}-${E2E_CLUSTER_ZONE}" + fi + local gcloud_project="$(gcloud config get-value project)" + local cluster_version="$(gcloud container clusters list --project=${gcloud_project} --format='value(currentMasterVersion)')" + cat << EOF > ${ARTIFACTS}/metadata.json +{ + "E2E:${geo_key}": "${geo_value}", + "E2E:Machine": "${E2E_CLUSTER_MACHINE}", + "E2E:Version": "${cluster_version}", + "E2E:MinNodes": "${E2E_MIN_CLUSTER_NODES}", + "E2E:MaxNodes": "${E2E_MAX_CLUSTER_NODES}" +} +EOF +} + +# Create a test cluster with kubetest and call the current script again. +function create_test_cluster() { + # Fail fast during setup. + set -o errexit + set -o pipefail + + header "Creating 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-command="container clusters create --quiet --enable-autoscaling --min-nodes=${E2E_MIN_CLUSTER_NODES} --max-nodes=${E2E_MAX_CLUSTER_NODES} --scopes=cloud-platform --enable-basic-auth --no-issue-client-certificate ${EXTRA_CLUSTER_CREATION_FLAGS[@]}" + --gke-shape={\"default\":{\"Nodes\":${E2E_MIN_CLUSTER_NODES}\,\"MachineType\":\"${E2E_CLUSTER_MACHINE}\"}} + --provider=gke + --deployment=gke + --cluster="${E2E_CLUSTER_NAME}" + ${geoflag} + --gcp-network="${E2E_NETWORK_NAME}" + --gke-environment="${E2E_GKE_ENVIRONMENT}" + --gke-command-group="${E2E_GKE_COMMAND_GROUP}" + --test=false + ) + if (( ! IS_BOSKOS )); then + CLUSTER_CREATION_ARGS+=(--gcp-project=${GCP_PROJECT}) + fi + # SSH keys are not used, but kubetest checks for their existence. + # Touch them so if they don't exist, empty files are create to satisfy the check. + mkdir -p $HOME/.ssh + touch $HOME/.ssh/google_compute_engine.pub + touch $HOME/.ssh/google_compute_engine + # Assume test failed (see details in set_test_return_code()). + set_test_return_code 1 + local gcloud_project="${GCP_PROJECT}" + [[ -z "${gcloud_project}" ]] && gcloud_project="$(gcloud config get-value project)" + echo "gcloud project is ${gcloud_project}" + (( IS_BOSKOS )) && echo "Using boskos for the test cluster" + [[ -n "${GCP_PROJECT}" ]] && echo "GCP project for test cluster is ${GCP_PROJECT}" + echo "Test script is ${E2E_SCRIPT}" + # Set arguments for this script again + local test_cmd_args="--run-tests" + (( EMIT_METRICS )) && test_cmd_args+=" --emit-metrics" + (( SKIP_KNATIVE_SETUP )) && test_cmd_args+=" --skip-knative-setup" + [[ -n "${GCP_PROJECT}" ]] && test_cmd_args+=" --gcp-project ${GCP_PROJECT}" + [[ -n "${E2E_SCRIPT_CUSTOM_FLAGS[@]}" ]] && test_cmd_args+=" ${E2E_SCRIPT_CUSTOM_FLAGS[@]}" + # Don't fail test for kubetest, as it might incorrectly report test failure + # if teardown fails (for details, see success() below) + set +o errexit + run_go_tool k8s.io/test-infra/kubetest \ + kubetest "${CLUSTER_CREATION_ARGS[@]}" \ + --up \ + --down \ + --extract "${E2E_CLUSTER_VERSION}" \ + --gcp-node-image "${SERVING_GKE_IMAGE}" \ + --test-cmd "${E2E_SCRIPT}" \ + --test-cmd-args "${test_cmd_args}" \ + ${EXTRA_KUBETEST_FLAGS[@]} + echo "Test subprocess exited with code $?" + # Ignore any errors below, this is a best-effort cleanup and shouldn't affect the test result. + set +o errexit + # Ensure we're using the GCP project used by kubetest + gcloud_project="$(gcloud config get-value project)" + # Delete target pools and health checks that might have leaked. + # See https://github.com/knative/serving/issues/959 for details. + # TODO(adrcunha): Remove once the leak issue is resolved. + local http_health_checks="$(gcloud compute target-pools list \ + --project=${gcloud_project} --format='value(healthChecks)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ + grep httpHealthChecks | tr '\n' ' ')" + local target_pools="$(gcloud compute target-pools list \ + --project=${gcloud_project} --format='value(name)' --filter="instances~-${E2E_CLUSTER_NAME}-" | \ + tr '\n' ' ')" + if [[ -n "${target_pools}" ]]; then + echo "Found leaked target pools, deleting" + gcloud compute forwarding-rules delete -q --project=${gcloud_project} --region=${E2E_CLUSTER_REGION} ${target_pools} + gcloud compute target-pools delete -q --project=${gcloud_project} --region=${E2E_CLUSTER_REGION} ${target_pools} + fi + if [[ -n "${http_health_checks}" ]]; then + echo "Found leaked health checks, deleting" + gcloud compute http-health-checks delete -q --project=${gcloud_project} ${http_health_checks} + fi + local result="$(cat ${TEST_RESULT_FILE})" + echo "Artifacts were written to ${ARTIFACTS}" + echo "Test result code is ${result}" + + exit ${result} +} + +# Setup the test cluster for running the tests. +function setup_test_cluster() { + # Fail fast during setup. + set -o errexit + set -o pipefail + + header "Setting up test cluster" + + # Save some metadata about cluster creation for using in prow and testgrid + save_metadata + + local k8s_user=$(gcloud config get-value core/account) + local k8s_cluster=$(kubectl config current-context) + + # If cluster admin role isn't set, this is a brand new cluster + # Setup the admin role and also KO_DOCKER_REPO + if [[ -z "$(kubectl get clusterrolebinding cluster-admin-binding 2> /dev/null)" ]]; then + acquire_cluster_admin_role ${k8s_user} ${E2E_CLUSTER_NAME} ${E2E_CLUSTER_REGION} ${E2E_CLUSTER_ZONE} + kubectl config set-context ${k8s_cluster} --namespace=default + export KO_DOCKER_REPO=gcr.io/$(gcloud config get-value project)/${E2E_BASE_NAME}-e2e-img + fi + + echo "- Cluster is ${k8s_cluster}" + echo "- User is ${k8s_user}" + echo "- Docker is ${KO_DOCKER_REPO}" + + export KO_DATA_PATH="${REPO_ROOT_DIR}/.git" + + trap teardown_test_resources EXIT + + # Handle failures ourselves, so we can dump useful info. + set +o errexit + set +o pipefail + + if (( ! SKIP_KNATIVE_SETUP )) && function_exists knative_setup; then + knative_setup || fail_test "Knative setup failed" + fi + if function_exists test_setup; then + test_setup || fail_test "test setup failed" + fi +} + +# Set the return code that the test script will return. +# Parameters: $1 - return code (0-255) +function set_test_return_code() { + # kubetest teardown might fail and thus incorrectly report failure of the + # script, even if the tests pass. + # We store the real test result to return it later, ignoring any teardown + # failure in kubetest. + # TODO(adrcunha): Get rid of this workaround. + echo -n "$1"> ${TEST_RESULT_FILE} +} + +# Signal (as return code and in the logs) that all E2E tests passed. +function success() { + set_test_return_code 0 + echo "**************************************" + echo "*** E2E TESTS PASSED ***" + echo "**************************************" + exit 0 +} + +# Exit test, dumping current state info. +# Parameters: $1 - error message (optional). +function fail_test() { + set_test_return_code 1 + [[ -n $1 ]] && echo "ERROR: $1" + dump_cluster_state + exit 1 +} + +RUN_TESTS=0 +EMIT_METRICS=0 +SKIP_KNATIVE_SETUP=0 +GCP_PROJECT="" +E2E_SCRIPT="" +E2E_CLUSTER_VERSION="" +EXTRA_CLUSTER_CREATION_FLAGS=() +EXTRA_KUBETEST_FLAGS=() +E2E_SCRIPT_CUSTOM_FLAGS=() + +# Parse flags and initialize the test cluster. +function initialize() { + E2E_SCRIPT="$(get_canonical_path $0)" + E2E_CLUSTER_VERSION="${SERVING_GKE_VERSION}" + + cd ${REPO_ROOT_DIR} + while [[ $# -ne 0 ]]; do + local parameter=$1 + # Try parsing flag as a custom one. + if function_exists parse_flags; then + parse_flags $@ + local skip=$? + if [[ ${skip} -ne 0 ]]; then + # Skip parsed flag (and possibly argument) and continue + # Also save it to it's passed through to the test script + for ((i=1;i<=skip;i++)); do + E2E_SCRIPT_CUSTOM_FLAGS+=("$1") + shift + done + continue + fi + fi + # Try parsing flag as a standard one. + case ${parameter} in + --run-tests) RUN_TESTS=1 ;; + --emit-metrics) EMIT_METRICS=1 ;; + --skip-knative-setup) SKIP_KNATIVE_SETUP=1 ;; + *) + [[ $# -ge 2 ]] || abort "missing parameter after $1" + shift + case ${parameter} in + --gcp-project) GCP_PROJECT=$1 ;; + --cluster-version) E2E_CLUSTER_VERSION=$1 ;; + --cluster-creation-flag) EXTRA_CLUSTER_CREATION_FLAGS+=($1) ;; + --kubetest-flag) EXTRA_KUBETEST_FLAGS+=($1) ;; + *) abort "unknown option ${parameter}" ;; + esac + esac + shift + done + + # Use PROJECT_ID if set, unless --gcp-project was used. + if [[ -n "${PROJECT_ID:-}" && -z "${GCP_PROJECT}" ]]; then + echo "\$PROJECT_ID is set to '${PROJECT_ID}', using it to run the tests" + GCP_PROJECT="${PROJECT_ID}" + fi + if (( ! IS_PROW )) && [[ -z "${GCP_PROJECT}" ]]; then + abort "set \$PROJECT_ID or use --gcp-project to select the GCP project where the tests are run" + fi + + (( IS_PROW )) && [[ -z "${GCP_PROJECT}" ]] && IS_BOSKOS=1 + + # Safety checks + is_protected_gcr ${KO_DOCKER_REPO} && \ + abort "\$KO_DOCKER_REPO set to ${KO_DOCKER_REPO}, which is forbidden" + + readonly RUN_TESTS + readonly EMIT_METRICS + readonly GCP_PROJECT + readonly IS_BOSKOS + readonly EXTRA_CLUSTER_CREATION_FLAGS + readonly EXTRA_KUBETEST_FLAGS + readonly SKIP_KNATIVE_SETUP + + if (( ! RUN_TESTS )); then + create_test_cluster + else + setup_test_cluster + fi +} diff --git a/vendor/github.com/knative/test-infra/scripts/library.sh b/vendor/github.com/knative/test-infra/scripts/library.sh new file mode 100644 index 000000000..1b9ee0705 --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/library.sh @@ -0,0 +1,426 @@ +#!/bin/bash + +# Copyright 2018 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is a collection of useful bash functions and constants, intended +# to be used in test scripts and the like. It doesn't do anything when +# called from command line. + +# Default GKE version to be used with Knative Serving +readonly SERVING_GKE_VERSION=gke-latest +readonly SERVING_GKE_IMAGE=cos + +# Public latest stable nightly images and yaml files. +readonly KNATIVE_BASE_YAML_SOURCE=https://storage.googleapis.com/knative-nightly/@/latest +readonly KNATIVE_ISTIO_CRD_YAML=${KNATIVE_BASE_YAML_SOURCE/@/serving}/istio-crds.yaml +readonly KNATIVE_ISTIO_YAML=${KNATIVE_BASE_YAML_SOURCE/@/serving}/istio.yaml +readonly KNATIVE_SERVING_RELEASE=${KNATIVE_BASE_YAML_SOURCE/@/serving}/serving.yaml +readonly KNATIVE_BUILD_RELEASE=${KNATIVE_BASE_YAML_SOURCE/@/build}/build.yaml +readonly KNATIVE_EVENTING_RELEASE=${KNATIVE_BASE_YAML_SOURCE/@/eventing}/release.yaml + +# Conveniently set GOPATH if unset +if [[ -z "${GOPATH:-}" ]]; then + export GOPATH="$(go env GOPATH)" + if [[ -z "${GOPATH}" ]]; then + echo "WARNING: GOPATH not set and go binary unable to provide it" + fi +fi + +# Useful environment variables +[[ -n "${PROW_JOB_ID:-}" ]] && IS_PROW=1 || IS_PROW=0 +readonly IS_PROW +readonly REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" +readonly REPO_NAME="$(basename ${REPO_ROOT_DIR})" + +# Set ARTIFACTS to an empty temp dir if unset +if [[ -z "${ARTIFACTS:-}" ]]; then + export ARTIFACTS="$(mktemp -d)" +fi + +# On a Prow job, redirect stderr to stdout so it's synchronously added to log +(( IS_PROW )) && exec 2>&1 + +# Print error message and exit 1 +# Parameters: $1..$n - error message to be displayed +function abort() { + echo "error: $@" + exit 1 +} + +# Display a box banner. +# Parameters: $1 - character to use for the box. +# $2 - banner message. +function make_banner() { + local msg="$1$1$1$1 $2 $1$1$1$1" + local border="${msg//[-0-9A-Za-z _.,\/()]/$1}" + echo -e "${border}\n${msg}\n${border}" +} + +# Simple header for logging purposes. +function header() { + local upper="$(echo $1 | tr a-z A-Z)" + make_banner "=" "${upper}" +} + +# Simple subheader for logging purposes. +function subheader() { + make_banner "-" "$1" +} + +# Simple warning banner for logging purposes. +function warning() { + make_banner "!" "$1" +} + +# Checks whether the given function exists. +function function_exists() { + [[ "$(type -t $1)" == "function" ]] +} + +# Waits until the given object doesn't exist. +# Parameters: $1 - the kind of the object. +# $2 - object's name. +# $3 - namespace (optional). +function wait_until_object_does_not_exist() { + local KUBECTL_ARGS="get $1 $2" + local DESCRIPTION="$1 $2" + + if [[ -n $3 ]]; then + KUBECTL_ARGS="get -n $3 $1 $2" + DESCRIPTION="$1 $3/$2" + fi + echo -n "Waiting until ${DESCRIPTION} does not exist" + for i in {1..150}; do # timeout after 5 minutes + if ! kubectl ${KUBECTL_ARGS} > /dev/null 2>&1; then + echo -e "\n${DESCRIPTION} does not exist" + return 0 + fi + echo -n "." + sleep 2 + done + echo -e "\n\nERROR: timeout waiting for ${DESCRIPTION} not to exist" + kubectl ${KUBECTL_ARGS} + return 1 +} + +# Waits until all pods are running in the given namespace. +# Parameters: $1 - namespace. +function wait_until_pods_running() { + echo -n "Waiting until all pods in namespace $1 are up" + for i in {1..150}; do # timeout after 5 minutes + local pods="$(kubectl get pods --no-headers -n $1 2>/dev/null)" + # All pods must be running + local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l) + if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then + local all_ready=1 + while read pod ; do + local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`) + # All containers must be ready + [[ -z ${status[0]} ]] && all_ready=0 && break + [[ -z ${status[1]} ]] && all_ready=0 && break + [[ ${status[0]} -lt 1 ]] && all_ready=0 && break + [[ ${status[1]} -lt 1 ]] && all_ready=0 && break + [[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break + done <<< $(echo "${pods}" | grep -v Completed) + if (( all_ready )); then + echo -e "\nAll pods are up:\n${pods}" + return 0 + fi + fi + echo -n "." + sleep 2 + done + echo -e "\n\nERROR: timeout waiting for pods to come up\n${pods}" + return 1 +} + +# Waits until the given service has an external address (IP/hostname). +# Parameters: $1 - namespace. +# $2 - service name. +function wait_until_service_has_external_ip() { + echo -n "Waiting until service $2 in namespace $1 has an external address (IP/hostname)" + for i in {1..150}; do # timeout after 15 minutes + local ip=$(kubectl get svc -n $1 $2 -o jsonpath="{.status.loadBalancer.ingress[0].ip}") + if [[ -n "${ip}" ]]; then + echo -e "\nService $2.$1 has IP $ip" + return 0 + fi + local hostname=$(kubectl get svc -n $1 $2 -o jsonpath="{.status.loadBalancer.ingress[0].hostname}") + if [[ -n "${hostname}" ]]; then + echo -e "\nService $2.$1 has hostname $hostname" + return 0 + fi + echo -n "." + sleep 6 + done + echo -e "\n\nERROR: timeout waiting for service $2.$1 to have an external address" + kubectl get pods -n $1 + return 1 +} + +# Waits for the endpoint to be routable. +# Parameters: $1 - External ingress IP address. +# $2 - cluster hostname. +function wait_until_routable() { + echo -n "Waiting until cluster $2 at $1 has a routable endpoint" + for i in {1..150}; do # timeout after 5 minutes + local val=$(curl -H "Host: $2" "http://$1" 2>/dev/null) + if [[ -n "$val" ]]; then + echo "\nEndpoint is now routable" + return 0 + fi + echo -n "." + sleep 2 + done + echo -e "\n\nERROR: Timed out waiting for endpoint to be routable" + return 1 +} + +# Returns the name of the first pod of the given app. +# Parameters: $1 - app name. +# $2 - namespace (optional). +function get_app_pod() { + local pods=($(get_app_pods $1 $2)) + echo "${pods[0]}" +} + +# Returns the name of all pods of the given app. +# Parameters: $1 - app name. +# $2 - namespace (optional). +function get_app_pods() { + local namespace="" + [[ -n $2 ]] && namespace="-n $2" + kubectl get pods ${namespace} --selector=app=$1 --output=jsonpath="{.items[*].metadata.name}" +} + +# Capitalize the first letter of each word. +# Parameters: $1..$n - words to capitalize. +function capitalize() { + local capitalized=() + for word in $@; do + local initial="$(echo ${word:0:1}| tr 'a-z' 'A-Z')" + capitalized+=("${initial}${word:1}") + done + echo "${capitalized[@]}" +} + +# Dumps pod logs for the given app. +# Parameters: $1 - app name. +# $2 - namespace. +function dump_app_logs() { + echo ">>> ${REPO_NAME_FORMATTED} $1 logs:" + for pod in $(get_app_pods "$1" "$2") + do + echo ">>> Pod: $pod" + kubectl -n "$2" logs "$pod" -c "$1" + done +} + +# Sets the given user as cluster admin. +# Parameters: $1 - user +# $2 - cluster name +# $3 - cluster region +# $4 - cluster zone, optional +function acquire_cluster_admin_role() { + echo "Acquiring cluster-admin role for user '$1'" + 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 ${geoflag}) + if [[ -n "${password}" ]]; then + # Cluster created with basic authentication + kubectl config set-credentials cluster-admin \ + --username=admin --password=${password} + else + local cert=$(mktemp) + local key=$(mktemp) + echo "Certificate in ${cert}, key in ${key}" + gcloud --format="value(masterAuth.clientCertificate)" \ + container clusters describe $2 ${geoflag} | base64 -d > ${cert} + gcloud --format="value(masterAuth.clientKey)" \ + container clusters describe $2 ${geoflag} | base64 -d > ${key} + kubectl config set-credentials cluster-admin \ + --client-certificate=${cert} --client-key=${key} + fi + kubectl config set-context $(kubectl config current-context) \ + --user=cluster-admin + kubectl create clusterrolebinding cluster-admin-binding \ + --clusterrole=cluster-admin \ + --user=$1 + # Reset back to the default account + gcloud container clusters get-credentials \ + $2 ${geoflag} --project $(gcloud config get-value project) +} + +# Runs a go test and generate a junit summary. +# Parameters: $1... - parameters to go test +function report_go_test() { + # Run tests in verbose mode to capture details. + # go doesn't like repeating -v, so remove if passed. + local args=" $@ " + local go_test="go test -race -v ${args/ -v / }" + # Just run regular go tests if not on Prow. + echo "Running tests with '${go_test}'" + local report=$(mktemp) + ${go_test} | tee ${report} + local failed=( ${PIPESTATUS[@]} ) + [[ ${failed[0]} -eq 0 ]] && failed=${failed[1]} || failed=${failed[0]} + echo "Finished run, return code is ${failed}" + # Install go-junit-report if necessary. + run_go_tool github.com/jstemmer/go-junit-report go-junit-report --help > /dev/null 2>&1 + local xml=$(mktemp ${ARTIFACTS}/junit_XXXXXXXX.xml) + cat ${report} \ + | go-junit-report \ + | sed -e "s#\"github.com/knative/${REPO_NAME}/#\"#g" \ + > ${xml} + echo "XML report written to ${xml}" + if (( ! IS_PROW )); then + # Keep the suffix, so files are related. + local logfile=${xml/junit_/go_test_} + logfile=${logfile/.xml/.log} + cp ${report} ${logfile} + echo "Test log written to ${logfile}" + fi + return ${failed} +} + +# Install the latest stable Knative/serving in the current cluster. +function start_latest_knative_serving() { + header "Starting Knative Serving" + subheader "Installing Istio" + echo "Installing Istio CRD from ${KNATIVE_ISTIO_CRD_YAML}" + kubectl apply -f ${KNATIVE_ISTIO_CRD_YAML} || return 1 + echo "Installing Istio from ${KNATIVE_ISTIO_YAML}" + kubectl apply -f ${KNATIVE_ISTIO_YAML} || return 1 + wait_until_pods_running istio-system || return 1 + kubectl label namespace default istio-injection=enabled || return 1 + subheader "Installing Knative Serving" + echo "Installing Serving from ${KNATIVE_SERVING_RELEASE}" + kubectl apply -f ${KNATIVE_SERVING_RELEASE} || return 1 + wait_until_pods_running knative-serving || return 1 +} + +# Install the latest stable Knative/build in the current cluster. +function start_latest_knative_build() { + header "Starting Knative Build" + 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 +} + +# Run a go tool, installing it first if necessary. +# Parameters: $1 - tool package/dir for go get/install. +# $2 - tool to run. +# $3..$n - parameters passed to the tool. +function run_go_tool() { + local tool=$2 + if [[ -z "$(which ${tool})" ]]; then + local action=get + [[ $1 =~ ^[\./].* ]] && action=install + go ${action} $1 + fi + shift 2 + ${tool} "$@" +} + +# Run dep-collector to update licenses. +# Parameters: $1 - output file, relative to repo root dir. +# $2...$n - directories and files to inspect. +function update_licenses() { + cd ${REPO_ROOT_DIR} || return 1 + local dst=$1 + shift + run_go_tool ./vendor/github.com/knative/test-infra/tools/dep-collector dep-collector $@ > ./${dst} +} + +# Run dep-collector to check for forbidden liceses. +# Parameters: $1...$n - directories and files to inspect. +function check_licenses() { + # Fetch the google/licenseclassifier for its license db + go get -u github.com/google/licenseclassifier + # Check that we don't have any forbidden licenses in our images. + run_go_tool ./vendor/github.com/knative/test-infra/tools/dep-collector dep-collector -check $@ +} + +# Run the given linter on the given files, checking it exists first. +# Parameters: $1 - tool +# $2 - tool purpose (for error message if tool not installed) +# $3 - tool parameters (quote if multiple parameters used) +# $4..$n - files to run linter on +function run_lint_tool() { + local checker=$1 + local params=$3 + if ! hash ${checker} 2>/dev/null; then + warning "${checker} not installed, not $2" + return 127 + fi + shift 3 + local failed=0 + for file in $@; do + ${checker} ${params} ${file} || failed=1 + done + return ${failed} +} + +# Check links in the given markdown files. +# Parameters: $1...$n - files to inspect +function check_links_in_markdown() { + # https://github.com/raviqqe/liche + local config="${REPO_ROOT_DIR}/test/markdown-link-check-config.rc" + [[ ! -e ${config} ]] && config="${_TEST_INFRA_SCRIPTS_DIR}/markdown-link-check-config.rc" + local options="$(grep '^-' ${config} | tr \"\n\" ' ')" + run_lint_tool liche "checking links in markdown files" "-d ${REPO_ROOT_DIR} ${options}" $@ +} + +# Check format of the given markdown files. +# Parameters: $1..$n - files to inspect +function lint_markdown() { + # https://github.com/markdownlint/markdownlint + local config="${REPO_ROOT_DIR}/test/markdown-lint-config.rc" + [[ ! -e ${config} ]] && config="${_TEST_INFRA_SCRIPTS_DIR}/markdown-lint-config.rc" + run_lint_tool mdl "linting markdown files" "-c ${config}" $@ +} + +# Return whether the given parameter is an integer. +# Parameters: $1 - integer to check +function is_int() { + [[ -n $1 && $1 =~ ^[0-9]+$ ]] +} + +# 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]}))" +readonly REPO_NAME_FORMATTED="Knative $(capitalize ${REPO_NAME//-/})" diff --git a/vendor/github.com/knative/test-infra/scripts/markdown-link-check-config.rc b/vendor/github.com/knative/test-infra/scripts/markdown-link-check-config.rc new file mode 100644 index 000000000..9d802a0d4 --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/markdown-link-check-config.rc @@ -0,0 +1,5 @@ +# For help, see +# https://github.com/raviqqe/liche/blob/master/README.md + +# Don't check localhost links +-x "^https?://localhost($|[:/].*)" diff --git a/vendor/github.com/knative/test-infra/scripts/markdown-lint-config.rc b/vendor/github.com/knative/test-infra/scripts/markdown-lint-config.rc new file mode 100644 index 000000000..461f891a2 --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/markdown-lint-config.rc @@ -0,0 +1,5 @@ +# For help, see +# https://github.com/markdownlint/markdownlint/blob/master/docs/configuration.md + +# Ignore long lines +rules "~MD013" diff --git a/vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh b/vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh new file mode 100644 index 000000000..e3c024f82 --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/presubmit-tests.sh @@ -0,0 +1,324 @@ +#!/bin/bash + +# Copyright 2018 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is a helper script for Knative presubmit test scripts. +# See README.md for instructions on how to use it. + +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) + +# Flag if this is a presubmit run or not. +[[ IS_PROW && -n "${PULL_PULL_SHA}" ]] && IS_PRESUBMIT=1 || IS_PRESUBMIT=0 +readonly IS_PRESUBMIT + +# List of changed files on presubmit, LF separated. +CHANGED_FILES="" + +# Flags that this PR is exempt of presubmit tests. +IS_PRESUBMIT_EXEMPT_PR=0 + +# Flags that this PR contains only changes to documentation. +IS_DOCUMENTATION_PR=0 + +# Returns true if PR only contains the given file regexes. +# Parameters: $1 - file regexes, space separated. +function pr_only_contains() { + [[ -z "$(echo "${CHANGED_FILES}" | grep -v \(${1// /\\|}\)$))" ]] +} + +# List changed files in the current PR. +# This is implemented as a function so it can be mocked in unit tests. +function list_changed_files() { + /workspace/githubhelper -list-changed-files +} + +# Initialize flags and context for presubmit tests: +# CHANGED_FILES, IS_PRESUBMIT_EXEMPT_PR and IS_DOCUMENTATION_PR. +function initialize_environment() { + CHANGED_FILES="" + IS_PRESUBMIT_EXEMPT_PR=0 + IS_DOCUMENTATION_PR=0 + (( ! IS_PRESUBMIT )) && return + CHANGED_FILES="$(list_changed_files)" + if [[ -n "${CHANGED_FILES}" ]]; then + echo -e "Changed files in commit ${PULL_PULL_SHA}:\n${CHANGED_FILES}" + local no_presubmit_files="${NO_PRESUBMIT_FILES[*]}" + pr_only_contains "${no_presubmit_files}" && IS_PRESUBMIT_EXEMPT_PR=1 + pr_only_contains "\.md ${no_presubmit_files}" && IS_DOCUMENTATION_PR=1 + else + header "NO CHANGED FILES REPORTED, ASSUMING IT'S AN ERROR AND RUNNING TESTS ANYWAY" + fi + readonly CHANGED_FILES + readonly IS_DOCUMENTATION_PR + readonly IS_PRESUBMIT_EXEMPT_PR +} + +# Display a pass/fail banner for a test group. +# Parameters: $1 - test group name (e.g., build) +# $2 - result (0=passed, 1=failed) +function results_banner() { + local result + [[ $2 -eq 0 ]] && result="PASSED" || result="FAILED" + header "$1 tests ${result}" +} + +# Run build tests. If there's no `build_tests` function, run the default +# build test runner. +function run_build_tests() { + (( ! RUN_BUILD_TESTS )) && return 0 + header "Running build tests" + local failed=0 + # Run pre-build tests, if any + if function_exists pre_build_tests; then + pre_build_tests || failed=1 + fi + # Don't run build tests if pre-build tests failed + if (( ! failed )); then + if function_exists build_tests; then + build_tests || failed=1 + else + default_build_test_runner || failed=1 + fi + fi + # Don't run post-build tests if pre/build tests failed + if (( ! failed )) && function_exists post_build_tests; then + post_build_tests || failed=1 + fi + results_banner "Build" ${failed} + return ${failed} +} + +# 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 and deleted files) + local mdfiles="" + for file in $(echo "${CHANGED_FILES}" | grep \.md$ | grep -v ^vendor/); do + [[ -f "${file}" ]] && mdfiles="${mdfiles} ${file}" + done + [[ -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} + # Skip build test if there is no go code + local go_pkg_dirs="$(go list ./...)" + [[ -z "${go_pkg_dirs}" ]] && return ${failed} + # Ensure all the code builds + subheader "Checking that go code builds" + go build -v ./... || failed=1 + # Get all build tags in go code (ignore /vendor) + local tags="$(grep -r '// +build' . \ + | grep -v '^./vendor/' | cut -f3 -d' ' | sort | uniq | tr '\n' ' ')" + if [[ -n "${tags}" ]]; then + go test -run=^$ -tags="${tags}" ./... || failed=1 + fi + if [[ -f ./hack/verify-codegen.sh ]]; then + subheader "Checking autogenerated code is up-to-date" + ./hack/verify-codegen.sh || failed=1 + fi + # Check that we don't have any forbidden licenses in our images. + subheader "Checking for forbidden licenses" + check_licenses ${go_pkg_dirs} || failed=1 + return ${failed} +} + +# Run unit tests. If there's no `unit_tests` function, run the default +# unit test runner. +function run_unit_tests() { + (( ! RUN_UNIT_TESTS )) && return 0 + header "Running unit tests" + local failed=0 + # Run pre-unit tests, if any + if function_exists pre_unit_tests; then + pre_unit_tests || failed=1 + fi + # Don't run unit tests if pre-unit tests failed + if (( ! failed )); then + if function_exists unit_tests; then + unit_tests || failed=1 + else + default_unit_test_runner || failed=1 + fi + fi + # Don't run post-unit tests if pre/unit tests failed + if (( ! failed )) && function_exists post_unit_tests; then + post_unit_tests || failed=1 + fi + results_banner "Unit" ${failed} + return ${failed} +} + +# Default unit test runner that runs all go tests in the repo. +function default_unit_test_runner() { + report_go_test ./... +} + +# Run integration tests. If there's no `integration_tests` function, run the +# default integration test runner. +function run_integration_tests() { + # Don't run integration tests if not requested OR on documentation PRs + (( ! RUN_INTEGRATION_TESTS )) && return 0 + (( IS_DOCUMENTATION_PR )) && return 0 + header "Running integration tests" + local failed=0 + # Run pre-integration tests, if any + if function_exists pre_integration_tests; then + pre_integration_tests || failed=1 + fi + # Don't run integration tests if pre-integration tests failed + if (( ! failed )); then + if function_exists integration_tests; then + integration_tests || failed=1 + else + default_integration_test_runner || failed=1 + fi + fi + # Don't run integration tests if pre/integration tests failed + if (( ! failed )) && function_exists post_integration_tests; then + post_integration_tests || failed=1 + fi + results_banner "Integration" ${failed} + return ${failed} +} + +# Default integration test runner that runs all `test/e2e-*tests.sh`. +function default_integration_test_runner() { + local options="" + local failed=0 + (( EMIT_METRICS )) && options="--emit-metrics" + for e2e_test in $(find test/ -name e2e-*tests.sh); do + echo "Running integration test ${e2e_test}" + if ! ${e2e_test} ${options}; then + failed=1 + fi + done + return ${failed} +} + +# Options set by command-line flags. +RUN_BUILD_TESTS=0 +RUN_UNIT_TESTS=0 +RUN_INTEGRATION_TESTS=0 +EMIT_METRICS=0 + +# Process flags and run tests accordingly. +function main() { + initialize_environment + if (( IS_PRESUBMIT_EXEMPT_PR )) && (( ! IS_DOCUMENTATION_PR )); then + header "Commit only contains changes that don't require tests, skipping" + exit 0 + fi + + # Show the version of the tools we're using + if (( IS_PROW )); then + # Disable gcloud update notifications + gcloud config set component_manager/disable_update_check true + header "Current test setup" + echo ">> gcloud SDK version" + gcloud version + echo ">> kubectl version" + kubectl version --client + echo ">> go version" + go version + echo ">> git version" + git version + echo ">> bazel version" + bazel version 2> /dev/null + if [[ "${DOCKER_IN_DOCKER_ENABLED}" == "true" ]]; then + echo ">> docker version" + docker version + fi + fi + + [[ -z $1 ]] && set -- "--all-tests" + + local TEST_TO_RUN="" + + while [[ $# -ne 0 ]]; do + local parameter=$1 + case ${parameter} in + --build-tests) RUN_BUILD_TESTS=1 ;; + --unit-tests) RUN_UNIT_TESTS=1 ;; + --integration-tests) RUN_INTEGRATION_TESTS=1 ;; + --emit-metrics) EMIT_METRICS=1 ;; + --all-tests) + RUN_BUILD_TESTS=1 + RUN_UNIT_TESTS=1 + RUN_INTEGRATION_TESTS=1 + ;; + --run-test) + shift + [[ $# -ge 1 ]] || abort "missing executable after --run-test" + TEST_TO_RUN=$1 + ;; + *) abort "error: unknown option ${parameter}" ;; + esac + shift + done + + readonly RUN_BUILD_TESTS + readonly RUN_UNIT_TESTS + readonly RUN_INTEGRATION_TESTS + readonly EMIT_METRICS + readonly TEST_TO_RUN + + cd ${REPO_ROOT_DIR} + + # Tests to be performed, in the right order if --all-tests is passed. + + local failed=0 + + if [[ -n "${TEST_TO_RUN}" ]]; then + if (( RUN_BUILD_TESTS || RUN_UNIT_TESTS || RUN_INTEGRATION_TESTS )); then + abort "--run-test must be used alone" + fi + # If this is a presubmit run, but a documentation-only PR, don't run the test + (( IS_PRESUBMIT && IS_DOCUMENTATION_PR )) && exit 0 + ${TEST_TO_RUN} || failed=1 + fi + + run_build_tests || failed=1 + run_unit_tests || failed=1 + run_integration_tests || failed=1 + + exit ${failed} +} diff --git a/vendor/github.com/knative/test-infra/scripts/release.sh b/vendor/github.com/knative/test-infra/scripts/release.sh new file mode 100644 index 000000000..139bfd528 --- /dev/null +++ b/vendor/github.com/knative/test-infra/scripts/release.sh @@ -0,0 +1,424 @@ +#!/bin/bash + +# Copyright 2018 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is a helper script for Knative release scripts. +# See README.md for instructions on how to use it. + +source $(dirname ${BASH_SOURCE})/library.sh + +# GitHub upstream. +readonly KNATIVE_UPSTREAM="https://github.com/knative/${REPO_NAME}" + +# Georeplicate images to {us,eu,asia}.gcr.io +readonly GEO_REPLICATION=(us eu asia) + +# Simple banner for logging purposes. +# Parameters: $1 - message to display. +function banner() { + make_banner "@" "$1" +} + +# Tag images in the yaml files if $TAG is not empty. +# $KO_DOCKER_REPO is the registry containing the images to tag with $TAG. +# Parameters: $1..$n - yaml files to parse for images. +function tag_images_in_yamls() { + [[ -z ${TAG} ]] && return 0 + local SRC_DIR="${GOPATH}/src/" + local DOCKER_BASE="${KO_DOCKER_REPO}/${REPO_ROOT_DIR/$SRC_DIR}" + local GEO_REGIONS="${GEO_REPLICATION[@]} " + echo "Tagging images under '${DOCKER_BASE}' with ${TAG}" + for file in $@; do + echo "Inspecting ${file}" + for image in $(grep -o "${DOCKER_BASE}/[a-z\./-]\+@sha256:[0-9a-f]\+" ${file}); do + for region in "" ${GEO_REGIONS// /. }; do + gcloud -q container images add-tag ${image} ${region}${image%%@*}:${TAG} + done + done + done +} + +# Copy the given yaml files to the $RELEASE_GCS_BUCKET bucket's "latest" directory. +# If $TAG is not empty, also copy them to $RELEASE_GCS_BUCKET bucket's "previous" directory. +# Parameters: $1..$n - yaml files to copy. +function publish_yamls() { + function verbose_gsutil_cp { + local DEST="gs://${RELEASE_GCS_BUCKET}/$1/" + shift + echo "Publishing [$@] to ${DEST}" + gsutil cp $@ ${DEST} + } + # Before publishing the YAML files, cleanup the `latest` dir. + echo "Cleaning up the `latest` directory first" + gsutil -m rm gs://${RELEASE_GCS_BUCKET}/latest/** + verbose_gsutil_cp latest $@ + [[ -n ${TAG} ]] && verbose_gsutil_cp previous/${TAG} $@ +} + +# These are global environment variables. +SKIP_TESTS=0 +TAG_RELEASE=0 +PUBLISH_RELEASE=0 +PUBLISH_TO_GITHUB=0 +TAG="" +RELEASE_VERSION="" +RELEASE_NOTES="" +RELEASE_BRANCH="" +RELEASE_GCS_BUCKET="" +KO_FLAGS="" +VALIDATION_TESTS="./test/presubmit-tests.sh" +YAMLS_TO_PUBLISH="" +export KO_DOCKER_REPO="" +export GITHUB_TOKEN="" + +# Convenience function to run the hub tool. +# Parameters: $1..$n - arguments to hub. +function hub_tool() { + run_go_tool github.com/github/hub hub $@ +} + +# Return the master version of a release. +# For example, "v0.2.1" returns "0.2" +# Parameters: $1 - release version label. +function master_version() { + local release="${1//v/}" + local tokens=(${release//\./ }) + echo "${tokens[0]}.${tokens[1]}" +} + +# Return the release build number of a release. +# For example, "v0.2.1" returns "1". +# Parameters: $1 - release version label. +function release_build_number() { + local tokens=(${1//\./ }) + echo "${tokens[2]}" +} + +# Setup the repository upstream, if not set. +function setup_upstream() { + # hub and checkout need the upstream URL to be set + # TODO(adrcunha): Use "git remote get-url" once available on Prow. + local upstream="$(git config --get remote.upstream.url)" + echo "Remote upstream URL is '${upstream}'" + if [[ -z "${upstream}" ]]; then + echo "Setting remote upstream URL to '${KNATIVE_UPSTREAM}'" + git remote add upstream ${KNATIVE_UPSTREAM} + fi +} + +# Fetch the release branch, so we can check it out. +function setup_branch() { + [[ -z "${RELEASE_BRANCH}" ]] && return + git fetch ${KNATIVE_UPSTREAM} ${RELEASE_BRANCH}:upstream/${RELEASE_BRANCH} +} + +# Setup version, branch and release notes for a auto release. +function prepare_auto_release() { + echo "Auto release requested" + TAG_RELEASE=1 + PUBLISH_RELEASE=1 + + git fetch --all + local tags="$(git tag | cut -d 'v' -f2 | cut -d '.' -f1-2 | sort | uniq)" + local branches="$( { (git branch -r | grep upstream/release-) ; (git branch | grep release-); } | cut -d '-' -f2 | sort | uniq)" + RELEASE_VERSION="" + + [[ -n "${tags}" ]] || abort "cannot obtain release tags for the repository" + [[ -n "${branches}" ]] || abort "cannot obtain release branches for the repository" + + for i in $branches; do + RELEASE_NUMBER=$i + for j in $tags; do + if [[ "$i" == "$j" ]]; then + RELEASE_NUMBER="" + fi + done + done + + if [ -z "$RELEASE_NUMBER" ]; then + echo "*** No new release will be generated, as no new branches exist" + exit 0 + fi + + RELEASE_VERSION="${RELEASE_NUMBER}.0" + RELEASE_BRANCH="release-${RELEASE_NUMBER}" + echo "Will create release ${RELEASE_VERSION} from branch ${RELEASE_BRANCH}" + # If --release-notes not used, add a placeholder + if [[ -z "${RELEASE_NOTES}" ]]; then + RELEASE_NOTES="$(mktemp)" + echo "[add release notes here]" > ${RELEASE_NOTES} + fi +} + +# Setup version, branch and release notes for a "dot" release. +function prepare_dot_release() { + echo "Dot release requested" + TAG_RELEASE=1 + PUBLISH_RELEASE=1 + # List latest release + local releases # don't combine with the line below, or $? will be 0 + releases="$(hub_tool release)" + [[ $? -eq 0 ]] || abort "cannot list releases" + # If --release-branch passed, restrict to that release + if [[ -n "${RELEASE_BRANCH}" ]]; then + local version_filter="v${RELEASE_BRANCH##release-}" + echo "Dot release will be generated for ${version_filter}" + releases="$(echo "${releases}" | grep ^${version_filter})" + fi + local last_version="$(echo "${releases}" | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$' | sort -r | head -1)" + [[ -n "${last_version}" ]] || abort "no previous release exist" + if [[ -z "${RELEASE_BRANCH}" ]]; then + echo "Last release is ${last_version}" + # Determine branch + local major_minor_version="$(master_version ${last_version})" + RELEASE_BRANCH="release-${major_minor_version}" + echo "Last release branch is ${RELEASE_BRANCH}" + fi + # Ensure there are new commits in the branch, otherwise we don't create a new release + setup_branch + local last_release_commit="$(git rev-list -n 1 ${last_version})" + local release_branch_commit="$(git rev-list -n 1 upstream/${RELEASE_BRANCH})" + [[ -n "${last_release_commit}" ]] || abort "cannot get last release commit" + [[ -n "${release_branch_commit}" ]] || abort "cannot get release branch last commit" + if [[ "${last_release_commit}" == "${release_branch_commit}" ]]; then + echo "*** Branch ${RELEASE_BRANCH} is at commit ${release_branch_commit}" + echo "*** Branch ${RELEASE_BRANCH} has no new cherry-picks since release ${last_version}" + echo "*** No dot release will be generated, as no changes exist" + exit 0 + fi + # Create new release version number + local last_build="$(release_build_number ${last_version})" + RELEASE_VERSION="${major_minor_version}.$(( last_build + 1 ))" + echo "Will create release ${RELEASE_VERSION} at commit ${release_branch_commit}" + # If --release-notes not used, copy from the latest release + if [[ -z "${RELEASE_NOTES}" ]]; then + RELEASE_NOTES="$(mktemp)" + hub_tool release show -f "%b" ${last_version} > ${RELEASE_NOTES} + echo "Release notes from ${last_version} copied to ${RELEASE_NOTES}" + fi +} + +# Parses flags and sets environment variables accordingly. +function parse_flags() { + TAG="" + RELEASE_VERSION="" + RELEASE_NOTES="" + RELEASE_BRANCH="" + KO_FLAGS="-P" + KO_DOCKER_REPO="gcr.io/knative-nightly" + RELEASE_GCS_BUCKET="knative-nightly/${REPO_NAME}" + GITHUB_TOKEN="" + local has_gcr_flag=0 + local has_gcs_flag=0 + local is_dot_release=0 + local is_auto_release=0 + + cd ${REPO_ROOT_DIR} + while [[ $# -ne 0 ]]; do + local parameter=$1 + case ${parameter} in + --skip-tests) SKIP_TESTS=1 ;; + --tag-release) TAG_RELEASE=1 ;; + --notag-release) TAG_RELEASE=0 ;; + --publish) PUBLISH_RELEASE=1 ;; + --nopublish) PUBLISH_RELEASE=0 ;; + --dot-release) is_dot_release=1 ;; + --auto-release) is_auto_release=1 ;; + *) + [[ $# -ge 2 ]] || abort "missing parameter after $1" + shift + case ${parameter} in + --github-token) + [[ ! -f "$1" ]] && abort "file $1 doesn't exist" + # Remove any trailing newline/space from token + GITHUB_TOKEN="$(echo -n $(cat $1))" + [[ -n "${GITHUB_TOKEN}" ]] || abort "file $1 is empty" + ;; + --release-gcr) + KO_DOCKER_REPO=$1 + has_gcr_flag=1 + ;; + --release-gcs) + RELEASE_GCS_BUCKET=$1 + has_gcs_flag=1 + ;; + --version) + [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || abort "version format must be '[0-9].[0-9].[0-9]'" + RELEASE_VERSION=$1 + ;; + --branch) + [[ $1 =~ ^release-[0-9]+\.[0-9]+$ ]] || abort "branch name must be 'release-[0-9].[0-9]'" + RELEASE_BRANCH=$1 + ;; + --release-notes) + [[ ! -f "$1" ]] && abort "file $1 doesn't exist" + RELEASE_NOTES=$1 + ;; + *) abort "unknown option ${parameter}" ;; + esac + esac + shift + done + + # Do auto release unless release is forced + if (( is_auto_release )); then + + (( is_dot_release )) && abort "cannot have both --dot-release and --auto-release set simultaneously" + [[ -n "${RELEASE_VERSION}" ]] && abort "cannot have both --version and --auto-release set simultaneously" + [[ -n "${RELEASE_BRANCH}" ]] && abort "cannot have both --branch and --auto-release set simultaneously" + + setup_upstream + prepare_auto_release + + fi + + # Setup dot releases + if (( is_dot_release )); then + setup_upstream + prepare_dot_release + fi + + # Update KO_DOCKER_REPO and KO_FLAGS if we're not publishing. + if (( ! PUBLISH_RELEASE )); then + (( has_gcr_flag )) && echo "Not publishing the release, GCR flag is ignored" + (( has_gcs_flag )) && echo "Not publishing the release, GCS flag is ignored" + KO_DOCKER_REPO="ko.local" + KO_FLAGS="-L ${KO_FLAGS}" + RELEASE_GCS_BUCKET="" + fi + + if (( TAG_RELEASE )); then + # Get the commit, excluding any tags but keeping the "dirty" flag + local commit="$(git describe --always --dirty --match '^$')" + [[ -n "${commit}" ]] || abort "Error getting the current commit" + # Like kubernetes, image tag is vYYYYMMDD-commit + TAG="v$(date +%Y%m%d)-${commit}" + fi + + if [[ -n "${RELEASE_VERSION}" ]]; then + TAG="v${RELEASE_VERSION}" + fi + + [[ -n "${RELEASE_VERSION}" && -n "${RELEASE_BRANCH}" ]] && (( PUBLISH_RELEASE )) && PUBLISH_TO_GITHUB=1 + + readonly SKIP_TESTS + readonly TAG_RELEASE + readonly PUBLISH_RELEASE + readonly PUBLISH_TO_GITHUB + readonly TAG + readonly RELEASE_VERSION + readonly RELEASE_NOTES + readonly RELEASE_BRANCH + readonly RELEASE_GCS_BUCKET + readonly KO_DOCKER_REPO + readonly VALIDATION_TESTS +} + +# Run tests (unless --skip-tests was passed). Conveniently displays a banner indicating so. +# Parameters: $1 - executable that runs the tests. +function run_validation_tests() { + if (( ! SKIP_TESTS )); then + banner "Running release validation tests" + # Run tests. + if ! $1; then + banner "Release validation tests failed, aborting" + exit 1 + fi + fi +} + +# Entry point for a release script. +function main() { + function_exists build_release || abort "function 'build_release()' not defined" + [[ -x ${VALIDATION_TESTS} ]] || abort "test script '${VALIDATION_TESTS}' doesn't exist" + parse_flags $@ + # Log what will be done and where. + banner "Release configuration" + echo "- Destination GCR: ${KO_DOCKER_REPO}" + (( SKIP_TESTS )) && echo "- Tests will NOT be run" || echo "- Tests will be run" + if (( TAG_RELEASE )); then + echo "- Artifacts will be tagged '${TAG}'" + else + echo "- Artifacts WILL NOT be tagged" + fi + if (( PUBLISH_RELEASE )); then + echo "- Release WILL BE published to '${RELEASE_GCS_BUCKET}'" + else + echo "- Release will not be published" + fi + if (( PUBLISH_TO_GITHUB )); then + echo "- Release WILL BE published to GitHub" + fi + [[ -n "${RELEASE_BRANCH}" ]] && echo "- Release will be built from branch '${RELEASE_BRANCH}'" + [[ -n "${RELEASE_NOTES}" ]] && echo "- Release notes are generated from '${RELEASE_NOTES}'" + + # Checkout specific branch, if necessary + if [[ -n "${RELEASE_BRANCH}" ]]; then + setup_upstream + setup_branch + git checkout upstream/${RELEASE_BRANCH} || abort "cannot checkout branch ${RELEASE_BRANCH}" + fi + + set -o errexit + set -o pipefail + + run_validation_tests ${VALIDATION_TESTS} + banner "Building the release" + build_release + # Do not use `||` above or any error will be swallowed. + if [[ $? -ne 0 ]]; then + abort "error building the release" + fi + [[ -z "${YAMLS_TO_PUBLISH}" ]] && abort "no manifests were generated" + echo "New release built successfully" + if (( PUBLISH_RELEASE )); then + tag_images_in_yamls ${YAMLS_TO_PUBLISH} + publish_yamls ${YAMLS_TO_PUBLISH} + publish_to_github ${YAMLS_TO_PUBLISH} + echo "New release published successfully" + fi +} + +# Publishes a new release on GitHub, also git tagging it (unless this is not a versioned release). +# Parameters: $1..$n - YAML files to add to the release. +function publish_to_github() { + (( PUBLISH_TO_GITHUB )) || return 0 + local title="${REPO_NAME_FORMATTED} release ${TAG}" + local attachments=() + local description="$(mktemp)" + local attachments_dir="$(mktemp -d)" + local commitish="" + # Copy each YAML to a separate dir + for yaml in $@; do + cp ${yaml} ${attachments_dir}/ + attachments+=("--attach=${yaml}#$(basename ${yaml})") + done + echo -e "${title}\n" > ${description} + if [[ -n "${RELEASE_NOTES}" ]]; then + cat ${RELEASE_NOTES} >> ${description} + fi + git tag -a ${TAG} -m "${title}" + local repo_url="${KNATIVE_UPSTREAM}" + [[ -n "${GITHUB_TOKEN}}" ]] && repo_url="${repo_url/:\/\//:\/\/${GITHUB_TOKEN}@}" + hub_tool push ${repo_url} tag ${TAG} + + [[ -n "${RELEASE_BRANCH}" ]] && commitish="--commitish=${RELEASE_BRANCH}" + hub_tool release create \ + --prerelease \ + ${attachments[@]} \ + --file=${description} \ + ${commitish} \ + ${TAG} +} diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 000000000..585b22f22 --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,336 @@ +# cloud.google.com/go v0.34.0 +cloud.google.com/go/compute/metadata +# github.com/PuerkitoBio/purell v1.1.0 +github.com/PuerkitoBio/purell +# github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 +github.com/PuerkitoBio/urlesc +# github.com/davecgh/go-spew v1.1.1 +github.com/davecgh/go-spew/spew +# github.com/emicklei/go-restful v2.8.0+incompatible +github.com/emicklei/go-restful +github.com/emicklei/go-restful/log +# github.com/evanphx/json-patch v4.1.0+incompatible +github.com/evanphx/json-patch +# github.com/fsnotify/fsnotify v1.4.7 +github.com/fsnotify/fsnotify +# github.com/ghodss/yaml v1.0.0 +github.com/ghodss/yaml +# github.com/go-openapi/jsonpointer v0.17.0 +github.com/go-openapi/jsonpointer +# github.com/go-openapi/jsonreference v0.17.0 +github.com/go-openapi/jsonreference +# github.com/go-openapi/spec v0.18.0 +github.com/go-openapi/spec +# github.com/go-openapi/swag v0.17.0 +github.com/go-openapi/swag +# github.com/gogo/protobuf v1.2.0 +github.com/gogo/protobuf/proto +github.com/gogo/protobuf/sortkeys +# github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b +github.com/golang/glog +# github.com/golang/protobuf v1.2.0 +github.com/golang/protobuf/proto +github.com/golang/protobuf/ptypes/any +github.com/golang/protobuf/ptypes +github.com/golang/protobuf/ptypes/duration +github.com/golang/protobuf/ptypes/timestamp +# github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c +github.com/google/btree +# github.com/google/go-cmp v0.2.0 +github.com/google/go-cmp/cmp +github.com/google/go-cmp/cmp/internal/diff +github.com/google/go-cmp/cmp/internal/function +github.com/google/go-cmp/cmp/internal/value +# github.com/google/go-containerregistry v0.0.0-20190109170535-caf7c6e36671 +github.com/google/go-containerregistry/pkg/name +# github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf +github.com/google/gofuzz +# github.com/google/licenseclassifier v0.0.0-20190103191631-c2a262e3078a +github.com/google/licenseclassifier +github.com/google/licenseclassifier/internal/sets +github.com/google/licenseclassifier/stringclassifier +github.com/google/licenseclassifier/stringclassifier/searchset +github.com/google/licenseclassifier/stringclassifier/internal/pq +github.com/google/licenseclassifier/stringclassifier/searchset/tokenizer +# github.com/googleapis/gnostic v0.2.0 +github.com/googleapis/gnostic/OpenAPIv2 +github.com/googleapis/gnostic/compiler +github.com/googleapis/gnostic/extensions +# github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f +github.com/gregjones/httpcache +github.com/gregjones/httpcache/diskcache +# github.com/hashicorp/golang-lru v0.5.0 +github.com/hashicorp/golang-lru +github.com/hashicorp/golang-lru/simplelru +# github.com/hashicorp/hcl v1.0.0 +github.com/hashicorp/hcl +github.com/hashicorp/hcl/hcl/printer +github.com/hashicorp/hcl/hcl/ast +github.com/hashicorp/hcl/hcl/parser +github.com/hashicorp/hcl/hcl/token +github.com/hashicorp/hcl/json/parser +github.com/hashicorp/hcl/hcl/scanner +github.com/hashicorp/hcl/hcl/strconv +github.com/hashicorp/hcl/json/scanner +github.com/hashicorp/hcl/json/token +# github.com/imdario/mergo v0.3.6 +github.com/imdario/mergo +# github.com/inconshreveable/mousetrap v1.0.0 +github.com/inconshreveable/mousetrap +# github.com/json-iterator/go v1.1.5 +github.com/json-iterator/go +# github.com/knative/build v0.3.0 +github.com/knative/build/pkg/apis/build/v1alpha1 +github.com/knative/build/pkg/apis/build +# github.com/knative/pkg v0.0.0-20190110005142-b6044a7d1795 +github.com/knative/pkg/apis +github.com/knative/pkg/apis/duck/v1alpha1 +github.com/knative/pkg/kmeta +github.com/knative/pkg/kmp +github.com/knative/pkg/apis/duck +# github.com/knative/serving v0.3.0 +github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1 +github.com/knative/serving/pkg/apis/serving/v1alpha1 +github.com/knative/serving/pkg/client/clientset/versioned/scheme +github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake +github.com/knative/serving/pkg/apis/autoscaling +github.com/knative/serving/pkg/apis/networking/v1alpha1 +github.com/knative/serving/pkg/apis/serving +github.com/knative/serving/pkg/apis/autoscaling/v1alpha1 +github.com/knative/serving/pkg/apis/networking +# github.com/knative/test-infra v0.0.0-20190304225739-6bb6546d833a +github.com/knative/test-infra/scripts +# github.com/magiconair/properties v1.8.0 +github.com/magiconair/properties +# github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 +github.com/mailru/easyjson/jlexer +github.com/mailru/easyjson/jwriter +github.com/mailru/easyjson/buffer +# github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a +github.com/mattbaird/jsonpatch +# github.com/mitchellh/go-homedir v1.0.0 +github.com/mitchellh/go-homedir +# github.com/mitchellh/mapstructure v1.1.2 +github.com/mitchellh/mapstructure +# github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd +github.com/modern-go/concurrent +# github.com/modern-go/reflect2 v1.0.1 +github.com/modern-go/reflect2 +# github.com/pelletier/go-toml v1.2.0 +github.com/pelletier/go-toml +# github.com/peterbourgon/diskv v2.0.1+incompatible +github.com/peterbourgon/diskv +# github.com/pkg/errors v0.8.1 +github.com/pkg/errors +# github.com/sergi/go-diff v1.0.0 +github.com/sergi/go-diff/diffmatchpatch +# github.com/spf13/afero v1.2.0 +github.com/spf13/afero +github.com/spf13/afero/mem +# github.com/spf13/cast v1.3.0 +github.com/spf13/cast +# github.com/spf13/cobra v0.0.3 +github.com/spf13/cobra +# github.com/spf13/jwalterweatherman v1.0.0 +github.com/spf13/jwalterweatherman +# github.com/spf13/pflag v1.0.3 +github.com/spf13/pflag +# github.com/spf13/viper v1.3.1 +github.com/spf13/viper +# golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc +golang.org/x/crypto/ssh/terminal +# golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e +golang.org/x/net/http2 +golang.org/x/net/http/httpguts +golang.org/x/net/http2/hpack +golang.org/x/net/idna +golang.org/x/net/context/ctxhttp +golang.org/x/net/context +# golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 +golang.org/x/oauth2 +golang.org/x/oauth2/google +golang.org/x/oauth2/internal +golang.org/x/oauth2/jws +golang.org/x/oauth2/jwt +# golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb +golang.org/x/sys/unix +golang.org/x/sys/windows +# golang.org/x/text v0.3.0 +golang.org/x/text/transform +golang.org/x/text/unicode/norm +golang.org/x/text/encoding/unicode +golang.org/x/text/encoding +golang.org/x/text/encoding/internal +golang.org/x/text/encoding/internal/identifier +golang.org/x/text/internal/utf8internal +golang.org/x/text/runes +golang.org/x/text/secure/bidirule +golang.org/x/text/unicode/bidi +golang.org/x/text/width +# golang.org/x/time v0.0.0-20181108054448-85acf8d2951c +golang.org/x/time/rate +# google.golang.org/appengine v1.4.0 +google.golang.org/appengine +google.golang.org/appengine/urlfetch +google.golang.org/appengine/internal +google.golang.org/appengine/internal/app_identity +google.golang.org/appengine/internal/modules +google.golang.org/appengine/internal/urlfetch +google.golang.org/appengine/internal/base +google.golang.org/appengine/internal/datastore +google.golang.org/appengine/internal/log +google.golang.org/appengine/internal/remote_api +# gopkg.in/inf.v0 v0.9.1 +gopkg.in/inf.v0 +# gopkg.in/yaml.v2 v2.2.2 +gopkg.in/yaml.v2 +# k8s.io/api v0.0.0-20181221193117-173ce66c1e39 +k8s.io/api/core/v1 +k8s.io/api/autoscaling/v1 +k8s.io/api/admissionregistration/v1alpha1 +k8s.io/api/admissionregistration/v1beta1 +k8s.io/api/apps/v1 +k8s.io/api/apps/v1beta1 +k8s.io/api/apps/v1beta2 +k8s.io/api/authentication/v1 +k8s.io/api/authentication/v1beta1 +k8s.io/api/authorization/v1 +k8s.io/api/authorization/v1beta1 +k8s.io/api/autoscaling/v2beta1 +k8s.io/api/autoscaling/v2beta2 +k8s.io/api/batch/v1 +k8s.io/api/batch/v1beta1 +k8s.io/api/batch/v2alpha1 +k8s.io/api/certificates/v1beta1 +k8s.io/api/coordination/v1beta1 +k8s.io/api/events/v1beta1 +k8s.io/api/extensions/v1beta1 +k8s.io/api/networking/v1 +k8s.io/api/policy/v1beta1 +k8s.io/api/rbac/v1 +k8s.io/api/rbac/v1alpha1 +k8s.io/api/rbac/v1beta1 +k8s.io/api/scheduling/v1alpha1 +k8s.io/api/scheduling/v1beta1 +k8s.io/api/settings/v1alpha1 +k8s.io/api/storage/v1 +k8s.io/api/storage/v1alpha1 +k8s.io/api/storage/v1beta1 +# k8s.io/apimachinery v0.0.0-20190104073114-849b284f3b75 +k8s.io/apimachinery/pkg/apis/meta/v1 +k8s.io/apimachinery/pkg/runtime/schema +k8s.io/apimachinery/pkg/runtime/serializer +k8s.io/apimachinery/pkg/types +k8s.io/apimachinery/pkg/watch +k8s.io/apimachinery/pkg/api/resource +k8s.io/apimachinery/pkg/conversion +k8s.io/apimachinery/pkg/fields +k8s.io/apimachinery/pkg/labels +k8s.io/apimachinery/pkg/runtime +k8s.io/apimachinery/pkg/selection +k8s.io/apimachinery/pkg/util/intstr +k8s.io/apimachinery/pkg/util/runtime +k8s.io/apimachinery/pkg/api/meta +k8s.io/apimachinery/pkg/util/json +k8s.io/apimachinery/pkg/util/net +k8s.io/apimachinery/pkg/util/yaml +k8s.io/apimachinery/pkg/util/errors +k8s.io/apimachinery/pkg/util/validation +k8s.io/apimachinery/pkg/api/equality +k8s.io/apimachinery/pkg/apis/meta/v1/unstructured +k8s.io/apimachinery/pkg/runtime/serializer/json +k8s.io/apimachinery/pkg/runtime/serializer/protobuf +k8s.io/apimachinery/pkg/runtime/serializer/recognizer +k8s.io/apimachinery/pkg/runtime/serializer/versioning +k8s.io/apimachinery/pkg/api/errors +k8s.io/apimachinery/pkg/runtime/serializer/streaming +k8s.io/apimachinery/pkg/util/sets +k8s.io/apimachinery/third_party/forked/golang/reflect +k8s.io/apimachinery/pkg/conversion/queryparams +k8s.io/apimachinery/pkg/util/naming +k8s.io/apimachinery/pkg/apis/meta/v1beta1 +k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme +k8s.io/apimachinery/pkg/version +k8s.io/apimachinery/pkg/util/validation/field +k8s.io/apimachinery/pkg/util/strategicpatch +k8s.io/apimachinery/pkg/util/framer +k8s.io/apimachinery/pkg/util/clock +k8s.io/apimachinery/pkg/util/mergepatch +k8s.io/apimachinery/third_party/forked/golang/json +k8s.io/apimachinery/pkg/util/cache +k8s.io/apimachinery/pkg/util/diff +k8s.io/apimachinery/pkg/util/wait +k8s.io/apimachinery/pkg/api/validation +k8s.io/apimachinery/pkg/apis/meta/v1/validation +k8s.io/apimachinery/pkg/apis/meta/internalversion +# k8s.io/cli-runtime v0.0.0-20190107235426-31214e12222d +k8s.io/cli-runtime/pkg/genericclioptions +k8s.io/cli-runtime/pkg/genericclioptions/printers +k8s.io/cli-runtime/pkg/genericclioptions/resource +k8s.io/cli-runtime/pkg/kustomize/k8sdeps +k8s.io/cli-runtime/pkg/kustomize/k8sdeps/kunstruct +k8s.io/cli-runtime/pkg/kustomize/k8sdeps/transformer +k8s.io/cli-runtime/pkg/kustomize/k8sdeps/validator +k8s.io/cli-runtime/pkg/kustomize/k8sdeps/configmapandsecret +k8s.io/cli-runtime/pkg/kustomize/k8sdeps/transformer/hash +k8s.io/cli-runtime/pkg/kustomize/k8sdeps/transformer/patch +# k8s.io/client-go v2.0.0-alpha.0.0.20181015214059-cbd9965a0e71+incompatible +k8s.io/client-go/plugin/pkg/client/auth/gcp +k8s.io/client-go/tools/clientcmd +k8s.io/client-go/rest +k8s.io/client-go/discovery +k8s.io/client-go/restmapper +k8s.io/client-go/tools/clientcmd/api +k8s.io/client-go/util/homedir +k8s.io/client-go/util/jsonpath +k8s.io/client-go/tools/auth +k8s.io/client-go/tools/clientcmd/api/latest +k8s.io/client-go/testing +k8s.io/client-go/pkg/version +k8s.io/client-go/plugin/pkg/client/auth/exec +k8s.io/client-go/rest/watch +k8s.io/client-go/tools/metrics +k8s.io/client-go/transport +k8s.io/client-go/util/cert +k8s.io/client-go/util/flowcontrol +k8s.io/client-go/kubernetes/scheme +k8s.io/client-go/third_party/forked/golang/template +k8s.io/client-go/tools/clientcmd/api/v1 +k8s.io/client-go/tools/cache +k8s.io/client-go/pkg/apis/clientauthentication +k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1 +k8s.io/client-go/pkg/apis/clientauthentication/v1beta1 +k8s.io/client-go/util/connrotation +k8s.io/client-go/util/integer +k8s.io/client-go/dynamic +k8s.io/client-go/tools/pager +k8s.io/client-go/util/buffer +k8s.io/client-go/util/retry +# k8s.io/klog v0.1.0 +k8s.io/klog +# k8s.io/kube-openapi v0.0.0-20181114233023-0317810137be +k8s.io/kube-openapi/pkg/util/proto +k8s.io/kube-openapi/pkg/common +# sigs.k8s.io/kustomize v1.0.11 +sigs.k8s.io/kustomize/pkg/commands/build +sigs.k8s.io/kustomize/pkg/constants +sigs.k8s.io/kustomize/pkg/fs +sigs.k8s.io/kustomize/pkg/factory +sigs.k8s.io/kustomize/pkg/ifc/transformer +sigs.k8s.io/kustomize/pkg/loader +sigs.k8s.io/kustomize/pkg/resmap +sigs.k8s.io/kustomize/pkg/target +sigs.k8s.io/kustomize/pkg/gvk +sigs.k8s.io/kustomize/pkg/ifc +sigs.k8s.io/kustomize/pkg/types +sigs.k8s.io/kustomize/pkg/resource +sigs.k8s.io/kustomize/pkg/transformers +sigs.k8s.io/kustomize/pkg/internal/error +sigs.k8s.io/kustomize/pkg/resid +sigs.k8s.io/kustomize/pkg/patch/transformer +sigs.k8s.io/kustomize/pkg/transformers/config +sigs.k8s.io/kustomize/pkg/patch +sigs.k8s.io/kustomize/pkg/expansion +sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig +# sigs.k8s.io/yaml v1.1.0 +sigs.k8s.io/yaml