1
1
version : 2.1
2
2
3
+ orbs :
4
+
5
+
3
6
references :
4
- images :
5
- go : &GOLANG_IMAGE circleci/golang:latest
6
- environments :
7
- tmp : &TEST_RESULTS_PATH /tmp/test-results # path to where test results are saved
8
-
9
- # reusable 'executor' object for jobs
10
- executors :
11
- go :
12
- docker :
13
- - image : *GOLANG_IMAGE
14
- environment :
15
- - TEST_RESULTS : *TEST_RESULTS_PATH
7
+ environment : &ENVIRONMENT
8
+ TEST_RESULTS_PATH : &TEST_RESULTS_PATH /tmp/test-results
9
+ WIN_TEST_RESULTS : &WIN_TEST_RESULTS c:\Users\circleci\AppData\Local\Temp\test-results
16
10
11
+ commands :
12
+ run-gotests :
13
+ parameters :
14
+ cmd :
15
+ type : string
16
+ platform :
17
+ type : string
18
+ steps :
19
+ - run :
20
+ name : " Run go tests"
21
+ command : |
22
+ PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
23
+ echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
24
+ echo $PACKAGE_NAMES
25
+ << parameters.cmd >> --format=short-verbose --junitfile $TEST_RESULTS_PATH/go-getter/gotestsum-report.xml -- -p 2 -cover -coverprofile=<< parameters.platform >>_cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
26
+
17
27
jobs :
18
- go-fmt-and-test :
19
- executor : go
28
+ linux-tests :
29
+ docker :
30
+ - image : circleci/golang:<< parameters.go-version >>
31
+ parameters :
32
+ go-version :
33
+ type : string
34
+ environment :
35
+ << : *ENVIRONMENT
36
+ parallelism : 4
20
37
steps :
38
+ - run : go version
21
39
- checkout
22
- - run : mkdir -p $TEST_RESULTS
40
+ - attach_workspace :
41
+ at : .
42
+ - run : mkdir -p $TEST_RESULTS_PATH/go-getter
23
43
24
44
# Restore go module cache if there is one
25
45
- restore_cache :
26
46
keys :
27
- - go-getter-modcache -v1-{{ checksum "go.mod" }}
47
+ - linux-gomod-cache -v1-{{ checksum "go.mod" }}
28
48
29
49
- run : go mod download
30
50
31
51
# Save go module cache if the go.mod file has changed
32
52
- save_cache :
33
- key : go-getter-modcache -v1-{{ checksum "go.mod" }}
53
+ key : linux-gomod-cache -v1-{{ checksum "go.mod" }}
34
54
paths :
35
55
- " /go/pkg/mod"
36
56
37
- # check go fmt output because it does not report non-zero when there are fmt changes
57
+ # Check go fmt output because it does not report non-zero when there are fmt changes
38
58
- run :
39
59
name : check go fmt
40
60
command : |
@@ -45,17 +65,106 @@ jobs:
45
65
exit 1
46
66
fi
47
67
48
- # run go tests with gotestsum
49
- - run : |
50
- PACKAGE_NAMES=$(go list ./...)
51
- gotestsum --format=short-verbose --junitfile $TEST_RESULTS/gotestsum-report.xml -- $PACKAGE_NAMES
68
+ # Run go tests with gotestsum
69
+ - run-gotests :
70
+ cmd : " gotestsum"
71
+ platform : " linux"
72
+
73
+ # Save coverage report parts
74
+ - persist_to_workspace :
75
+ root : .
76
+ paths :
77
+ - linux_cov_*.part
78
+
52
79
- store_test_results :
53
80
path : *TEST_RESULTS_PATH
54
81
- store_artifacts :
55
82
path : *TEST_RESULTS_PATH
56
83
84
+ windows-tests :
85
+ executor :
86
+ name : win/default
87
+ shell : bash --login -eo pipefail
88
+ environment :
89
+ << : *ENVIRONMENT
90
+ working_directory : c:\gopath\src\github.com\hashicorp\go-getter
91
+ parameters :
92
+ go-version :
93
+ type : string
94
+ gotestsum-version :
95
+ type : string
96
+ steps :
97
+ - run : git config --global core.autocrlf false
98
+ - checkout
99
+ - attach_workspace :
100
+ at : .
101
+ - run :
102
+ name : Setup (remove pre-installed go)
103
+ command : |
104
+ rm -rf "c:\Go"
105
+ mkdir -p $TEST_RESULTS_PATH/go-getter
106
+
107
+ - restore_cache :
108
+ keys :
109
+ - win-golang-<< parameters.go-version >>-cache-v1
110
+ - win-gomod-cache-{{ checksum "go.mod" }}-v1
111
+
112
+ - run :
113
+ name : Install go version << parameters.go-version >>
114
+ command : |
115
+ if [ ! -d "c:\go" ]; then
116
+ echo "Cache not found, installing new version of go"
117
+ curl --fail --location https://dl.google.com/go/go<< parameters.go-version >>.windows-amd64.zip --output go.zip
118
+ unzip go.zip -d "/c"
119
+ fi
120
+
121
+ - run :
122
+ command : go mod download
123
+
124
+ - save_cache :
125
+ key : win-golang-<< parameters.go-version >>-cache-v1
126
+ paths :
127
+ - /go
128
+
129
+ - save_cache :
130
+ key : win-gomod-cache-{{ checksum "go.mod" }}-v1
131
+ paths :
132
+ - c:\Windows\system32\config\systemprofile\go\pkg\mod
133
+
134
+ - run :
135
+ name : Install gotestsum
136
+ command : |
137
+ curl --fail --location https://github.com/gotestyourself/gotestsum/releases/download/v<< parameters.gotestsum-version >>/gotestsum_<< parameters.gotestsum-version >>_windows_amd64.tar.gz --output gotestsum.tar.gz
138
+ tar -xvzf gotestsum.tar.gz
139
+
140
+ - run-gotests :
141
+ cmd : " ./gotestsum.exe"
142
+ platform : " win"
143
+
144
+ # Save coverage report parts
145
+ - persist_to_workspace :
146
+ root : .
147
+ paths :
148
+ - win_cov_*.part
149
+
150
+ - store_test_results :
151
+ path : *WIN_TEST_RESULTS
152
+ - store_artifacts :
153
+ path : *WIN_TEST_RESULTS
154
+
57
155
workflows :
58
- version : 2
59
- test-and-build :
156
+ go-getter :
60
157
jobs :
61
- - go-fmt-and-test
158
+ - linux-tests :
159
+ context : go-getter
160
+ matrix :
161
+ parameters :
162
+ go-version : ["1.14.1"]
163
+ name : linux-test-go-<< matrix.go-version >>
164
+ - windows-tests :
165
+ context : go-getter
166
+ matrix :
167
+ parameters :
168
+ go-version : ["1.14.1"]
169
+ gotestsum-version : ["0.4.1"]
170
+ name : win-test-go-<< matrix.go-version >>
0 commit comments