Skip to content

Commit 5910b5b

Browse files
committed
clean up commits
Signed-off-by: Stephanie <[email protected]>
1 parent c175e96 commit 5910b5b

File tree

9 files changed

+132
-12
lines changed

9 files changed

+132
-12
lines changed

.github/workflows/go.yml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
if [[ ! -z $(git status -s) ]]
2929
then
3030
echo "Go mod state is not clean"
31+
git diff "$GITHUB_SHA"
3132
exit 1
3233
fi
3334
- name: Build Binary

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ main
1818
# Files used for debugging
1919
.vscode/
2020

21+
# Files created by GoLand
22+
.idea/
23+
2124
# File created running tests
2225
tests/**/tmp/
2326

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ gofmt:
1515

1616
.PHONY: bin
1717
bin:
18-
go build main.go
18+
go build *.go
1919

2020
.PHONY: test
2121
test:

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
4343
}
4444
deployment := generator.GetDeployment(deployParams)
4545
```
46+
47+
<br></br>
48+
Run `updateApi.sh` can update to use latest `github.com/devfile/api` and update the schema saved under `pkg/devfile/parser/data`
49+
50+
The script also accepts version number as an argument to update devfile schema for a specific devfile version.
51+
For example, run the following command will update devfile schema for 2.0.0
52+
```
53+
./updateApi.sh 2.0.0
54+
```
55+
Running the script with no arguments will default to update the latest devfile version
56+
4657
4758
## Usage
4859
@@ -54,4 +65,4 @@ In the future, the following projects will be consuming this library as a Golang
5465
5566
## Issues
5667
57-
Issues are tracked in the [devfile/api](https://github.com/devfile/api) repo with the label [area/library](https://github.com/devfile/api/issues?q=is%3Aopen+is%3Aissue+label%3Aarea%2Flibrary)
68+
Issues are tracked in the [devfile/api](https://github.com/devfile/api) repo with the label [area/library](https://github.com/devfile/api/issues?q=is%3Aopen+is%3Aissue+label%3Aarea%2Flibrary)

go.mod

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

55
require (
6-
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835
6+
github.com/devfile/api/v2 v2.0.0-20210223145532-81859eaef987
77
github.com/fatih/color v1.7.0
88
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
99
github.com/gobwas/glob v0.2.3

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
4444
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4545
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4646
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
47-
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835 h1:PalHtpqhvX/yu5DKFqwTWa1h7UJBd0H7+veJStur/wg=
48-
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
47+
github.com/devfile/api/v2 v2.0.0-20210223145532-81859eaef987 h1:3wclWpWL/+IP6oAMY1M+RECQYa/4ZBkff7jDX1RyLxg=
48+
github.com/devfile/api/v2 v2.0.0-20210223145532-81859eaef987/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
4949
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
5050
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
5151
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=

main.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ import (
1313
)
1414

1515
func main() {
16+
if len(os.Args) > 1 && os.Args[1] == "updateSchema" {
17+
ReplaceSchemaFile()
18+
} else {
19+
parserTest()
20+
}
21+
}
22+
23+
//ParseDevfile to parse devfile from library
24+
func ParseDevfile(devfileLocation string) (parser.DevfileObj, error) {
25+
26+
devfile, err := devfilepkg.ParseAndValidate(devfileLocation)
27+
return devfile, err
28+
}
29+
30+
func parserTest() {
1631
var devfile parser.DevfileObj
1732
var err error
1833
if len(os.Args) > 1 {
@@ -107,10 +122,3 @@ func main() {
107122
}
108123

109124
}
110-
111-
//ParseDevfile to parse devfile from library
112-
func ParseDevfile(devfileLocation string) (parser.DevfileObj, error) {
113-
114-
devfile, err := devfilepkg.ParseAndValidate(devfileLocation)
115-
return devfile, err
116-
}

replaceSchemaFile.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
"strings"
8+
)
9+
10+
func ReplaceSchemaFile() {
11+
if len(os.Args) != 7 {
12+
printErr(fmt.Errorf("ReplaceSchemaFile() expect 7 arguments"))
13+
os.Exit(1)
14+
}
15+
originalSchema := os.Args[2]
16+
schemaURL := os.Args[3]
17+
packageVersion := os.Args[4]
18+
jsonSchemaVersion := os.Args[5]
19+
filePath := os.Args[6]
20+
21+
// replace all ` with ' to convert schema content from json file format to json format in golang
22+
newSchema := strings.ReplaceAll(originalSchema, "`", "'")
23+
fmt.Printf("Writing to file: %s\n", filePath)
24+
fileContent := fmt.Sprintf("package %s\n\n// %s\nconst %s = `%s\n`\n", packageVersion, schemaURL, jsonSchemaVersion, newSchema)
25+
26+
if err := ioutil.WriteFile(filePath, []byte(fileContent), 0755); err != nil {
27+
printErr(err)
28+
os.Exit(1)
29+
}
30+
}
31+
32+
func printErr(err error) {
33+
// prints error in red
34+
colorRed := "\033[31m"
35+
colorReset := "\033[0m"
36+
37+
fmt.Println(string(colorRed), err, string(colorReset))
38+
}

updateApi.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
BLUE='\033[1;34m'
4+
GREEN='\033[0;32m'
5+
RED='\033[0;31m'
6+
NC='\033[0m'
7+
BOLD='\033[1m'
8+
9+
set -e
10+
11+
CURRENT_DIR=$(pwd)
12+
API_PKG="github.com/devfile/api/v2"
13+
SCHEMA_URL_MASTER="https://raw.githubusercontent.com/devfile/api/master/schemas/latest/devfile.json"
14+
15+
# 2.0.0 devfile
16+
SCHEMA_URL_200="https://raw.githubusercontent.com/devfile/api/2.0.x/schemas/latest/devfile.json"
17+
PACKAGE_VERSION_200="version200"
18+
JSON_SCHEMA_200="JsonSchema200"
19+
FILE_PATH_200="./pkg/devfile/parser/data/v2/2.0.0/devfileJsonSchema200.go"
20+
21+
# 2.1.0 devfile
22+
PACKAGE_VERSION_210="version210"
23+
JSON_SCHEMA_210="JsonSchema210"
24+
FILE_PATH_210="./pkg/devfile/parser/data/v2/2.1.0/devfileJsonSchema210.go"
25+
26+
27+
onError() {
28+
cd "${CURRENT_DIR}"
29+
}
30+
trap 'onError' ERR
31+
32+
33+
echo -e "${GREEN}Updating devfile/api in go.mod${NC}"
34+
go get "${API_PKG}@master"
35+
36+
echo -e "${GREEN}Get latest schema${NC}"
37+
38+
case "${1}" in
39+
"2.0.0")
40+
SCHEMA_URL=${SCHEMA_URL_200}
41+
PACKAGE_VERSION=${PACKAGE_VERSION_200}
42+
JSON_SCHEMA=${JSON_SCHEMA_200}
43+
FILE_PATH=${FILE_PATH_200}
44+
;;
45+
*)
46+
# default
47+
SCHEMA_URL=${SCHEMA_URL_MASTER}
48+
PACKAGE_VERSION=${PACKAGE_VERSION_210}
49+
JSON_SCHEMA=${JSON_SCHEMA_210}
50+
FILE_PATH=${FILE_PATH_210}
51+
;;
52+
esac
53+
54+
schema=$(curl -L "${SCHEMA_URL}")
55+
56+
#replace all ` with ' and write to schema file
57+
echo -e "${GREEN}Write to go file${NC}"
58+
go build *.go
59+
./main updateSchema "${schema}" "${SCHEMA_URL}" "${PACKAGE_VERSION}" "${JSON_SCHEMA}" "${FILE_PATH}"

0 commit comments

Comments
 (0)