diff --git a/.travis.yml b/.travis.yml index 4f15008944..0fe57ab80e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +env: + global: + - KUBE_VERSION: 1.13 language: go go: - 1.11.5 @@ -8,22 +11,10 @@ jobs: cache: directories: - $HOME/.cache/go-build - # Don't want default ./... here: install: - - export PATH=$GOPATH/bin:$PATH - - mkdir -p $HOME/gopath/src/k8s.io - - mv $TRAVIS_BUILD_DIR $HOME/gopath/src/k8s.io/website && cd $HOME/gopath/src/k8s.io/website - - # Make sure we are testing against the correct branch - - pushd $GOPATH/src/k8s.io && git clone https://github.com/kubernetes/kubernetes && popd - - pushd $GOPATH/src/k8s.io/kubernetes && git checkout release-1.13 && make generated_files && popd - - cp -L -R $GOPATH/src/k8s.io/kubernetes/vendor/ $GOPATH/src/ - - rm -r $GOPATH/src/k8s.io/kubernetes/vendor/ - - # Fetch additional dependencies to run the tests in examples/examples_test.go - - go get -t -v k8s.io/website/content/en/examples + - bash scripts/test_examples.sh install script: - - go test -v k8s.io/website/content/en/examples + - bash scripts/test_examples.sh run - name: "Hugo build" install: - make travis-hugo-build diff --git a/scripts/test_examples.sh b/scripts/test_examples.sh new file mode 100644 index 0000000000..9938477871 --- /dev/null +++ b/scripts/test_examples.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +# List files changed in the commit to check +FILES=`git log -n 2 --name-only --format=""` + +TEST_EXAMPLES=No + +# Currently examine en directory only, can extend to other lang when neded +for f in $FILES; do + if [[ $f =~ "content/en/examples/" ]]; then + TEST_EXAMPLES=Yes + break + fi + if [[ $f =~ ".travis.yml" ]]; then + TEST_EXAMPLES=Yes + break + fi +done + +function install() { + if [[ $TEST_EXAMPLES == No ]]; then + echo "PR not touching examples, skipping example tests install" + exit 0 + fi + + export PATH=$GOPATH/bin:$PATH + mkdir -p $HOME/gopath/src/k8s.io + mv $TRAVIS_BUILD_DIR $HOME/gopath/src/k8s.io/website && cd $HOME/gopath/src/k8s.io/website + + # Make sure we are testing against the correct branch + wget https://github.com/kubernetes/kubernetes/archive/v${KUBE_VERSION}.0.tar.gz -P $GOPATH/src/k8s.io + + pushd $GOPATH/src/k8s.io + tar xzf v${KUBE_VERSION}.0.tar.gz + mv kubernetes-${KUBE_VERSION}.0 kubernetes + cd kubernetes + make generated_files + cp -L -R vendor $GOPATH/src/ + rm -r vendor + popd + + # Fetch additional dependencies to run the tests in examples/examples_test.go + go get -t -v k8s.io/website/content/en/examples +} + +function run_test() { + if [[ $TEST_EXAMPLES == No ]]; then + echo "PR not touching examples, skipping example tests execution" + exit 0 + fi + go test -v k8s.io/website/content/en/examples +} + +if [[ $1 == install ]]; then + install + exit 0 +elif [[ $1 == "run" ]]; then + run_test +fi