...
1version: 2.1
2
3orbs:
4 win: circleci/windows@2.2.0
5
6references:
7 environment: &ENVIRONMENT
8 GOMAXPROCS: 4
9 GO111MODULE: "on"
10 GOPROXY: https://proxy.golang.org/
11 TEST_RESULTS_DIR: &TEST_RESULTS_DIR /tmp/test-results
12 WIN_TEST_RESULTS: &WIN_TEST_RESULTS c:\Users\circleci\AppData\Local\Temp\test-results
13
14commands:
15 git-verify:
16 steps:
17 - run:
18 name: "Verify no code was generated"
19 command: |
20 if [[ -z $(git status --porcelain) ]]; then
21 echo "Git directory is clean."
22 else
23 echo "Git is dirty. Run `make fmt` and `make generate` locally and commit any formatting fixes or generated code."
24 git status --porcelain
25 exit 1
26 fi
27
28 run-gotests:
29 parameters:
30 cmd:
31 type: string
32 platform:
33 type: string
34 steps:
35 - run:
36 name: "Run go tests"
37 command: |
38 PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
39 echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
40 echo $PACKAGE_NAMES
41 << parameters.cmd >> --format=short-verbose --junitfile $TEST_RESULTS_DIR/hcl2/gotestsum-report.xml -- -p 2 -cover -coverprofile=<< parameters.platform >>_cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
42
43jobs:
44 go-checks:
45 docker:
46 - image: circleci/golang:<< parameters.go-version >>
47 environment:
48 <<: *ENVIRONMENT
49 parameters:
50 go-version:
51 type: string
52 steps:
53 - checkout
54 - run: go mod verify
55 - run: make fmt
56 - git-verify
57
58 linux-tests:
59 docker:
60 - image: circleci/golang:<< parameters.go-version >>
61 environment:
62 <<: *ENVIRONMENT
63 parameters:
64 go-version:
65 type: string
66 parallelism: 4
67 steps:
68 - checkout
69 - attach_workspace:
70 at: .
71 - run: mkdir -p $TEST_RESULTS_DIR/hcl2
72 - run-gotests:
73 cmd: "gotestsum"
74 platform: "linux"
75
76 # save coverage report parts
77 - persist_to_workspace:
78 root: .
79 paths:
80 - linux_cov_*.part
81
82 - store_test_results:
83 path: *TEST_RESULTS_DIR
84 - store_artifacts:
85 path: *TEST_RESULTS_DIR
86
87 win-tests:
88 executor:
89 name: win/default
90 shell: bash --login -eo pipefail
91 environment:
92 <<: *ENVIRONMENT
93 working_directory: c:\gopath\src\github.com\hashicorp\hcl
94 parameters:
95 go-version:
96 type: string
97 gotestsum-version:
98 type: string
99 steps:
100 - add_ssh_keys:
101 fingerprints:
102 - "3f:fc:7c:7b:7f:45:55:70:d0:7a:6b:26:7f:0d:50:e9"
103 - run: git config --global core.autocrlf false
104 - checkout
105 - attach_workspace:
106 at: .
107 # - git-verify
108 - run:
109 name: Setup (remove pre-installed golang version)
110 command: |
111 rm -rf "c:\Go"
112 mkdir -p $TEST_RESULTS_DIR/hcl2
113 - restore_cache:
114 keys:
115 - win-golang-<< parameters.go-version >>-cache-v1
116 - win-gomod-cache-{{ checksum "go.mod" }}-v1
117
118 - run:
119 name: Install go version << parameters.go-version >>
120 command: |
121 if [ ! -d "c:\go" ]; then
122 echo "Cache not found, installing new version of go"
123 curl --fail --location https://dl.google.com/go/go<< parameters.go-version >>.windows-amd64.zip --output go.zip
124 unzip go.zip -d "/c"
125 fi
126 - run:
127 name: Go mod download
128 command: |
129 go mod verify
130 go mod download
131
132 - save_cache:
133 key: win-golang-<< parameters.go-version >>-cache-v1
134 paths:
135 - /go
136
137 - save_cache:
138 key: win-gomod-cache-{{ checksum "go.mod" }}-v1
139 paths:
140 - c:\Windows\system32\config\systemprofile\go\pkg\mod
141
142 - run:
143 name: Install gotestsum
144 command: |
145 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
146 tar -xvzf gotestsum.tar.gz
147 - run-gotests:
148 cmd: "./gotestsum.exe"
149 platform: "win"
150
151 # save coverage report parts
152 - persist_to_workspace:
153 root: .
154 paths:
155 - win_cov_*.part
156
157 - store_test_results:
158 path: *WIN_TEST_RESULTS
159 - store_artifacts:
160 path: *WIN_TEST_RESULTS
161
162workflows:
163 hcl2:
164 jobs:
165 # - go-checks:
166 # matrix:
167 # parameters:
168 # go-version: ["1.14"]
169 # name: go-checks-<< matrix.go-version >>
170 - linux-tests:
171 matrix:
172 parameters:
173 go-version: ["1.14"]
174 name: linux-test-go-<< matrix.go-version >>
175 - win-tests:
176 matrix:
177 parameters:
178 go-version: ["1.12"]
179 gotestsum-version: ["0.4.1"]
180 name: win-test-go-<< matrix.go-version >>
View as plain text