Skip to content

Commit

Permalink
chore(tools): Cache rework for CircleCI (#14156)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Oct 24, 2023
1 parent 04480a5 commit 4413991
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 33 deletions.
79 changes: 55 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,34 @@ commands:
default: "gotestsum"
cache_version:
type: string
default: "v2"
default: "v1"
goversion:
type: string
default: 1.21.3
steps:
- check-changed-files-or-halt
- when:
condition:
equal: [ windows, << parameters.os >> ]
steps:
- run:
name: Remove Go and MinGW to avoid clashes after upgrade during cache restore
command: |
rm -rf '/c/Program Files/Go'
rm -rf '/c/ProgramData/chocolatey/lib/mingw'
- when:
condition:
equal: [ darwin, << parameters.os >> ]
steps:
- run:
name: Ensure go directory is empty and have proper permissions before cache restore
command: |
sudo rm -rf '/usr/local/Cellar/go'
sudo mkdir -p '/usr/local/Cellar/go'
sudo chown -R $(id -u):$(id -g) '/usr/local/Cellar/go'
- restore_cache:
name: "Restore binaries from cache"
key: << parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-bins-<< parameters.cache_version >>-<< parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-{{ checksum "go.sum" }}
- when:
condition:
equal: [ linux, << parameters.os >> ]
Expand All @@ -61,10 +80,11 @@ commands:
condition:
equal: [ windows, << parameters.os >> ]
steps:
- run: rm -rf '/c/Program Files/Go'
- run: choco feature enable -n allowGlobalConfirmation
- run: git config --system core.longpaths true
- run: 'sh ./scripts/installgo_windows.sh'
- run: choco install mingw --version=12.2.0.03042023
- run: 'sh ./scripts/installmingw_windows.sh'
- run: choco install make
- run: go env
- run: go install github.com/golangci/golangci-lint/cmd/[email protected]
- when:
Expand Down Expand Up @@ -103,8 +123,18 @@ commands:
equal: [ "386", << parameters.arch >> ]
steps:
- run: echo 'export RACE="-race"' >> $BASH_ENV
- run: |
GOARCH=<< parameters.arch >> ./<< parameters.gotestsum >> -- ${RACE} -short -cover -coverprofile=coverage.out ./...
- when:
condition:
equal: [ windows, << parameters.os >> ]
steps:
- run: |
export PATH="/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin:$PATH"
GOARCH=<< parameters.arch >> ./<< parameters.gotestsum >> -- ${RACE} -short -cover -coverprofile=coverage.out ./...
- unless:
condition:
equal: [ windows, << parameters.os >> ]
steps:
- run: GOARCH=<< parameters.arch >> ./<< parameters.gotestsum >> -- ${RACE} -short -cover -coverprofile=coverage.out ./...
- when:
condition:
and:
Expand All @@ -127,7 +157,7 @@ commands:
steps:
- save_cache:
name: 'Saving binaries to cache'
key: << parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-bins-<< parameters.cache_version >>-<< parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '/go/src/github.com/influxdata/telegraf/gotestsum'
- when:
Expand All @@ -136,7 +166,7 @@ commands:
steps:
- save_cache:
name: 'Saving binaries to cache'
key: << parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-bins-<< parameters.cache_version >>-<< parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '~/go/src/github.com/influxdata/telegraf/gotestsum'
- '/usr/local/Cellar/go'
Expand All @@ -148,10 +178,11 @@ commands:
steps:
- save_cache:
name: 'Saving binaries to cache'
key: << parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-bins-<< parameters.cache_version >>-<< parameters.os >>-<< parameters.arch >>-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '~\project\gotestsum.exe'
- 'C:\Program Files\Go'
- 'C:\ProgramData\chocolatey\lib\mingw'
package-build:
parameters:
type:
Expand Down Expand Up @@ -201,12 +232,12 @@ jobs:
default: 1.21.3
cache_version:
type: string
default: "v2"
default: "v1"
steps:
- checkout
- restore_cache:
name: "Restore Go caches"
key: linux-amd64-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-linux-amd64-go<< parameters.goversion >>-{{ checksum "go.sum" }}
- check-changed-files-or-halt
- run: ./scripts/make_docs.sh
- run: 'make deps'
Expand All @@ -216,7 +247,7 @@ jobs:
- test-go
- save_cache:
name: "Save Go caches"
key: linux-amd64-go<< parameters.goversion >>-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-linux-amd64-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '/go/pkg/mod'
- '~/.cache/golangci-lint'
Expand All @@ -233,12 +264,12 @@ jobs:
default: 1.21.3
cache_version:
type: string
default: "v2"
default: "v1"
steps:
- checkout
- restore_cache:
name: "Restore Go caches"
key: linux-386-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-linux-386-go<< parameters.goversion >>-{{ checksum "go.sum" }}
- check-changed-files-or-halt
- run: 'GOARCH=386 make deps'
- run: 'GOARCH=386 make tidy'
Expand All @@ -247,7 +278,7 @@ jobs:
arch: "386"
- save_cache:
name: "Save Go caches"
key: linux-386-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-linux-386-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '/go/pkg/mod'
- '~/.cache/golangci-lint'
Expand All @@ -270,18 +301,18 @@ jobs:
default: 1.21.3
cache_version:
type: string
default: "v2"
default: "v1"
steps:
- checkout
- restore_cache:
name: "Restore Go caches"
key: darwin-arm64-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-darwin-arm64-go<< parameters.goversion >>-{{ checksum "go.sum" }}
- test-go:
os: darwin
arch: arm64
- save_cache:
name: "Save Go caches"
key: darwin-arm64-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-darwin-arm64-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '~/go/pkg/mod'
- '~/Library/Caches/golangci-lint'
Expand All @@ -293,7 +324,7 @@ jobs:
default: 1.21.3
cache_version:
type: string
default: "v2"
default: "v1"
executor:
name: win/default
shell: bash.exe
Expand All @@ -302,13 +333,13 @@ jobs:
- checkout
- restore_cache:
name: "Restore Go caches"
key: windows-amd64-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-windows-amd64-go<< parameters.goversion >>-{{ checksum "go.sum" }}
- test-go:
os: windows
gotestsum: "gotestsum.exe"
- save_cache:
name: "Save Go caches"
key: windows-amd64-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-windows-amd64-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '~\go\pkg\mod'
- '~\AppData\Local\golangci-lint'
Expand All @@ -322,18 +353,18 @@ jobs:
default: 1.21.3
cache_version:
type: string
default: "v2"
default: "v1"
steps:
- checkout
- restore_cache:
name: "Restore Go caches"
key: linux-amd64-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-linux-amd64-go<< parameters.goversion >>-{{ 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: "Save Go caches"
key: linux-amd64-go<< parameters.goversion >>-cache-<< parameters.cache_version >>-{{ checksum "go.sum" }}
key: go-caches-<< parameters.cache_version >>-linux-amd64-go<< parameters.goversion >>-{{ checksum "go.sum" }}
paths:
- '/go/pkg/mod'
- '~/.cache/golangci-lint'
Expand Down
8 changes: 4 additions & 4 deletions scripts/installgo_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ setup_go () {

sudo rm -rfv /usr/local/go
sudo tar -C /usr/local -xzf go${GO_VERSION}.${GO_ARCH}.tar.gz

echo "$PATH"
which go
go version
}

if command -v go >/dev/null 2>&1; then
Expand All @@ -34,3 +30,7 @@ if command -v go >/dev/null 2>&1; then
else
setup_go
fi

echo "$PATH"
command -v go
go version
5 changes: 4 additions & 1 deletion scripts/installgo_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ if command -v go >/dev/null 2>&1; then
echo "$v is installed, required version is ${GO_VERSION}"
if [ "$v" != ${GO_VERSION} ]; then
setup_go
go version
fi
else
setup_go
fi

echo "$PATH"
command -v go
go version
9 changes: 5 additions & 4 deletions scripts/installgo_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ set -eux
GO_VERSION="1.21.3"

setup_go () {
rm -rf '/c/Program Files/Go'
choco upgrade golang --allow-downgrade --version=${GO_VERSION}
choco install make
choco upgrade golang --allow-downgrade --force --version=${GO_VERSION}
git config --system core.longpaths true
}

Expand All @@ -17,8 +15,11 @@ if command -v go >/dev/null 2>&1; then
echo "$v is installed, required version is ${GO_VERSION}"
if [ "$v" != ${GO_VERSION} ]; then
setup_go
go version
fi
else
setup_go
fi

echo "$PATH"
command -v go
go version
28 changes: 28 additions & 0 deletions scripts/installmingw_windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

set -eux

MINGW_VERSION="12.2.0.03042023"
GCC_VERSION="12.2.0"

setup_mingw () {
choco upgrade mingw --allow-downgrade --force --version=${MINGW_VERSION}
}

export PATH="/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin:$PATH"
echo "$PATH"

if command -v gcc >/dev/null 2>&1; then
echo "MinGW is already installed"
v=$(gcc -dumpversion)
echo "$v is installed, required version is ${GCC_VERSION}"
if [ "$v" != ${GCC_VERSION} ]; then
setup_mingw
fi
else
setup_mingw
fi

echo "$PATH"
command -v gcc
gcc -dumpversion

0 comments on commit 4413991

Please sign in to comment.