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>
This commit is contained in:
ᴜɴᴋɴᴡᴏɴ
2020-03-28 14:26:37 +08:00
committed by GitHub
co-authored by Sourcegraph Bot
parent 09e0d86be8
commit 91a7cdb4a0
10 changed files with 94 additions and 45 deletions
+49
View File
@@ -0,0 +1,49 @@
name: Go
on:
push:
branches: [master]
pull_request:
env:
GOPROXY: "https://proxy.golang.org"
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Init Go modules
run: go mod init gopkg.in/ini.v1
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1
test:
name: Test
strategy:
matrix:
go-version: [1.13.x, 1.14.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Run unit tests
run: |
go mod init gopkg.in/ini.v1
go test -v -race -coverprofile=coverage -covermode=atomic ./...
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v1.0.6
with:
file: ./coverage
flags: unittests
- name: Cache downloaded modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-23
View File
@@ -1,23 +0,0 @@
language: go
os: linux
dist: xenial
go:
- 1.6.x
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
- 1.14.x
install: skip
script:
- go get golang.org/x/tools/cmd/cover
- go get github.com/smartystreets/goconvey
- mkdir -p $HOME/gopath/src/gopkg.in
- ln -s $HOME/gopath/src/github.com/go-ini/ini $HOME/gopath/src/gopkg.in/ini.v1
- cd $HOME/gopath/src/gopkg.in/ini.v1
- go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
after_success:
- bash <(curl -s https://codecov.io/bash)
+2 -1
View File
@@ -1,7 +1,8 @@
# INI
[![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)
[![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)
[![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)
[![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)
[![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)
![](https://avatars0.githubusercontent.com/u/10216035?v=3&s=200)
+2 -2
View File
@@ -66,10 +66,10 @@ func parseDataSource(source interface{}) (dataSource, error) {
return sourceFile{s}, nil
case []byte:
return &sourceData{s}, nil
case io.Reader:
return &sourceReadCloser{ioutil.NopCloser(s)}, nil
case io.ReadCloser:
return &sourceReadCloser{s}, nil
case io.Reader:
return &sourceReadCloser{ioutil.NopCloser(s)}, nil
default:
return nil, fmt.Errorf("error parsing data source: unknown type %q", s)
}
+12 -7
View File
@@ -17,6 +17,7 @@ package ini_test
import (
"bytes"
"io/ioutil"
"runtime"
"testing"
. "github.com/smartystreets/goconvey/convey"
@@ -87,8 +88,8 @@ AllowedIPs = 192.168.2.3/32`))
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
sec.NewKey("PublicKey", "<client3's publickey>")
sec.NewKey("AllowedIPs", "192.168.2.4/32")
_, _ = sec.NewKey("PublicKey", "<client3's publickey>")
_, _ = sec.NewKey("AllowedIPs", "192.168.2.4/32")
var buf bytes.Buffer
_, err = f.WriteTo(&buf)
@@ -167,7 +168,7 @@ AllowedIPs = 192.168.2.4/32
})
So(f, ShouldNotBeNil)
f.NewSections("Interface", "Peer", "Peer")
_ = f.NewSections("Interface", "Peer", "Peer")
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "Interface", "Peer", "Peer"})
f.DeleteSection("Peer")
So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "Interface"})
@@ -326,7 +327,7 @@ func TestFile_DeleteSection(t *testing.T) {
f := ini.Empty()
So(f, ShouldNotBeNil)
f.NewSections("author", "package", "features")
_ = f.NewSections("author", "package", "features")
f.DeleteSection("features")
f.DeleteSection("")
So(f.SectionStrings(), ShouldResemble, []string{"author", "package"})
@@ -350,6 +351,10 @@ NAME = Unknwon`)), ShouldBeNil)
}
func TestFile_WriteTo(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping testing on Windows")
}
Convey("Write content to somewhere", t, func() {
f, err := ini.Load(fullConf)
So(err, ShouldBeNil)
@@ -358,8 +363,8 @@ func TestFile_WriteTo(t *testing.T) {
f.Section("author").Comment = `Information about package author
# Bio can be written in multiple lines.`
f.Section("author").Key("NAME").Comment = "This is author name"
f.Section("note").NewBooleanKey("boolean_key")
f.Section("note").NewKey("more", "notes")
_, _ = f.Section("note").NewBooleanKey("boolean_key")
_, _ = f.Section("note").NewKey("more", "notes")
var buf bytes.Buffer
_, err = f.WriteTo(&buf)
@@ -367,7 +372,7 @@ func TestFile_WriteTo(t *testing.T) {
golden := "testdata/TestFile_WriteTo.golden"
if *update {
ioutil.WriteFile(golden, buf.Bytes(), 0644)
So(ioutil.WriteFile(golden, buf.Bytes(), 0644), ShouldBeNil)
}
expected, err := ioutil.ReadFile(golden)
+5 -1
View File
@@ -18,8 +18,10 @@
package ini
import (
"os"
"regexp"
"runtime"
"strings"
)
const (
@@ -55,8 +57,10 @@ var (
DefaultFormatRight = ""
)
var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test")
func init() {
if runtime.GOOS == "windows" {
if runtime.GOOS == "windows" && !inTest {
LineBreak = "\r\n"
}
}
+5 -5
View File
@@ -2,6 +2,7 @@ package ini_test
import (
"path/filepath"
"runtime"
"testing"
. "github.com/smartystreets/goconvey/convey"
@@ -15,16 +16,15 @@ type testData struct {
}
func TestMultiline(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping testing on Windows")
}
Convey("Parse Python-style multiline values", t, func() {
path := filepath.Join("testdata", "multiline.ini")
f, err := ini.LoadSources(ini.LoadOptions{
AllowPythonMultilineValues: true,
ReaderBufferSize: 64 * 1024,
/*
Debug: func(m string) {
fmt.Println(m)
},
*/
}, path)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
+5
View File
@@ -17,6 +17,7 @@ package ini_test
import (
"bytes"
"fmt"
"runtime"
"strings"
"testing"
"time"
@@ -184,6 +185,10 @@ func TestKey_Helpers(t *testing.T) {
})
Convey("Get multiple line value", func() {
if runtime.GOOS == "windows" {
t.Skip("Skipping testing on Windows")
}
So(f.Section("author").Key("BIO").String(), ShouldEqual, "Gopher.\nCoding addict.\nGood man.\n")
})
+14 -5
View File
@@ -84,7 +84,10 @@ func (p *parser) BOM() error {
case mask[0] == 254 && mask[1] == 255:
fallthrough
case mask[0] == 255 && mask[1] == 254:
p.buf.Read(mask)
_, err = p.buf.Read(mask)
if err != nil {
return err
}
case mask[0] == 239 && mask[1] == 187:
mask, err := p.buf.Peek(3)
if err != nil && err != io.EOF {
@@ -93,7 +96,10 @@ func (p *parser) BOM() error {
return nil
}
if mask[2] == 191 {
p.buf.Read(mask)
_, err = p.buf.Read(mask)
if err != nil {
return err
}
}
}
return nil
@@ -135,7 +141,7 @@ func readKeyName(delimiters string, in []byte) (string, int, error) {
}
// Get out key name
endIdx := -1
var endIdx int
if len(keyQuote) > 0 {
startIdx := len(keyQuote)
// FIXME: fail case -> """"""name"""=value
@@ -413,7 +419,10 @@ func (f *File) parse(reader io.Reader) (err error) {
if f.options.AllowNestedValues &&
isLastValueEmpty && len(line) > 0 {
if line[0] == ' ' || line[0] == '\t' {
lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
err = lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
if err != nil {
return err
}
continue
}
}
@@ -460,7 +469,7 @@ func (f *File) parse(reader io.Reader) (err error) {
inUnparseableSection = false
for i := range f.options.UnparseableSections {
if f.options.UnparseableSections[i] == name ||
(f.options.Insensitive && strings.ToLower(f.options.UnparseableSections[i]) == strings.ToLower(name)) {
(f.options.Insensitive && strings.EqualFold(f.options.UnparseableSections[i], name)) {
inUnparseableSection = true
continue
}
-1
View File
@@ -695,7 +695,6 @@ func (s *Section) ReflectFrom(v interface{}) error {
}
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
val = val.Elem()
} else {
return errors.New("not a pointer to a struct")