Skip to content
Open
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
22 changes: 17 additions & 5 deletions internal/kokoro/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ export GOOGLE_API_GO_EXPERIMENTAL_ENABLE_NEW_AUTH_LIB="true"
# Display commands being run
set -x

# Define some utility functions
logmsg() { echo "[$(date "+%Y-%m-%d %H:%M:%S")] $1"; }
# quick func to measure duration of a specific command
logduration() {
local start_time=$(date +%s)
logmsg "Measuring duration for command: $*"
# Execute the command
"$@"
local end_time=$(date +%s)
local duration=$((end_time - start_time))
logmsg "command completed in ${duration} seconds"
}
try3() { eval "$*" || eval "$*" || eval "$*"; }

# cd to project dir on Kokoro instance
cd github/google-api-go-client
git config --global --add safe.directory "$(pwd)/./.git"
Expand All @@ -39,18 +53,16 @@ export GO111MODULE=on
mkdir -p $GOCLOUD_HOME

# Move code into $GOPATH and get dependencies
git clone . $GOCLOUD_HOME
logduration git clone . $GOCLOUD_HOME
cd $GOCLOUD_HOME

try3() { eval "$*" || eval "$*" || eval "$*"; }

# All packages, including +build tools, are fetched.
try3 go mod download
./internal/kokoro/vet.sh
logduration ./internal/kokoro/vet.sh

# Testing the generator itself depends on a generation step
cd google-api-go-generator
go generate
logduration go generate
cd ..

set +e # Run all tests, don't stop after the first failure.
Expand Down
26 changes: 24 additions & 2 deletions internal/kokoro/vet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,44 @@
# Fail on error, and display commands being run.
set -ex

# Define some utility functions
logmsg() { echo "[$(date "+%Y-%m-%d %H:%M:%S")] $1"; }
# quick func to measure duration of a specific command
logduration() {
local start_time=$(date +%s)
logmsg "Measuring duration for command: $*"
# Execute the command
"$@"
local end_time=$(date +%s)
local duration=$((end_time - start_time))
logmsg "command completed in ${duration} seconds"
}

if [[ $KOKORO_JOB_NAME != *"latest-version"* ]]; then
exit 0
fi

# Fail if a dependency was added without the necessary go.mod/go.sum change
# being part of the commit.
go mod tidy
logduration go mod tidy
git diff go.mod | tee /dev/stderr | (! read)
git diff go.sum | tee /dev/stderr | (! read)

# Easier to debug CI.
pwd

logmsg gofmt start
gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)
logmsg goimports start
goimports -l . 2>&1 | tee /dev/stderr | (! read)
logmsg goimports stop

# Experiment: only test the "known" handwritten roots
export MANUAL_PACKAGES="./google-api-go-generator/... ./googleapi/... ./idtoken/... ./internal/... ./iterator/... ./option/..."

# Runs the linter. Regrettably the linter is very simple and does not provide the ability to exclude rules or files,
# so we rely on inverse grepping to do this for us.
logmsg golint start
golint ./... 2>&1 | (
grep -v "gen.go" |
grep -v "disco.go" |
Expand All @@ -41,9 +61,11 @@ golint ./... 2>&1 | (
grep -vE "\.pb\.go:" || true
) | tee /dev/stderr | (! read)

staticcheck -go 1.24 ./... 2>&1 | (
logmsg staticcheck start
staticcheck -go 1.24 ${MANUAL_PACKAGES} 2>&1 | (
grep -v "SA1019" |
grep -v "S1007" |
grep -v "error var Done should have name of the form ErrFoo" |
grep -v "examples" || true
) | tee /dev/stderr | (! read)
logmsg done with vet