-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
89 lines (81 loc) · 2.56 KB
/
Taskfile.yaml
File metadata and controls
89 lines (81 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
version: '3'
silent: true
vars:
DIR_ARTIFACTS: "{{.ROOT_DIR}}/artifacts"
DIR_DATA: "{{.ROOT_DIR}}/data"
API_SPEC_PATH: "{{.DIR_ARTIFACTS}}/api.json"
LIB_DIR: "lib"
DIR_PACKAGE: "{{.ROOT_DIR}}/{{.LIB_DIR}}"
HYPERSTACK_API_ADDRESS: "https://infrahub-api.nexgencloud.com/v1"
env:
HYPERSTACK_STAGING: "true"
HYPERSTACK_API_KEY: ~
HYPERSTACK_API_ADDRESS: "{{.HYPERSTACK_API_ADDRESS}}"
HYPERSTACK_API_SPEC_ADDRESS: "https://infrahub-api-doc.nexgencloud.com/api.json"
tasks:
init:
desc: |
Install all the necessary dependencies
vars:
DEPS: |-
github.com/deepmap/oapi-codegen/cmd/oapi-codegen
cmds:
# language=bash
- |
# TODO: check go.mod
# go install
go get {{.DEPS}}
go install {{.DEPS}}
build:
desc: |
Generates go sdk file from api.json
vars:
SPEC_PATH: |-
https://infrahub-api-doc.nexgencloud.com/api.json
# TODO: from go.mod
PROJECT: "github.com\\/NexGenCloud\\/hyperstack-sdk-go"
TIME_PACKAGE: "time"
env:
DIR_ARTIFACTS: "{{.DIR_ARTIFACTS}}"
DIR_PACKAGE: "{{.DIR_PACKAGE}}"
cmds:
# language=bash
- |
echo -n "Generating Go SDK... "
go run sdk_generator.go
mkdir -p "{{.DIR_PACKAGE}}/{{.TIME_PACKAGE}}"
find "{{.DIR_PACKAGE}}" \
-name "*.go" \
-exec bash -c 'sed -i.tmp -e "s/time\.Time/{{.TIME_PACKAGE}}.CustomTime/g" "$1" && rm "$1.tmp"' _ {} \;
find "{{.DIR_PACKAGE}}" \
-name "*.go" \
-exec bash -c 'sed -i.tmp -e '"'"'s/"time"/"{{.PROJECT}}\/{{.LIB_DIR}}\/{{.TIME_PACKAGE}}"/g'"'"' "$1" && rm "$1.tmp"' _ {} \;
sed 's/PACKAGE_REPLACE/{{.TIME_PACKAGE}}/g' "{{.DIR_DATA}}/CustomTime.go" \
> "{{.DIR_PACKAGE}}/{{.TIME_PACKAGE}}/CustomTime.go"
echo "done"
build-api-spec:
desc: |
Pulls the latest api.json from the server
dotenv: [ '.env' ]
vars:
SCRIPTS_DIR: "scripts"
SORT_SCHEMAS: "{{.SCRIPTS_DIR}}/sort_schemas.py"
FIX_API_SPEC: "{{.SCRIPTS_DIR}}/fix_api_spec.py"
cmds:
# language=bash
- |
echo -n "Pulling the latest OpenAPI spec... "
curl -s "${HYPERSTACK_API_SPEC_ADDRESS}" > "{{.API_SPEC_PATH}}"
echo "done"
echo -n "Fixing api spec... "
python3 "{{.SORT_SCHEMAS}}" "{{.API_SPEC_PATH}}"
python3 "{{.FIX_API_SPEC}}" "{{.API_SPEC_PATH}}"
echo "done"
test:
desc: |
Runs tests
env:
DIR_ARTIFACTS: "{{.DIR_ARTIFACTS}}"
cmds:
# language=bash
- go test -v sdk_generator_test.go