Skip to content

Commit b7c2cb5

Browse files
authored
Merge pull request #117 from yangcao77/625-concrete-version
support concrete schema version
2 parents 61ec35a + e66d97c commit b7c2cb5

File tree

7 files changed

+271
-18
lines changed

7 files changed

+271
-18
lines changed

devfile.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
schemaVersion: 2.2.0
1+
schemaVersion: 2.2.0-latest
22
metadata:
33
name: nodejs
44
version: 1.0.0

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/devfile/library
33
go 1.15
44

55
require (
6-
github.com/devfile/api/v2 v2.0.0-20210914125740-da05a3e14c3b
6+
github.com/devfile/api/v2 v2.0.0-20210917193329-089a48011460
77
github.com/fatih/color v1.7.0
88
github.com/gobwas/glob v0.2.3
99
github.com/golang/mock v1.5.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ
8383
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8484
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8585
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
86-
github.com/devfile/api/v2 v2.0.0-20210914125740-da05a3e14c3b h1:OSORBTgmRBJUKbZhGJJn+CH7gyY4IBdARn9pJpnqyBs=
87-
github.com/devfile/api/v2 v2.0.0-20210914125740-da05a3e14c3b/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
86+
github.com/devfile/api/v2 v2.0.0-20210917193329-089a48011460 h1:cmd+3poyUwevcWchYdvE02YT1nQU4SJpA5/wrdLrpWE=
87+
github.com/devfile/api/v2 v2.0.0-20210917193329-089a48011460/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
8888
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
8989
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
9090
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=

pkg/devfile/parser/context/apiVersion.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package parser
33
import (
44
"encoding/json"
55
"fmt"
6+
"strings"
67

78
"github.com/devfile/library/pkg/devfile/parser/data"
89
"github.com/pkg/errors"
@@ -38,7 +39,9 @@ func (d *DevfileCtx) SetDevfileAPIVersion() error {
3839
}
3940

4041
// Successful
41-
d.apiVersion = schemaVersion.(string)
42+
// split by `-` and get the first substring as schema version, schemaVersion without `-` won't get affected
43+
// e.g. 2.2.0-latest => 2.2.0, 2.2.0 => 2.2.0
44+
d.apiVersion = strings.Split(schemaVersion.(string), "-")[0]
4245
klog.V(4).Infof("devfile schemaVersion: '%s'", d.apiVersion)
4346
return nil
4447
}

pkg/devfile/parser/context/apiVersion_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
func TestSetDevfileAPIVersion(t *testing.T) {
1010

1111
const (
12-
schemaVersion = "2.0.0"
13-
validJson = `{"schemaVersion": "2.0.0"}`
12+
schemaVersion = "2.2.0"
13+
validJson = `{"schemaVersion": "2.2.0"}`
14+
concreteSchema = `{"schemaVersion": "2.2.0-latest"}`
1415
emptyJson = "{}"
1516
emptySchemaVersionJson = `{"schemaVersion": ""}`
1617
devfilePath = "/testpath/devfile.yaml"
@@ -30,6 +31,12 @@ func TestSetDevfileAPIVersion(t *testing.T) {
3031
want: schemaVersion,
3132
wantErr: nil,
3233
},
34+
{
35+
name: "concrete schemaVersion",
36+
devfileCtx: DevfileCtx{rawContent: []byte(concreteSchema), absPath: devfilePath},
37+
want: schemaVersion,
38+
wantErr: nil,
39+
},
3340
{
3441
name: "schemaVersion not present",
3542
devfileCtx: DevfileCtx{rawContent: []byte(emptyJson), absPath: devfilePath},

0 commit comments

Comments
 (0)