diff --git a/.gitignore b/.gitignore index aada8fd38838..e63d24faf8b3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ src/app/frontend/environments/version.ts # Local copies of dependencies that should stay on developers' local machines: node_modules/ +vendor/ # Build and test artifacts: .go_workspace/ diff --git a/.travis.yml b/.travis.yml index a449e4f817e0..34fe33bf3fe8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,9 +25,6 @@ before_install: - mv $HOME/build/kubernetes $GOPATH/src/github.com/ - export TRAVIS_BUILD_DIR=$GOPATH/src/github.com/kubernetes/dashboard - cd $TRAVIS_BUILD_DIR - - mkdir -p $TRAVIS_BUILD_DIR/.tmp/src/github.com/kubernetes/dashboard/src/app - - cp -r $TRAVIS_BUILD_DIR/src/app/backend $TRAVIS_BUILD_DIR/.tmp/src/github.com/kubernetes/dashboard/src/app - - ln -s $TRAVIS_BUILD_DIR/vendor $TRAVIS_BUILD_DIR/.tmp/src/github.com/kubernetes/dashboard/src/app/backend/vendor before_script: - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - @@ -43,7 +40,6 @@ jobs: script: npm run check - script: npm run test:coverage after_success: - - rm -rf $TRAVIS_BUILD_DIR/.tmp - bash <(curl -s https://codecov.io/bash) - script: npm run cluster:start && npm run test:e2e - stage: deploy diff --git a/aio/scripts/update-vendor.sh b/aio/scripts/update-vendor.sh new file mode 100755 index 000000000000..88daa7925e09 --- /dev/null +++ b/aio/scripts/update-vendor.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Copyright 2019 The Kubernetes 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. + +TMP_DIR="${TMP_DIR:-$(mktemp -d /tmp/update-vendor.XXXX)}" + +echo "vendor: running 'go mod tidy'" +go mod tidy -v + +echo "vendor: running 'go mod vendor'" +go mod vendor + +# sort recorded packages for a given vendored dependency in modules.txt. +# `go mod vendor` outputs in imported order, which means slight go changes (or different platforms) can result in a differently ordered modules.txt. +# scan | prefix comment lines with the module name | sort field 1 | strip leading text on comment lines +awk '{if($1=="#") print $2 " " $0; else print}' < vendor/modules.txt | sort -k1,1 -s | sed 's/.*#/#/' > "${TMP_DIR}/modules.txt.tmp" +mv "${TMP_DIR}/modules.txt.tmp" vendor/modules.txt + +echo "Vendor Updated" \ No newline at end of file diff --git a/aio/scripts/verify-vendor.sh b/aio/scripts/verify-vendor.sh new file mode 100755 index 000000000000..b4d161766c70 --- /dev/null +++ b/aio/scripts/verify-vendor.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# Copyright 2015 The Kubernetes 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. + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. + +mkdir -p "${KUBE_ROOT}/_tmp" +_tmpdir="$(mktemp -d "${KUBE_ROOT}/_tmp/kube-vendor.XXXXXX")" + +if [[ -z ${KEEP_TMP:-} ]]; then + KEEP_TMP=false +fi + +# Copy the contents of the kube directory into the nice clean place (which is NOT shaped like a GOPATH) +_kubetmp="${_tmpdir}" +mkdir -p "${_kubetmp}" +# should create ${_kubectmp}/kubernetes +git archive --format=tar --prefix=kubernetes/ "$(git write-tree)" | (cd "${_kubetmp}" && tar xf -) +_kubetmp="${_kubetmp}/kubernetes" + +pushd "${_kubetmp}" > /dev/null 2>&1 + # Destroy deps in the copy of the kube tree + rm -rf ./vendor + + # Recreate the vendor tree using the nice clean set we just downloaded + aio/scripts/update-vendor.sh +popd > /dev/null 2>&1 + +ret=0 + +pushd "${KUBE_ROOT}" > /dev/null 2>&1 + # Test for diffs + if ! _out="$(diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' go.mod "${_kubetmp}/go.mod")"; then + echo "Your go.mod file is different:" >&2 + echo "${_out}" >&2 + echo "Vendor Verify failed." >&2 + echo "If you're seeing this locally, run the below command to fix your go.mod:" >&2 + echo "npm run fix:backend:vendor" >&2 + ret=1 + fi +popd > /dev/null 2>&1 + +chmod -R +w "${_tmpdir}" +if [ "${KEEP_TMP}" == "true" ]; then + echo "Leaving ${_tmpdir} for you to examine or copy. Please delete it manually when finished. (rm -rf ${_tmpdir})" +else + echo "Removing ${_tmpdir}" + rm -rf "${_tmpdir}" +fi + +if [[ ${ret} -gt 0 ]]; then + exit ${ret} +fi + +echo "Vendor Verified." +# ex: ts=2 sw=2 et filetype=sh diff --git a/package.json b/package.json index e10e2c157e91..fc1d6de9d7d3 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,9 @@ "cluster:start": "./aio/scripts/start-cluster.sh", "cluster:stop": "./aio/scripts/stop-cluster.sh", "check": "concurrently \"npm run check:backend\" \"npm run check:frontend\" \"npm run check:license\" \"npm run check:i18n\"", - "check:backend": "golangci-lint run -c .golangci.yml src/app/backend/...", + "check:backend": "concurrently \"npm run check:backend:lint\" \"npm run check:backend:vendor\"", + "check:backend:lint": "golangci-lint run -c .golangci.yml src/app/backend/...", + "check:backend:vendor": "./aio/scripts/verify-vendor.sh", "check:frontend": "concurrently \"npm run check:frontend:ts\" \"npm run check:frontend:scss\" \"npm run check:frontend:html\"", "check:frontend:ts": "gts check", "check:frontend:scss": "./aio/scripts/format.sh --styles --check && ./node_modules/sass-lint/bin/sass-lint.js -c .sass-lint.yml 'src/app/frontend/**/*.scss' -v -q", @@ -44,7 +46,9 @@ "check:license": "gulp check-license-headers", "check:i18n": "ng xi18n --outFile ../i18n/messages.xlf", "fix": "concurrently \"npm run fix:backend\" \"npm run fix:frontend\" \"npm run fix:license\" \"npm run fix:i18n\"", - "fix:backend": "golangci-lint run -c .golangci.yml --fix src/app/backend/...", + "fix:backend": "concurrently \"npm run fix:backend:lint\" \"npm run fix:backend:vendor\"", + "fix:backend:lint": "golangci-lint run -c .golangci.yml --fix src/app/backend/...", + "fix:backend:vendor": "./aio/scripts/update-vendor.sh", "fix:frontend": "concurrently \"npm run fix:frontend:ts\" \"npm run fix:frontend:scss\" \"npm run fix:frontend:html\"", "fix:frontend:ts": "gts fix", "fix:frontend:scss": "scssfmt -r 'src/**/*.scss'",