Skip to content

Commit 419e66c

Browse files
Continue profile in group on error (#149)
* continue profile in group on error * split doc compilation and doc release * compile doc on PR * upgrade codecov action * checkout first * remove cache in doc * flag renamed continue-on-error * set continue-on-error to false can override global * add a test to make sure it works on all formats
1 parent c360880 commit 419e66c

File tree

12 files changed

+333
-30
lines changed

12 files changed

+333
-30
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ jobs:
2323

2424
steps:
2525

26+
- name: Check out code into the Go module directory
27+
uses: actions/checkout@v3
28+
2629
- name: Set up Go ${{ matrix.go_version }}
2730
uses: actions/setup-go@v3
2831
with:
2932
go-version: ${{ matrix.go_version }}
30-
31-
- name: Check out code into the Go module directory
32-
uses: actions/checkout@v3
33+
check-latest: true
34+
cache: true
3335

3436
- name: Generate mocks
3537
run: make mocks
@@ -44,7 +46,7 @@ jobs:
4446
shell: bash
4547

4648
- name: Code coverage with codecov
47-
uses: codecov/codecov-action@v2
49+
uses: codecov/codecov-action@v3
4850

4951
- name: Archive code coverage results
5052
uses: actions/upload-artifact@v3

.github/workflows/doc.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@ name: documentation
33
on:
44
push:
55
branches:
6-
- master # Set a branch to deploy
6+
- master
77
paths:
88
- "docs/**"
9+
10+
pull_request:
11+
types: [opened, synchronize, reopened]
12+
paths:
13+
- 'docs/**'
914

1015
jobs:
11-
deploy:
16+
build:
1217
runs-on: ubuntu-latest
1318
steps:
1419

15-
- name: Set up Go 1.19
16-
uses: actions/setup-go@v3
17-
with:
18-
go-version: 1.19
19-
2020
- uses: actions/checkout@v3
2121
with:
2222
submodules: true # Fetch Hugo themes (true OR recursive)
2323
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
2424

25+
- name: Set up Go 1.19
26+
uses: actions/setup-go@v3
27+
with:
28+
go-version: 1.19
29+
2530
- name: Check configuration snippets in documentation
2631
run: go run ./config/checkdoc -r docs/content
2732
shell: bash
@@ -34,11 +39,3 @@ jobs:
3439

3540
- name: Build
3641
run: cd docs && hugo --minify
37-
38-
- name: Deploy
39-
uses: peaceiris/actions-gh-pages@v3
40-
# if: github.ref == 'refs/heads/main'
41-
with:
42-
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
publish_branch: gh-docs
44-
publish_dir: ./public

.github/workflows/release-doc.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: documentation
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- name: Set up Go 1.19
14+
uses: actions/setup-go@v3
15+
with:
16+
go-version: 1.19
17+
18+
- uses: actions/checkout@v3
19+
with:
20+
submodules: true # Fetch Hugo themes (true OR recursive)
21+
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
22+
23+
- name: Check configuration snippets in documentation
24+
run: go run ./config/checkdoc -r docs/content
25+
shell: bash
26+
27+
- name: Setup Hugo
28+
uses: peaceiris/actions-hugo@v2
29+
with:
30+
hugo-version: 'latest'
31+
extended: true
32+
33+
- name: Build
34+
run: cd docs && hugo --minify
35+
36+
- name: Deploy
37+
uses: peaceiris/actions-gh-pages@v3
38+
# if: github.ref == 'refs/heads/main'
39+
with:
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
publish_branch: gh-docs
42+
publish_dir: ./public

bools/bools.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package bools
2+
3+
func IsTrue(value *bool) bool {
4+
if value == nil {
5+
return false
6+
}
7+
return *value
8+
}
9+
10+
func IsStrictlyFalse(value *bool) bool {
11+
if value == nil {
12+
return false
13+
}
14+
return !*value
15+
}
16+
17+
func IsFalseOrUndefined(value *bool) bool {
18+
if value == nil {
19+
return true
20+
}
21+
return !*value
22+
}
23+
24+
func IsUndefined(value *bool) bool {
25+
return value == nil
26+
}
27+
28+
func IsTrueOrUndefined(value *bool) bool {
29+
if value == nil {
30+
return true
31+
}
32+
return *value
33+
}

bools/bools_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package bools
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestBools(t *testing.T) {
11+
fixtures := []struct {
12+
source *bool
13+
isTrue bool
14+
isStrictlyFalse bool
15+
isFalseOrUndefined bool
16+
isUndefined bool
17+
isTrueOrUndefined bool
18+
}{
19+
{
20+
source: nil,
21+
isTrue: false,
22+
isStrictlyFalse: false,
23+
isFalseOrUndefined: true,
24+
isUndefined: true,
25+
isTrueOrUndefined: true,
26+
},
27+
{
28+
source: boolPointer(true),
29+
isTrue: true,
30+
isStrictlyFalse: false,
31+
isFalseOrUndefined: false,
32+
isUndefined: false,
33+
isTrueOrUndefined: true,
34+
},
35+
{
36+
source: boolPointer(false),
37+
isTrue: false,
38+
isStrictlyFalse: true,
39+
isFalseOrUndefined: true,
40+
isUndefined: false,
41+
isTrueOrUndefined: false,
42+
},
43+
}
44+
45+
for _, fixture := range fixtures {
46+
t.Run(toString(fixture.source), func(t *testing.T) {
47+
assert.Equal(t, fixture.isTrue, IsTrue(fixture.source))
48+
assert.Equal(t, fixture.isStrictlyFalse, IsStrictlyFalse(fixture.source))
49+
assert.Equal(t, fixture.isFalseOrUndefined, IsFalseOrUndefined(fixture.source))
50+
assert.Equal(t, fixture.isUndefined, IsUndefined(fixture.source))
51+
assert.Equal(t, fixture.isTrueOrUndefined, IsTrueOrUndefined(fixture.source))
52+
})
53+
}
54+
}
55+
56+
func boolPointer(value bool) *bool {
57+
output := &value
58+
return output
59+
}
60+
61+
func toString(value *bool) string {
62+
if value == nil {
63+
return "<nil>"
64+
}
65+
return strconv.FormatBool(*value)
66+
}

config/config_test.go

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,157 @@ profile:
197197
}
198198
}
199199

200+
func TestBoolPointer(t *testing.T) {
201+
boolPointer := func(value bool) *bool {
202+
output := &value
203+
return output
204+
}
205+
206+
fixtures := []struct {
207+
testTemplate
208+
continueOnError *bool
209+
}{
210+
{
211+
testTemplate: testTemplate{
212+
format: FormatTOML,
213+
config: `
214+
version = 2
215+
[groups]
216+
[groups.groupname]
217+
profiles = []
218+
`,
219+
},
220+
continueOnError: nil,
221+
},
222+
{
223+
testTemplate: testTemplate{
224+
format: FormatYAML,
225+
config: `
226+
version: 2
227+
groups:
228+
groupname:
229+
profiles: []
230+
`,
231+
},
232+
continueOnError: nil,
233+
},
234+
{
235+
testTemplate: testTemplate{
236+
format: FormatJSON,
237+
config: `
238+
{
239+
"version": 2,
240+
"groups": {
241+
"groupname":{
242+
"profiles": []
243+
}
244+
}
245+
}
246+
`,
247+
},
248+
continueOnError: nil,
249+
},
250+
{
251+
testTemplate: testTemplate{
252+
format: FormatTOML,
253+
config: `
254+
version = 2
255+
[groups]
256+
[groups.groupname]
257+
profiles = []
258+
continue-on-error = true
259+
`,
260+
},
261+
continueOnError: boolPointer(true),
262+
},
263+
{
264+
testTemplate: testTemplate{
265+
format: FormatYAML,
266+
config: `
267+
version: 2
268+
groups:
269+
groupname:
270+
profiles: []
271+
continue-on-error: true
272+
`,
273+
},
274+
continueOnError: boolPointer(true),
275+
},
276+
{
277+
testTemplate: testTemplate{
278+
format: FormatJSON,
279+
config: `
280+
{
281+
"version": 2,
282+
"groups": {
283+
"groupname":{
284+
"profiles": [],
285+
"continue-on-error": true
286+
}
287+
}
288+
}
289+
`,
290+
},
291+
continueOnError: boolPointer(true),
292+
},
293+
{
294+
testTemplate: testTemplate{
295+
format: FormatTOML,
296+
config: `
297+
version = 2
298+
[groups]
299+
[groups.groupname]
300+
profiles = []
301+
continue-on-error = false
302+
`,
303+
},
304+
continueOnError: boolPointer(false),
305+
},
306+
{
307+
testTemplate: testTemplate{
308+
format: FormatYAML,
309+
config: `
310+
version: 2
311+
groups:
312+
groupname:
313+
profiles: []
314+
continue-on-error: false
315+
`,
316+
},
317+
continueOnError: boolPointer(false),
318+
},
319+
{
320+
testTemplate: testTemplate{
321+
format: FormatJSON,
322+
config: `
323+
{
324+
"version": 2,
325+
"groups": {
326+
"groupname":{
327+
"profiles": [],
328+
"continue-on-error": false
329+
}
330+
}
331+
}
332+
`,
333+
},
334+
continueOnError: boolPointer(false),
335+
},
336+
}
337+
338+
for _, fixture := range fixtures {
339+
t.Run(fixture.format, func(t *testing.T) {
340+
c, err := Load(bytes.NewBufferString(fixture.config), fixture.format)
341+
require.NoError(t, err)
342+
343+
group, err := c.GetProfileGroup("groupname")
344+
require.NoError(t, err)
345+
346+
assert.Equal(t, fixture.continueOnError, group.ContinueOnError)
347+
})
348+
}
349+
}
350+
200351
func TestGetIncludes(t *testing.T) {
201352
config, err := Load(bytes.NewBufferString(`includes=["i1", "i2"]`), "toml")
202353
require.NoError(t, err)

0 commit comments

Comments
 (0)