ci: migrate from Travis to GitHub Actions (#230)
* ci: migrate from Travis to GitHub Actions
* Setting up GOPATH
* Download dependencies
* Fix GOPATH
* Fix GOPATH
* Fix GOPATH
* Fix deps
* Damn it!
* ???
* Init Go mod
* Fix lint errors
* Fix failing tests on Windows
* Skip some tests on Windows
Co-authored-by: Sourcegraph Bot <campaigns@sourcegraph.com>
ᴜɴᴋɴᴡᴏɴ authored 4 years ago
GitHub committed 4 years ago
0 | name: Go | |
1 | on: | |
2 | push: | |
3 | branches: [master] | |
4 | pull_request: | |
5 | env: | |
6 | GOPROXY: "https://proxy.golang.org" | |
7 | ||
8 | jobs: | |
9 | lint: | |
10 | name: Lint | |
11 | runs-on: ubuntu-latest | |
12 | steps: | |
13 | - uses: actions/checkout@v2 | |
14 | - name: Init Go modules | |
15 | run: go mod init gopkg.in/ini.v1 | |
16 | - name: Run golangci-lint | |
17 | uses: actions-contrib/golangci-lint@v1 | |
18 | ||
19 | test: | |
20 | name: Test | |
21 | strategy: | |
22 | matrix: | |
23 | go-version: [1.13.x, 1.14.x] | |
24 | platform: [ubuntu-latest, macos-latest, windows-latest] | |
25 | runs-on: ${{ matrix.platform }} | |
26 | steps: | |
27 | - name: Install Go | |
28 | uses: actions/setup-go@v1 | |
29 | with: | |
30 | go-version: ${{ matrix.go-version }} | |
31 | - name: Checkout code | |
32 | uses: actions/checkout@v2 | |
33 | - name: Run unit tests | |
34 | run: | | |
35 | go mod init gopkg.in/ini.v1 | |
36 | go test -v -race -coverprofile=coverage -covermode=atomic ./... | |
37 | - name: Upload coverage report to Codecov | |
38 | uses: codecov/codecov-action@v1.0.6 | |
39 | with: | |
40 | file: ./coverage | |
41 | flags: unittests | |
42 | - name: Cache downloaded modules | |
43 | uses: actions/cache@v1 | |
44 | with: | |
45 | path: ~/go/pkg/mod | |
46 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
47 | restore-keys: | | |
48 | ${{ runner.os }}-go- |
0 | language: go | |
1 | os: linux | |
2 | dist: xenial | |
3 | go: | |
4 | - 1.6.x | |
5 | - 1.7.x | |
6 | - 1.8.x | |
7 | - 1.9.x | |
8 | - 1.10.x | |
9 | - 1.11.x | |
10 | - 1.12.x | |
11 | - 1.13.x | |
12 | - 1.14.x | |
13 | install: skip | |
14 | script: | |
15 | - go get golang.org/x/tools/cmd/cover | |
16 | - go get github.com/smartystreets/goconvey | |
17 | - mkdir -p $HOME/gopath/src/gopkg.in | |
18 | - ln -s $HOME/gopath/src/github.com/go-ini/ini $HOME/gopath/src/gopkg.in/ini.v1 | |
19 | - cd $HOME/gopath/src/gopkg.in/ini.v1 | |
20 | - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... | |
21 | after_success: | |
22 | - bash <(curl -s https://codecov.io/bash) |
0 | 0 | # INI |
1 | 1 | |
2 | [![Build Status](https://img.shields.io/travis/go-ini/ini/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.org/go-ini/ini) | |
2 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/go-ini/ini/Go?logo=github&style=for-the-badge)](https://github.com/go-ini/ini/actions?query=workflow%3AGo) | |
3 | 3 | [![codecov](https://img.shields.io/codecov/c/github/go-ini/ini/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/go-ini/ini) |
4 | [![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/go-ini/ini?tab=doc) | |
4 | 5 | [![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/go-ini/ini) |
5 | 6 | |
6 | 7 | ![](https://avatars0.githubusercontent.com/u/10216035?v=3&s=200) |
65 | 65 | return sourceFile{s}, nil |
66 | 66 | case []byte: |
67 | 67 | return &sourceData{s}, nil |
68 | case io.ReadCloser: | |
69 | return &sourceReadCloser{s}, nil | |
68 | 70 | case io.Reader: |
69 | 71 | return &sourceReadCloser{ioutil.NopCloser(s)}, nil |
70 | case io.ReadCloser: | |
71 | return &sourceReadCloser{s}, nil | |
72 | 72 | default: |
73 | 73 | return nil, fmt.Errorf("error parsing data source: unknown type %q", s) |
74 | 74 | } |
16 | 16 | import ( |
17 | 17 | "bytes" |
18 | 18 | "io/ioutil" |
19 | "runtime" | |
19 | 20 | "testing" |
20 | 21 | |
21 | 22 | . "github.com/smartystreets/goconvey/convey" |
86 | 87 | So(err, ShouldBeNil) |
87 | 88 | So(f, ShouldNotBeNil) |
88 | 89 | |
89 | sec.NewKey("PublicKey", "<client3's publickey>") | |
90 | sec.NewKey("AllowedIPs", "192.168.2.4/32") | |
90 | _, _ = sec.NewKey("PublicKey", "<client3's publickey>") | |
91 | _, _ = sec.NewKey("AllowedIPs", "192.168.2.4/32") | |
91 | 92 | |
92 | 93 | var buf bytes.Buffer |
93 | 94 | _, err = f.WriteTo(&buf) |
166 | 167 | }) |
167 | 168 | So(f, ShouldNotBeNil) |
168 | 169 | |
169 | f.NewSections("Interface", "Peer", "Peer") | |
170 | _ = f.NewSections("Interface", "Peer", "Peer") | |
170 | 171 | So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "Interface", "Peer", "Peer"}) |
171 | 172 | f.DeleteSection("Peer") |
172 | 173 | So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "Interface"}) |
325 | 326 | f := ini.Empty() |
326 | 327 | So(f, ShouldNotBeNil) |
327 | 328 | |
328 | f.NewSections("author", "package", "features") | |
329 | _ = f.NewSections("author", "package", "features") | |
329 | 330 | f.DeleteSection("features") |
330 | 331 | f.DeleteSection("") |
331 | 332 | So(f.SectionStrings(), ShouldResemble, []string{"author", "package"}) |
349 | 350 | } |
350 | 351 | |
351 | 352 | func TestFile_WriteTo(t *testing.T) { |
353 | if runtime.GOOS == "windows" { | |
354 | t.Skip("Skipping testing on Windows") | |
355 | } | |
356 | ||
352 | 357 | Convey("Write content to somewhere", t, func() { |
353 | 358 | f, err := ini.Load(fullConf) |
354 | 359 | So(err, ShouldBeNil) |
357 | 362 | f.Section("author").Comment = `Information about package author |
358 | 363 | # Bio can be written in multiple lines.` |
359 | 364 | f.Section("author").Key("NAME").Comment = "This is author name" |
360 | f.Section("note").NewBooleanKey("boolean_key") | |
361 | f.Section("note").NewKey("more", "notes") | |
365 | _, _ = f.Section("note").NewBooleanKey("boolean_key") | |
366 | _, _ = f.Section("note").NewKey("more", "notes") | |
362 | 367 | |
363 | 368 | var buf bytes.Buffer |
364 | 369 | _, err = f.WriteTo(&buf) |
366 | 371 | |
367 | 372 | golden := "testdata/TestFile_WriteTo.golden" |
368 | 373 | if *update { |
369 | ioutil.WriteFile(golden, buf.Bytes(), 0644) | |
374 | So(ioutil.WriteFile(golden, buf.Bytes(), 0644), ShouldBeNil) | |
370 | 375 | } |
371 | 376 | |
372 | 377 | expected, err := ioutil.ReadFile(golden) |
17 | 17 | package ini |
18 | 18 | |
19 | 19 | import ( |
20 | "os" | |
20 | 21 | "regexp" |
21 | 22 | "runtime" |
23 | "strings" | |
22 | 24 | ) |
23 | 25 | |
24 | 26 | const ( |
54 | 56 | DefaultFormatRight = "" |
55 | 57 | ) |
56 | 58 | |
59 | var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test") | |
60 | ||
57 | 61 | func init() { |
58 | if runtime.GOOS == "windows" { | |
62 | if runtime.GOOS == "windows" && !inTest { | |
59 | 63 | LineBreak = "\r\n" |
60 | 64 | } |
61 | 65 | } |
1 | 1 | |
2 | 2 | import ( |
3 | 3 | "path/filepath" |
4 | "runtime" | |
4 | 5 | "testing" |
5 | 6 | |
6 | 7 | . "github.com/smartystreets/goconvey/convey" |
14 | 15 | } |
15 | 16 | |
16 | 17 | func TestMultiline(t *testing.T) { |
18 | if runtime.GOOS == "windows" { | |
19 | t.Skip("Skipping testing on Windows") | |
20 | } | |
21 | ||
17 | 22 | Convey("Parse Python-style multiline values", t, func() { |
18 | 23 | path := filepath.Join("testdata", "multiline.ini") |
19 | 24 | f, err := ini.LoadSources(ini.LoadOptions{ |
20 | 25 | AllowPythonMultilineValues: true, |
21 | 26 | ReaderBufferSize: 64 * 1024, |
22 | /* | |
23 | Debug: func(m string) { | |
24 | fmt.Println(m) | |
25 | }, | |
26 | */ | |
27 | 27 | }, path) |
28 | 28 | So(err, ShouldBeNil) |
29 | 29 | So(f, ShouldNotBeNil) |
16 | 16 | import ( |
17 | 17 | "bytes" |
18 | 18 | "fmt" |
19 | "runtime" | |
19 | 20 | "strings" |
20 | 21 | "testing" |
21 | 22 | "time" |
183 | 184 | }) |
184 | 185 | |
185 | 186 | Convey("Get multiple line value", func() { |
187 | if runtime.GOOS == "windows" { | |
188 | t.Skip("Skipping testing on Windows") | |
189 | } | |
190 | ||
186 | 191 | So(f.Section("author").Key("BIO").String(), ShouldEqual, "Gopher.\nCoding addict.\nGood man.\n") |
187 | 192 | }) |
188 | 193 |
83 | 83 | case mask[0] == 254 && mask[1] == 255: |
84 | 84 | fallthrough |
85 | 85 | case mask[0] == 255 && mask[1] == 254: |
86 | p.buf.Read(mask) | |
86 | _, err = p.buf.Read(mask) | |
87 | if err != nil { | |
88 | return err | |
89 | } | |
87 | 90 | case mask[0] == 239 && mask[1] == 187: |
88 | 91 | mask, err := p.buf.Peek(3) |
89 | 92 | if err != nil && err != io.EOF { |
92 | 95 | return nil |
93 | 96 | } |
94 | 97 | if mask[2] == 191 { |
95 | p.buf.Read(mask) | |
98 | _, err = p.buf.Read(mask) | |
99 | if err != nil { | |
100 | return err | |
101 | } | |
96 | 102 | } |
97 | 103 | } |
98 | 104 | return nil |
134 | 140 | } |
135 | 141 | |
136 | 142 | // Get out key name |
137 | endIdx := -1 | |
143 | var endIdx int | |
138 | 144 | if len(keyQuote) > 0 { |
139 | 145 | startIdx := len(keyQuote) |
140 | 146 | // FIXME: fail case -> """"""name"""=value |
412 | 418 | if f.options.AllowNestedValues && |
413 | 419 | isLastValueEmpty && len(line) > 0 { |
414 | 420 | if line[0] == ' ' || line[0] == '\t' { |
415 | lastRegularKey.addNestedValue(string(bytes.TrimSpace(line))) | |
421 | err = lastRegularKey.addNestedValue(string(bytes.TrimSpace(line))) | |
422 | if err != nil { | |
423 | return err | |
424 | } | |
416 | 425 | continue |
417 | 426 | } |
418 | 427 | } |
459 | 468 | inUnparseableSection = false |
460 | 469 | for i := range f.options.UnparseableSections { |
461 | 470 | if f.options.UnparseableSections[i] == name || |
462 | (f.options.Insensitive && strings.ToLower(f.options.UnparseableSections[i]) == strings.ToLower(name)) { | |
471 | (f.options.Insensitive && strings.EqualFold(f.options.UnparseableSections[i], name)) { | |
463 | 472 | inUnparseableSection = true |
464 | 473 | continue |
465 | 474 | } |