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