diff --git a/.travis.yml b/.travis.yml index 050f0a3c1..fe565ff0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,15 @@ go: 1.17.x dist: xenial +git: + depth: 10 + +# Build master and PRs which merge into those branches +# We don't automatically build other branches when they're pushed; create a PR to cause the CI to run. +branches: + only: + - master + cache: directories: - vendor @@ -26,7 +35,8 @@ env: - REDIS_URL="redis://" stages: -- test + - name: test + if: (type = push OR type = pull_request) AND branch = master before_cache: - make clean @@ -34,17 +44,24 @@ before_cache: jobs: include: - stage: test - name: linux - go: 1.17.x + name: lint + script: - make deps - make lintall + + - stage: test + name: linux + + script: + - make deps - GO111MODULE=on make build - mkdir -p build/linux/amd64 - cp ${GOPATH%%:*}/bin/travis-worker build/linux/amd64 - make test-no-cover - make test-cover - make smoke + addons: apt: packages: @@ -56,11 +73,13 @@ jobs: - travis-ci/worker/$TRAVIS_BUILD_NUMBER/$TRAVIS_JOB_NUMBER - travis-ci/worker/$(git describe --always --dirty --tags) - travis-ci/worker/$TRAVIS_BRANCH + - stage: test name: crossbuild - go: 1.17.x + script: - GO111MODULE=on make build/darwin/amd64/travis-worker + addons: artifacts: paths: @@ -69,9 +88,11 @@ jobs: - travis-ci/worker/$TRAVIS_BUILD_NUMBER/$TRAVIS_JOB_NUMBER - travis-ci/worker/$(git describe --always --dirty --tags) - travis-ci/worker/$TRAVIS_BRANCH + - stage: test name: docker if: type != 'pull_request' && env(VAULT_PASS) is present && env(VAULT_USERNAME) is present + script: - vault login -method=userpass username=$VAULT_USERNAME password=$VAULT_PASS - vault kv get -field=secret gcp/gcr-sa-key > /tmp/gcr_key.json; @@ -80,6 +101,7 @@ jobs: - gcloud auth configure-docker - make docker-build - make docker-push + addons: snaps: - name: google-cloud-sdk @@ -89,8 +111,10 @@ jobs: update: true packages: - docker-ce + - stage: test name: http-job-test + script: - GO111MODULE=on make build - mkdir -p build/linux/amd64 diff --git a/Makefile b/Makefile index 9ad35e269..7ef7c0b66 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ deps: .ensure-shfmt .ensure-golangci-lint .deps-fetched .PHONY: .ensure-golangci-lint .ensure-golangci-lint: - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(HOME)/bin v1.23.6 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(HOME)/bin if ! command -v $(go env GOPATH)/bin/golangci-lint &>/dev/null; then \ $(HOME)/bin/golangci-lint --version; \ fi diff --git a/backend/gce.go b/backend/gce.go index 2d80c66ed..faafe93b7 100644 --- a/backend/gce.go +++ b/backend/gce.go @@ -119,7 +119,7 @@ var ( "UPLOAD_RETRY_SLEEP": fmt.Sprintf("sleep interval between script upload attempts (default %v)", defaultGCEUploadRetrySleep), "WARMER_URL": "URL for warmer service", "WARMER_TIMEOUT": fmt.Sprintf("timeout for requests to warmer service (default %v)", defaultGCEWarmerTimeout), - "WARMER_SSH_PASSPHRASE": fmt.Sprintf("The passphrase used to decipher instace SSH keys"), + "WARMER_SSH_PASSPHRASE": "The passphrase used to decipher instace SSH keys", "ZONE": fmt.Sprintf("[DEPRECATED] Use ZONES instead. Zone name (default %q)", defaultGCEZone), "ZONES": fmt.Sprintf("comma-delimited list of zone names (default %q)", defaultGCEZone), } @@ -907,7 +907,7 @@ func buildGoogleComputeService(cfg *config.ProviderConfig) (*compute.Service, er if err != nil { return nil, errors.Wrap(err, "could not build default client") } - return compute.New(client) + return compute.New(client) //nolint:staticcheck } a, err := loadGoogleAccountJSON(cfg.Get("ACCOUNT_JSON")) @@ -931,7 +931,7 @@ func buildGoogleComputeService(cfg *config.ProviderConfig) (*compute.Service, er client.Transport = gceCustomHTTPTransport } - return compute.New(client) + return compute.New(client) //nolint:staticcheck } func loadGoogleAccountJSON(filenameOrJSON string) (*gceAccountJSON, error) { diff --git a/backend/lxd.go b/backend/lxd.go index dca195faa..3ad8557ac 100644 --- a/backend/lxd.go +++ b/backend/lxd.go @@ -52,14 +52,14 @@ var ( "CPUS": fmt.Sprintf("CPU count to allocate to each container (default %q)", lxdLimitCPU), "CPUS_BURST": fmt.Sprintf("allow using all CPUs when not in use (default %v)", lxdLimitCPUBurst), "NETWORK": fmt.Sprintf("network bandwidth (default %q)", lxdLimitNetwork), - "POOL": fmt.Sprintf("storage pool to use for the instances"), + "POOL": "storage pool to use for the instances", "DISK": fmt.Sprintf("disk size (default %q)", lxdLimitDisk), "PROCESS": fmt.Sprintf("maximum number of processes (default %q)", lxdLimitProcess), "IMAGE": fmt.Sprintf("image to use for the containers (default %q)", lxdImage), "IMAGE_AUTO_DOWNLOAD": fmt.Sprintf("automatically try to download lxc image if it's missing (default %v)", lxdImageAutoDownload), - "IMAGE_SERVER_URL": fmt.Sprintf("base URL for images auto download"), + "IMAGE_SERVER_URL": "base URL for images auto download", "IMAGE_SELECTOR_TYPE": fmt.Sprintf("image selector type (\"env\" or \"api\", default %q)", defaultLxdImageSelectorType), - "IMAGE_SELECTOR_URL": fmt.Sprintf("URL for image selector API, used only when image selector is \"api\""), + "IMAGE_SELECTOR_URL": "URL for image selector API, used only when image selector is \"api\"", "DOCKER_POOL": fmt.Sprintf("storage pool to use for Docker (default %q)", lxdDockerPool), "DOCKER_DISK": fmt.Sprintf("disk size to use for Docker (default %q)", lxdDockerDisk), "NETWORK_STATIC": fmt.Sprintf("whether to statically set network configuration (default %v)", lxdNetworkStatic), diff --git a/context/package.go b/context/package.go index 7eb4659ed..c8061f4c8 100644 --- a/context/package.go +++ b/context/package.go @@ -91,7 +91,7 @@ func WithTimings(ctx context.Context) context.Context { func TimeSince(ctx context.Context, name string, since time.Time) { if timings, ok := ctx.Value(timingsKey).(map[string]time.Duration); ok { elapsed := time.Since(since) - if _, ok := timings[name]; ok { + if _, ok := timings[name]; ok { //nolint:gosimple timings[name] += elapsed } else { timings[name] = elapsed diff --git a/script/list-packages b/script/list-packages index 2ebcb2b80..535547f03 100755 --- a/script/list-packages +++ b/script/list-packages @@ -5,7 +5,7 @@ main() { cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" find . -maxdepth 1 -type d | grep -v '^\.$' | sed 's@./@@' | while read -r pkg; do - if [[ "x$(bash -c "shopt -s nullglob; echo ${pkg}/*.go")" == "x" ]]; then + if [[ "_$(bash -c "shopt -s nullglob; echo ${pkg}/*.go")" == "_" ]]; then continue fi echo "github.com/travis-ci/worker/${pkg}"