Skip to content

Commit 0a57493

Browse files
committed
fix circleci cache logic
1 parent f9fdbbd commit 0a57493

File tree

2 files changed

+89
-44
lines changed

2 files changed

+89
-44
lines changed

.circleci/config.yml

Lines changed: 89 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,78 @@ orbs:
44
golang: cci-orb/golang@volatile
55
codecov: codecov/[email protected]
66

7+
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" }}
10+
711
commands:
8-
parse_goflags:
12+
restore_dependencies:
13+
parameters:
14+
go-version:
15+
type: string
16+
steps:
17+
- restore_cache:
18+
name: "Restore module dependencies cache"
19+
keys:
20+
- *cache_key
21+
- restore_cache:
22+
name: "Restore dependencies tools"
23+
keys:
24+
- *cache_tools_key
25+
- run:
26+
name: "Download project modules"
27+
command: |
28+
go mod download
29+
30+
save_dependencies:
31+
parameters:
32+
go-version:
33+
type: string
34+
steps:
35+
- save_cache:
36+
name: "Save module cache"
37+
key: *cache_key
38+
paths:
39+
- /go/pkg/mod/cache
40+
- save_cache:
41+
name: "Save dependencies tools"
42+
key: *cache_tools_key
43+
paths:
44+
- /go/bin/
45+
- run:
46+
name: "go mod vendor"
47+
command: |
48+
go mod vendor
49+
50+
setup:
51+
steps:
52+
- checkout
53+
- run:
54+
name: Check versions
55+
command: |
56+
go version
57+
go env
58+
- run:
59+
name: "Parse CPUs"
60+
command: |
61+
# https://circleci.com/changelog#container-cgroup-limits-now-visible-inside-the-docker-executor
62+
CPUS="$(echo $(($(cat /sys/fs/cgroup/cpu/cpu.shares) / 1024)))"
63+
echo "export CPUS=${CPUS}" >> $BASH_ENV
64+
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+
74+
set_goflags:
975
steps:
1076
- run:
1177
name: "Parse CPUs"
1278
command: |
13-
CPUS="$(make env/JOBS)"
1479
echo "export GOFLAGS='-p=${CPUS} -cpu=${CPUS}'" >> $BASH_ENV
1580
1681
jobs:
@@ -26,47 +91,24 @@ jobs:
2691
working_directory: /go/src/go.lsp.dev/jsonrpc2
2792
resource_class: xlarge
2893
steps:
29-
- checkout
30-
- run:
31-
name: Check versions
32-
command: |
33-
go version
34-
go env
35-
- restore_cache:
36-
name: Restore Go modules cache
37-
key: 'gomod-<< parameters.go-version >>-{{ checksum "go.mod" }}-{{ checksum "go.sum" }}'
94+
- restore_dependencies:
95+
go-version: << parameters.go-version >>
96+
- install_tools
97+
- save_dependencies:
98+
go-version: << parameters.go-version >>
99+
- set_goflags
38100
- run:
39-
name: Download Go module dependencies
40-
command: |
41-
go mod download
42-
- save_cache:
43-
name: Save Go modules cache
44-
key: 'gomod-<< parameters.go-version >>-{{ checksum "go.mod" }}-{{ checksum "go.sum" }}'
45-
paths:
46-
- /go/pkg/mod/cache
47-
- run:
48-
name: Run go mod vendor
49-
command: |
50-
go mod vendor
51-
- parse_goflags
52-
- run:
53-
name: Test and collect coverages
101+
name: Test and take a coverage
54102
environment:
55-
# https://github.com/gotestyourself/gotestsum#format
56103
GOTESTSUM_FORMAT: standard-verbose
57-
# https://github.com/gotestyourself/gotestsum#junit-xml
58104
GOTESTSUM_JUNITFILE: /tmp/test-results/tests.xml
59-
# https://github.com/gotestyourself/gotestsum#finding-and-skipping-slow-tests
60105
GOTESTSUM_JSONFILE: /tmp/test-results/tests.json
61106
command: |
62107
mkdir -p /tmp/test-results
63108
make coverage
64109
- codecov/upload:
65110
file: "coverage.out"
66-
- store_test_results:
67-
path: /tmp/test-results
68-
- store_artifacts:
69-
path: /tmp/test-results
111+
when: on_success
70112

71113
lint:
72114
parameters:
@@ -80,13 +122,11 @@ jobs:
80122
working_directory: /go/src/go.lsp.dev/jsonrpc2
81123
resource_class: large
82124
steps:
83-
- checkout
84-
- golang/gomod
85-
- run:
86-
name: Check versions
87-
command: |
88-
go version
89-
go env
125+
- restore_dependencies:
126+
go-version: << parameters.go-version >>
127+
- install_tools
128+
- save_dependencies:
129+
go-version: << parameters.go-version >>
90130
- run:
91131
name: Run fmt and lint for sources
92132
command: |
@@ -102,9 +142,18 @@ workflows:
102142
matrix:
103143
parameters:
104144
go-version: ["1.15-buster", "1.16-rc-buster"]
145+
pre-steps:
146+
- setup
147+
post-steps:
148+
- store_test_results:
149+
path: /tmp/test-results
150+
- store_artifacts:
151+
path: /tmp/test-results
105152

106153
- lint:
107154
context: org-global
108155
matrix:
109156
parameters:
110157
go-version: ["1.15-buster"]
158+
pre-steps:
159+
- setup

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ TOOLS_BIN := ${CURDIR}/tools/bin
3434

3535
# Set build environment
3636
JOBS := $(shell getconf _NPROCESSORS_CONF)
37-
ifeq ($(CIRCLECI),true)
38-
# https://circleci.com/changelog#container-cgroup-limits-now-visible-inside-the-docker-executor
39-
JOBS := $(shell echo $$(($$(cat /sys/fs/cgroup/cpu/cpu.shares) / 1024)))
40-
endif
4137

4238
# -----------------------------------------------------------------------------
4339
# defines

0 commit comments

Comments
 (0)