Skip to content

Commit cb869d9

Browse files
authored
Merge pull request #49 from hashicorp/fix-ci-config
Fix CI config
2 parents 7795f06 + af59c66 commit cb869d9

File tree

3 files changed

+165
-56
lines changed

3 files changed

+165
-56
lines changed

.circleci/config.yml

Lines changed: 158 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,164 @@
1-
version: 2.1
1+
version: 2.1
2+
3+
orbs:
4+
win: circleci/windows@2.2.0
25

36
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
1610

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+
1727
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
54150

55151
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 >>

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# go-multierror
22

3-
[![Build Status](http://img.shields.io/travis/hashicorp/go-multierror.svg?style=flat-square)][travis]
4-
[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
3+
[![CircleCI](https://img.shields.io/circleci/build/github/hashicorp/go-multierror/master)](https://circleci.com/gh/hashicorp/go-multierror)
4+
[![Go Reference](https://pkg.go.dev/badge/github.com/hashicorp/go-multierror.svg)](https://pkg.go.dev/github.com/hashicorp/go-multierror)
5+
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/hashicorp/go-multierror)
56

6-
[travis]: https://travis-ci.org/hashicorp/go-multierror
7+
[circleci]: https://app.circleci.com/pipelines/github/hashicorp/go-multierror
78
[godocs]: https://pkg.go.dev/github.com/hashicorp/go-multierror
89

910
`go-multierror` is a package for Go that provides a mechanism for

prefix_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func TestPrefix_NilError(t *testing.T) {
2727
func TestPrefix_NonError(t *testing.T) {
2828
original := errors.New("foo")
2929
result := Prefix(original, "bar")
30+
if result == nil {
31+
t.Fatal("error result was nil")
32+
}
3033
if result.Error() != "bar foo" {
3134
t.Fatalf("bad: %s", result)
3235
}

0 commit comments

Comments
 (0)