diff --git a/.circleci/config.yml b/.circleci/config.yml index 097c9a47b..909118190 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,51 +37,62 @@ commands: default: "gotestsum" cache_version: type: string - default: "v3" + default: "v1" steps: - - checkout - check-changed-files-or-halt + - restore_cache: + name: "Restore binaries from cache" + key: << parameters.os >>-<< parameters.arch >>-go-bin-<< parameters.cache_version >>-{{ checksum "go.sum" }} - when: condition: equal: [ linux, << parameters.os >> ] steps: - - restore_cache: - key: linux-go-<< parameters.cache_version >>-{{ checksum "go.sum" }} - attach_workspace: at: '/go' - when: condition: equal: [ darwin, << parameters.os >> ] steps: - - restore_cache: - key: darwin-go-<< parameters.cache_version >>-{{ checksum "go.sum" }} - run: 'sh ./scripts/installgo_mac.sh' - when: condition: equal: [ windows, << parameters.os >> ] steps: - - run: rm -rf /c/Go - run: choco feature enable -n allowGlobalConfirmation - - restore_cache: - key: windows-go-<< parameters.cache_version >>-{{ checksum "go.sum" }} - run: 'sh ./scripts/installgo_windows.sh' - run: choco install mingw + - run: go env - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2 - when: condition: equal: [ linux, << parameters.os >> ] steps: - - run: GOGC=20 /go/bin/golangci-lint run --verbose + - run: + name: golangci-lint cache status + command: GOGC=20 /go/bin/golangci-lint cache status + - run: + name: golangci-lint run + command: GOGC=20 /go/bin/golangci-lint run --verbose - when: condition: equal: [ darwin, << parameters.os >> ] steps: - - run: $HOME/go/bin/golangci-lint run --verbose + - run: + name: golangci-lint cache status + command: $HOME/go/bin/golangci-lint cache status + - run: + name: golangci-lint run + command: $HOME/go/bin/golangci-lint run --verbose - when: condition: equal: [ windows, << parameters.os >> ] steps: - - run: $HOME/go/bin/golangci-lint.exe run --verbose + - run: + name: golangci-lint cache status + command: $HOME/go/bin/golangci-lint.exe cache status + - run: + name: golangci-lint run + command: $HOME/go/bin/golangci-lint.exe run --verbose - run: ./scripts/install_gotestsum.sh << parameters.os >> << parameters.gotestsum >> - unless: condition: @@ -111,19 +122,19 @@ commands: equal: [ linux, << parameters.os >> ] steps: - save_cache: - name: 'Saving cache' - key: linux-go-<< parameters.cache_version >>-{{ checksum "go.sum" }} + name: 'Saving binaries to cache' + key: << parameters.os >>-<< parameters.arch >>-go-bin-<< parameters.cache_version >>-{{ checksum "go.sum" }} paths: - - '~/go/src/github.com/influxdata/telegraf/gotestsum' + - '/go/src/github.com/influxdata/telegraf/gotestsum' - when: condition: equal: [ darwin, << parameters.os >> ] steps: - save_cache: - name: 'Saving cache' - key: darwin-go-<< parameters.cache_version >>-{{ checksum "go.sum" }} + name: 'Saving binaries to cache' + key: << parameters.os >>-<< parameters.arch >>-go-bin-<< parameters.cache_version >>-{{ checksum "go.sum" }} paths: - - '/go/src/github.com/influxdata/telegraf/gotestsum' + - '~/go/src/github.com/influxdata/telegraf/gotestsum' - '/usr/local/Cellar/go' - '/usr/local/bin/go' - '/usr/local/bin/gofmt' @@ -132,11 +143,11 @@ commands: equal: [ windows, << parameters.os >> ] steps: - save_cache: - name: 'Saving cache' - key: windows-go-<< parameters.cache_version >>-{{ checksum "go.sum" }} + name: 'Saving binaries to cache' + key: << parameters.os >>-<< parameters.arch >>-go-bin-<< parameters.cache_version >>-{{ checksum "go.sum" }} paths: - - 'C:\Go' - - 'C:\Users\circleci\project\gotestsum.exe' + - '~\project\gotestsum.exe' + - 'C:\Program Files\Go' package-build: parameters: type: @@ -176,13 +187,15 @@ commands: root: './build' paths: - 'dist' + jobs: test-go-linux: executor: telegraf-ci steps: - checkout - restore_cache: - key: go-mod-v1-{{ checksum "go.sum" }} + name: "Restore Go caches" + key: linux-amd64-go-cache-v1-{{ checksum "go.sum" }} - check-changed-files-or-halt - run: ./scripts/make_docs.sh - run: 'make deps' @@ -191,10 +204,12 @@ jobs: - run: 'make check-deps' - test-go - save_cache: - name: 'go module cache' - key: go-mod-v1-{{ checksum "go.sum" }} + name: "Save Go caches" + key: linux-amd64-go-cache-v1-{{ checksum "go.sum" }} paths: - '/go/pkg/mod' + - '~/.cache/golangci-lint' + - '~/.cache/go-build' - persist_to_workspace: root: '/go' paths: @@ -204,13 +219,21 @@ jobs: steps: - checkout - restore_cache: - key: go-mod-v1-{{ checksum "go.sum" }} + name: "Restore Go caches" + key: linux-386-go-cache-v1-{{ checksum "go.sum" }} - check-changed-files-or-halt - run: 'GOARCH=386 make deps' - run: 'GOARCH=386 make tidy' - run: 'GOARCH=386 make check' - test-go: arch: "386" + - save_cache: + name: "Save Go caches" + key: linux-386-go-cache-v1-{{ checksum "go.sum" }} + paths: + - '/go/pkg/mod' + - '~/.cache/golangci-lint' + - '~/.cache/go-build' test-integration: machine: image: ubuntu-2204:current @@ -224,32 +247,57 @@ jobs: test-go-mac: executor: mac steps: + - checkout + - restore_cache: + name: "Restore Go caches" + key: darwin-amd64-go-cache-v1-{{ checksum "go.sum" }} - test-go: os: darwin + - save_cache: + name: "Save Go caches" + key: darwin-amd64-go-cache-v1-{{ checksum "go.sum" }} + paths: + - '~/go/pkg/mod' + - '~/Library/Caches/golangci-lint' + - '~/Library/Caches/go-build' test-go-windows: executor: name: win/default shell: bash.exe size: xlarge steps: + - checkout + - restore_cache: + name: "Restore Go caches" + key: windows-amd64-go-cache-v1-{{ checksum "go.sum" }} - test-go: os: windows gotestsum: "gotestsum.exe" + - save_cache: + name: "Save Go caches" + key: windows-amd64-go-cache-v1-{{ checksum "go.sum" }} + paths: + - '~\go\pkg\mod' + - '~\AppData\Local\golangci-lint' + - '~\AppData\Local\go-build' test-licenses: executor: telegraf-ci steps: - checkout - restore_cache: - key: go-mod-v1-{{ checksum "go.sum" }} + name: "Restore Go caches" + key: linux-amd64-go-cache-v1-{{ checksum "go.sum" }} - check-changed-files-or-halt - run: 'make build_tools' - run: './tools/license_checker/license_checker -whitelist ./tools/license_checker/data/whitelist' - save_cache: - name: 'go module cache' - key: go-mod-v1-{{ checksum "go.sum" }} + name: "Save Go caches" + key: linux-amd64-go-cache-v1-{{ checksum "go.sum" }} paths: - '/go/pkg/mod' + - '~/.cache/golangci-lint' + - '~/.cache/go-build' windows-package: parameters: diff --git a/scripts/installgo_windows.sh b/scripts/installgo_windows.sh index 3de5fd1fa..397de25cb 100644 --- a/scripts/installgo_windows.sh +++ b/scripts/installgo_windows.sh @@ -8,8 +8,6 @@ setup_go () { choco upgrade golang --allow-downgrade --version=${GO_VERSION} choco install make git config --system core.longpaths true - rm -rf /c/Go - cp -r /c/Program\ Files/Go /c/ } if command -v go >/dev/null 2>&1; then