Skip to content

Commit

Permalink
Run CI tests against Go 1.16 and 1.19 (#139)
Browse files Browse the repository at this point in the history
* Run CI tests against Go 1.16 and 1.19

* Downgrade golang.org/x/sys to support Go 1.16

* Replace strings.Cut(), which was added in Go 1.18
  • Loading branch information
VojtechVitek committed Nov 19, 2022
1 parent 6c3057e commit cb7195e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ on:

jobs:
test:
strategy:
matrix:
go-version: [1.16, 1.19]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: ${{ matrix.go-version }}
- name: Test
run: go test -v ./...

Expand Down
8 changes: 7 additions & 1 deletion cmd/webrpc-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ func collectCliArgs(flags *flag.FlagSet, args []string) (cliFlags []string, temp
templateOpts = map[string]interface{}{}

for _, arg := range args {
name, value, _ := strings.Cut(arg, "=")
//name, value, _ := strings.Cut(arg, "=") // Added in Go 1.18.
name, value := arg, ""
if i := strings.Index(arg, "="); i >= 0 {
name = arg[:i]
value = arg[i+1:]
}

if !strings.HasPrefix(name, "-") {
return nil, nil, fmt.Errorf("option %q is invalid (expected -name=value)", arg)
}
Expand Down
6 changes: 3 additions & 3 deletions gen/funcmap_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func isListType(v interface{}) bool {

// Return true if given type is map (ie. map<T1,T2>).
func isMapType(v interface{}) bool {
key, value, found := strings.Cut(toString(v), ",")
key, value, found := stringsCut(toString(v), ",")
return found && strings.HasPrefix(key, "map<") && strings.HasSuffix(value, ">")
}

// Returns given map's key type (ie. `T1` from `map<T1,T2>`)
func mapKeyType(v interface{}) string {
str := toString(v)
key, value, found := strings.Cut(str, ",")
key, value, found := stringsCut(str, ",")
if !found || !strings.HasPrefix(key, "map<") || !strings.HasSuffix(value, ">") {
panic(fmt.Errorf("mapKeyValue: expected map<Type1,Type2>, got %v", str))
}
Expand All @@ -47,7 +47,7 @@ func mapKeyType(v interface{}) string {
// Returns given map's value type (ie. `T2` from `map<T1,T2>`)
func mapValueType(v interface{}) string {
str := toString(v)
key, value, found := strings.Cut(str, ",")
key, value, found := stringsCut(str, ",")
if !found || !strings.HasPrefix(key, "map<") || !strings.HasSuffix(value, ">") {
panic(fmt.Errorf("mapKeyValue: expected map<Type1,Type2>, got %v", str))
}
Expand Down
11 changes: 10 additions & 1 deletion gen/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func getOldTarget(target string) string {
}

func isGolangTarget(target string) bool {
target, _, _ = strings.Cut(target, "@")
target, _, _ = stringsCut(target, "@")

if target == "golang" || target == "go" {
return true
Expand All @@ -44,3 +44,12 @@ func formatGoSource(source []byte) (string, error) {
}
return string(formatted), nil
}

// strings.Cut was added in Go 1.18.
// Replace this once we bump up go version directive in go.mod.
func stringsCut(s, sep string) (before, after string, found bool) {
if i := strings.Index(s, sep); i >= 0 {
return s[:i], s[i+len(sep):], true
}
return s, "", false
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ require (
golang.org/x/crypto v0.2.0 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
)

// Last version working with Go 1.16 (undefined: unsafe.Slice).
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab
19 changes: 2 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
Expand Down

0 comments on commit cb7195e

Please sign in to comment.