fix(build): Minor build optimizations (#265)

* Check that every generated file has been regenerated for CI
* No color when not on a tty which is useful for build logs
* Always do updates when called without args
* Removed -u option and added -c for codegen only (dep update, docs gen, formatting, license check)
This commit is contained in:
Roland Huß 2019-07-15 22:21:27 +02:00 committed by Knative Prow Robot
parent fca0a09e86
commit 55073029b4
8 changed files with 37 additions and 95 deletions

View File

@ -73,7 +73,7 @@ You can link that script into a directory within your search `$PATH`. This allow
* `build.sh` - Compile, test, generate docs and format source code * `build.sh` - Compile, test, generate docs and format source code
* `build.sh -f` - Compile only * `build.sh -f` - Compile only
* `build.sh -f -t` - Compile & test * `build.sh -f -t` - Compile & test
* `build.sh -u` - Update dependencies before compiling * `build.sh -c` - Update dependencies, regenerate documentation and format source files
* `build.sh -w` - Enter watch mode for automatic recompilation * `build.sh -w` - Enter watch mode for automatic recompilation
* `build.sh -w -t` - Enter watch mode for automatic recompilation & running tests * `build.sh -w -t` - Enter watch mode for automatic recompilation & running tests

View File

@ -19,7 +19,6 @@ Manage your Knative building blocks:
### SEE ALSO ### SEE ALSO
* [kn completion](kn_completion.md) - Output shell completion code (default Bash)
* [kn revision](kn_revision.md) - Revision command group * [kn revision](kn_revision.md) - Revision command group
* [kn route](kn_route.md) - Route command group * [kn route](kn_route.md) - Route command group
* [kn service](kn_service.md) - Service command group * [kn service](kn_service.md) - Service command group

View File

@ -1,30 +0,0 @@
## kn completion
Output shell completion code (default Bash)
### Synopsis
Output shell completion code (default Bash)
```
kn completion [flags]
```
### Options
```
-h, --help help for completion
--zsh Generates completion code for Zsh shell.
```
### Options inherited from parent commands
```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```
### SEE ALSO
* [kn](kn.md) - Knative client

1
go.sum
View File

@ -342,6 +342,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZe
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09 h1:6Cq5LXQ/D2J5E7sYJemWSQApczOzY1rxSp8TWloyxIY=
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=

View File

@ -47,16 +47,17 @@ run() {
fi fi
if $(has_flag --watch -w); then if $(has_flag --watch -w); then
# Build and test first
go_build
go_test
# Go in endless loop, to be stopped with CTRL-C
watch watch
# No exit, needs to be stopped with CTRL-C anyways
fi fi
if $(has_flag -u --update); then if ! $(has_flag --fast -f) || $(has_flag --codegen -c); then
# Update dependencies # Update dependencies
update_deps update_deps
fi
if ! $(has_flag --fast -f); then
# Format source code and cleanup imports # Format source code and cleanup imports
source_format source_format
@ -69,6 +70,11 @@ run() {
generate_docs generate_docs
fi fi
# Stop when only codegen is requested
if $(has_flag --codegen -c); then
exit 0
fi
# Run build # Run build
go_build go_build
@ -91,7 +97,7 @@ source_format() {
which goimports >/dev/null 2>&1 which goimports >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "✋ No 'goimports' found. Please use" echo "✋ No 'goimports' found. Please use"
echo "✋ go get golang.org/x/tools/cmd/goimports" echo "✋ go install golang.org/x/tools/cmd/goimports"
echo "✋ to enable import cleanup. Import cleanup skipped." echo "✋ to enable import cleanup. Import cleanup skipped."
# Run go fmt instead # Run go fmt instead
@ -112,8 +118,14 @@ go_build() {
go_test() { go_test() {
local test_output=$(mktemp /tmp/kn-client-test-output.XXXXXX) local test_output=$(mktemp /tmp/kn-client-test-output.XXXXXX)
local red=""
local reset="" local red=""
local reset=""
# Use color only when a terminal is set
if [ -t 1 ]; then
red=""
reset=""
fi
echo "🧪 ${S}Test" echo "🧪 ${S}Test"
set +e set +e
@ -240,10 +252,9 @@ Usage: $(basename $BASH_SOURCE) [... options ...]
with the following options: with the following options:
-f --fast Only compile (without formatting, testing, doc generation) -f --fast Only compile (without dep update, formatting, testing, doc gen)
-t --test Run tests when used with --fast or --watch -t --test Run tests when used with --fast or --watch
-i --imports Organize and cleanup imports -c --codegen Runs formatting, doc gen and update without compiling/testing
-u --update Update dependencies before compiling
-w --watch Watch for source changes and recompile in fast mode -w --watch Watch for source changes and recompile in fast mode
-h --help Display this help message -h --help Display this help message
--verbose More output --verbose More output

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
# Copyright 2019 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.
set -o errexit
set -o nounset
set -o pipefail
# GO111MODULE used so that it works no matter if someone has this repo
# cloned under $GOPATH or not
GO111MODULE=on go mod vendor

View File

@ -20,33 +20,17 @@ set -o pipefail
source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/library.sh source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/library.sh
readonly TMP_DIFFROOT="$(mktemp -d ${REPO_ROOT_DIR}/tmpdiffroot.XXXXXX)" # Needed later
go install golang.org/x/tools/cmd/goimports
cleanup() { "${REPO_ROOT_DIR}"/hack/build.sh --codegen
rm -rf "${TMP_DIFFROOT}" if output="$(git status --porcelain)" && [ -z "$output" ]; then
} echo "${REPO_ROOT_DIR} is up to date."
trap "cleanup" EXIT SIGINT
cleanup
# Save working tree state
mkdir -p "${TMP_DIFFROOT}/vendor"
cp -aR "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}"
"${REPO_ROOT_DIR}/hack/update-deps.sh"
echo "Diffing ${REPO_ROOT_DIR} against freshly update dependencies"
ret=0
diff -Naupr --no-dereference "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1
# Restore working tree state
rm -fr "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/vendor"
cp -aR "${TMP_DIFFROOT}"/* "${REPO_ROOT_DIR}"
if [[ $ret -eq 0 ]]
then
echo "${REPO_ROOT_DIR} up to date."
else else
echo "ERROR: ${REPO_ROOT_DIR} is out of date. Please run ./hack/update-deps.sh" echo "ERROR: Modified files found:"
git status --porcelain
echo "ERROR: Diff"
git diff
echo "ERROR: ${REPO_ROOT_DIR} is out of date. Please run ./hack/build.sh -u and commit."
exit 1 exit 1
fi fi

View File

@ -28,9 +28,9 @@ func NewCompletionCommand(p *KnParams) *cobra.Command {
var completionFlags CompletionFlags var completionFlags CompletionFlags
completionCmd := &cobra.Command{ completionCmd := &cobra.Command{
Use: "completion", Use: "completion",
Short: "Output shell completion code (default Bash)", Short: "Output shell completion code (default Bash)",
Hidden: true, // Don't show this in help listing. Hidden: true, // Don't show this in help listing.
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if completionFlags.Zsh { if completionFlags.Zsh {
cmd.Root().GenZshCompletion(os.Stdout) cmd.Root().GenZshCompletion(os.Stdout)