Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go modules verification and update scripts #3995

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions aio/scripts/update-vendor.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed as it would create a local vendor dir.


# 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"
72 changes: 72 additions & 0 deletions aio/scripts/verify-vendor.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@
"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",
"check:frontend:html": "./aio/scripts/format.sh --html --check",
"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'",
Expand Down