Skip to content

Commit 42eb070

Browse files
committed
circleci: fix cache tools
1 parent 9df92e5 commit 42eb070

File tree

2 files changed

+81
-75
lines changed

2 files changed

+81
-75
lines changed

.circleci/config.yml

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,49 @@ orbs:
44
golang: cci-orb/golang@volatile
55
codecov: codecov/[email protected]
66

7+
executors:
8+
golang:
9+
docker:
10+
- image: golang:1.15-buster
11+
auth:
12+
username: $DOCKERHUB_USER
13+
password: $DOCKERHUB_PASSWORD
14+
working_directory: /go/src/go.lsp.dev/protocol
15+
716
command_vars:
8-
- cache_key: &cache_key gomod-<< parameters.go-version >>-{{ checksum "go.mod" }}-{{ checksum "go.sum" }}
9-
- cache_tools_key: &cache_tools_key tools-<< parameters.go-version >>-{{ checksum "tools/go.mod" }}-{{ checksum "tools/go.sum" }}
17+
- cache_key: &cache_key go-mod-v1-{{ checksum "go.mod" }}-{{ checksum "go.sum" }}
18+
- cache_tools_key: &cache_tools_key go-tools-v1-{{ checksum "tools/go.mod" }}-{{ checksum "tools/go.sum" }}
1019

1120
commands:
1221
restore_dependencies:
13-
parameters:
14-
go-version:
15-
type: string
1622
steps:
17-
- restore_cache:
18-
name: "Restore module dependencies cache"
19-
keys:
20-
- *cache_key
2123
- restore_cache:
2224
name: "Restore dependencies tools"
2325
keys:
2426
- *cache_tools_key
25-
- run:
26-
name: "Download project modules"
27-
command: |
28-
go mod download
2927

3028
save_dependencies:
31-
parameters:
32-
go-version:
33-
type: string
3429
steps:
35-
- save_cache:
36-
name: "Save module cache"
37-
key: *cache_key
38-
paths:
39-
- /go/pkg/mod/cache
4030
- save_cache:
4131
name: "Save dependencies tools"
4232
key: *cache_tools_key
4333
paths:
44-
- /go/bin/
34+
- /go/src/go.lsp.dev/protocol/tools/bin/
35+
- persist_to_workspace:
36+
name: "Persist dependencies tools"
37+
root: "/go"
38+
paths:
39+
- src/go.lsp.dev/protocol/tools/bin
40+
41+
install_tools:
42+
steps:
4543
- run:
46-
name: "go mod vendor"
44+
name: "Download dependency tools"
4745
command: |
48-
go mod vendor
46+
find /go/bin/ -mindepth 1 -type f -executable | head -1
47+
if [ -z $(find ./tools/bin/ -mindepth 1 -type f -executable | head -1) ]; then
48+
make -j${CPUS} tools
49+
fi
4950
5051
setup:
5152
steps:
@@ -55,48 +56,50 @@ commands:
5556
command: |
5657
go version
5758
go env
59+
- restore_cache:
60+
name: "Restore module cache"
61+
keys:
62+
- *cache_key
63+
- run:
64+
name: "Download modules"
65+
command: |
66+
go mod download
67+
- run:
68+
name: "Run go mod vendor"
69+
command: |
70+
go mod vendor
5871
- run:
5972
name: "Parse CPUs"
6073
command: |
6174
# https://circleci.com/changelog#container-cgroup-limits-now-visible-inside-the-docker-executor
6275
CPUS="$(echo $(($(cat /sys/fs/cgroup/cpu/cpu.shares) / 1024)))"
6376
echo "export CPUS=${CPUS}" >> $BASH_ENV
6477
65-
install_tools:
66-
steps:
67-
- run:
68-
name: "Download project tool dependencies"
69-
command: |
70-
if [ -z $(find /go/bin/ -mindepth 1 -type f -executable | head -1) ]; then
71-
make -j${CPUS} tools GOBIN=/go/bin
72-
fi
73-
7478
set_goflags:
7579
steps:
7680
- run:
77-
name: "Parse CPUs"
81+
name: "Set GOFLAGS"
7882
command: |
7983
echo "export GOFLAGS='-p=${CPUS} -cpu=${CPUS}'" >> $BASH_ENV
8084
8185
jobs:
86+
tools:
87+
executor: golang
88+
resource_class: large
89+
steps:
90+
- checkout
91+
- restore_dependencies
92+
- install_tools
93+
- save_dependencies
94+
8295
test:
83-
parameters:
84-
go-version:
85-
type: string
86-
docker:
87-
- image: golang:<< parameters.go-version >>
88-
auth:
89-
username: $DOCKERHUB_USER
90-
password: $DOCKERHUB_PASSWORD
91-
working_directory: /go/src/go.lsp.dev/protocol
96+
executor: golang
9297
resource_class: xlarge
9398
parallelism: 2
9499
steps:
95-
- restore_dependencies:
96-
go-version: << parameters.go-version >>
97-
- install_tools
98-
- save_dependencies:
99-
go-version: << parameters.go-version >>
100+
- attach_workspace:
101+
name: "Attach tools"
102+
at: "/go"
100103
- set_goflags
101104
- run:
102105
name: Test and take a coverage
@@ -107,43 +110,45 @@ jobs:
107110
command: |
108111
mkdir -p /tmp/test-results
109112
make $(circleci tests split .circleci/coverage-targets)
113+
- save_cache:
114+
name: "Save module cache"
115+
key: *cache_key
116+
paths:
117+
- /go/pkg/mod/cache
110118
- codecov/upload:
111119
file: "coverage.out"
112120
when: on_success
113121

114122
lint:
115-
parameters:
116-
go-version:
117-
type: string
118-
docker:
119-
- image: golang:<< parameters.go-version >>
120-
auth:
121-
username: $DOCKERHUB_USER
122-
password: $DOCKERHUB_PASSWORD
123-
working_directory: /go/src/go.lsp.dev/protocol
123+
executor: golang
124124
resource_class: large
125125
parallelism: 2
126126
steps:
127-
- restore_dependencies:
128-
go-version: << parameters.go-version >>
129-
- install_tools
130-
- save_dependencies:
131-
go-version: << parameters.go-version >>
127+
- attach_workspace:
128+
name: "Attach tools"
129+
at: "/go"
132130
- run:
133131
name: Run fmt and lint for sources
134132
command: |
135133
make lint GO_LINT_FLAGS="$(circleci tests split .circleci/lint-buildtags)" JOBS=${CPUS}
136134
git add -N . && git diff --exit-code
135+
- save_cache:
136+
name: "Save module cache"
137+
key: *cache_key
138+
paths:
139+
- /go/pkg/mod/cache
137140

138141
workflows:
139142
version: 2
140143
workflows:
141144
jobs:
145+
- tools:
146+
context: org-global
147+
142148
- test:
143149
context: org-global
144-
matrix:
145-
parameters:
146-
go-version: ["1.15-buster", "1.16-rc-buster"]
150+
requires:
151+
- tools
147152
pre-steps:
148153
- setup
149154
post-steps:
@@ -154,8 +159,7 @@ workflows:
154159

155160
- lint:
156161
context: org-global
157-
matrix:
158-
parameters:
159-
go-version: ["1.15-buster"]
162+
requires:
163+
- tools
160164
pre-steps:
161165
- setup

Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ tools/%: ## install an individual dependent tool
102102
@${MAKE} tools/bin/$* 1>/dev/null
103103

104104
tools/bin/%: ${TOOLS_DIR}/go.mod ${TOOLS_DIR}/go.sum
105-
@cd tools; \
106-
for t in ${TOOLS}; do \
107-
if [ -z '$*' ] || [ $$(basename $$t) = '$*' ]; then \
108-
echo "Install $$t ..." >&2; \
109-
GOBIN=${TOOLS_BIN} CGO_ENABLED=0 go install -v -mod=mod ${GO_FLAGS} "$${t}"; \
110-
fi \
111-
done
105+
@if [ -z '${CI}' ]; then \
106+
cd tools; \
107+
for t in ${TOOLS}; do \
108+
if [ -z '$*' ] || [ $$(basename $$t) = '$*' ]; then \
109+
echo "Install $$t ..." >&2; \
110+
GOBIN=${TOOLS_BIN} CGO_ENABLED=0 go install -v -mod=mod ${GO_FLAGS} "$${t}"; \
111+
fi \
112+
done \
113+
fi
112114

113115

114116
##@ clean

0 commit comments

Comments
 (0)