Skip to content

Commit 2e8ac31

Browse files
authored
add examples support for draft info (#165)
1 parent 2cddc6a commit 2e8ac31

File tree

23 files changed

+225
-63
lines changed

23 files changed

+225
-63
lines changed

.github/workflows/e2e-info.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Draft Info E2E Test
2+
on:
3+
pull_request:
4+
branches: [ main ]
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- name: Set up Go
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: 1.18.2
15+
- name: make
16+
run: make
17+
- name: Validate JSON
18+
run: |
19+
./test/check_info_schema.sh

.github/workflows/integration-info.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ vendor/
66
draft
77
langtest
88
.vscode/
9-
/pkg/languages/builders
9+
/pkg/languages/builders
10+
info.json

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ go-generate:
1616
run-unit-tests:
1717
docker build . -t gotest && docker run -t --rm --name draft-test gotest test ./... -buildvcs=false
1818

19+
#TODO: add more e2e tests to the local testing
20+
.PHONY: run-e2e-tests-local
21+
run-e2e-tests-local: go-generate vendor build
22+
test/check_info_schema.sh;
23+
1924
.PHONY: generate-integrations
2025
generate-integrations:
2126
cd ./test; \

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,24 @@ If you plan on deploying your application through your GitHub Action, commit all
5050

5151
### `draft info`
5252
The `draft info` command prints information about supported languages and deployment types.
53-
Example output:
53+
54+
Example output (for brevity, only the first supported language is shown):
5455
```
5556
{
56-
"supported_languages": [
57-
"php",
58-
"python",
59-
"rust",
60-
"swift",
61-
"csharp",
62-
"go",
63-
"gradle",
64-
"javascript",
65-
"ruby",
66-
"clojure",
67-
"erlang",
68-
"gomodule",
69-
"java"
70-
],
71-
"supported_deployment_types": [
57+
"supportedLanguages": [
58+
{
59+
"name": "clojure",
60+
"displayName": "Clojure",
61+
"variableExampleValues": {
62+
"VERSION": [
63+
"8-jdk-alpine",
64+
"11-jdk-alpine"
65+
]
66+
}
67+
}
68+
]
69+
...,
70+
"supportedDeploymentTypes": [
7271
"helm",
7372
"kustomize",
7473
"manifests"

cmd/info.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ type infoCmd struct {
2323
info *draftInfo
2424
}
2525

26+
// draftConfigInfo is a struct that contains information about the example usage of variables for a single draft.yaml
27+
type draftConfigInfo struct {
28+
Name string `json:"name"`
29+
DisplayName string `json:"displayName,omitempty"`
30+
VariableExampleValues map[string][]string `json:"variableExampleValues,omitempty"`
31+
}
32+
2633
type draftInfo struct {
27-
SupportedLanguages []string `json:"supported_languages"`
28-
SupportedDeploymentTypes []string `json:"supported_deployment_types"`
34+
SupportedLanguages []draftConfigInfo `json:"supportedLanguages"`
35+
SupportedDeploymentTypes []string `json:"supportedDeploymentTypes"`
2936
}
3037

3138
func newInfoCmd() *cobra.Command {
@@ -52,8 +59,19 @@ func (ic *infoCmd) run() error {
5259
l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, "")
5360
d := deployments.CreateDeploymentsFromEmbedFS(template.Deployments, "")
5461

62+
languagesInfo := make([]draftConfigInfo, 0)
63+
for _, lang := range l.Names() {
64+
langConfig := l.GetConfig(lang)
65+
newConfig := draftConfigInfo{
66+
Name: lang,
67+
DisplayName: langConfig.DisplayName,
68+
VariableExampleValues: langConfig.GetVariableExampleValues(),
69+
}
70+
languagesInfo = append(languagesInfo, newConfig)
71+
}
72+
5573
ic.info = &draftInfo{
56-
SupportedLanguages: l.Names(),
74+
SupportedLanguages: languagesInfo,
5775
SupportedDeploymentTypes: d.DeployTypes(),
5876
}
5977

pkg/config/draftconfig.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
//TODO: remove Name Overrides since we don't need them anymore
88
type DraftConfig struct {
9+
DisplayName string `yaml:"displayName"`
910
NameOverrides []FileNameOverride `yaml:"nameOverrides"`
1011
Variables []BuilderVar `yaml:"variables"`
1112
VariableDefaults []BuilderVarDefault `yaml:"variableDefaults"`
@@ -19,9 +20,10 @@ type FileNameOverride struct {
1920
}
2021

2122
type BuilderVar struct {
22-
Name string `yaml:"name"`
23-
Description string `yaml:"description"`
24-
VarType string `yaml:"type"`
23+
Name string `yaml:"name"`
24+
Description string `yaml:"description"`
25+
VarType string `yaml:"type"`
26+
ExampleValues []string `yaml:"exampleValues"`
2527
}
2628

2729
type BuilderVarDefault struct {
@@ -30,6 +32,16 @@ type BuilderVarDefault struct {
3032
ReferenceVar string `yaml:"referenceVar"`
3133
}
3234

35+
func (d *DraftConfig) GetVariableExampleValues() map[string][]string {
36+
variableExampleValues := make(map[string][]string)
37+
for _, variable := range d.Variables {
38+
if len(variable.ExampleValues) > 0 {
39+
variableExampleValues[variable.Name] = variable.ExampleValues
40+
}
41+
}
42+
return variableExampleValues
43+
}
44+
3345
func (d *DraftConfig) initNameOverrideMap() {
3446
d.nameOverrideMap = make(map[string]string)
3547
log.Debug("initializing nameOverrideMap")

template/dockerfiles/clojure/draft.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
language: clojure
2+
displayName: Clojure
23
variables:
34
- name: "PORT"
45
description: "the port exposed in the application"
56
type: int
67
- name: "VERSION"
78
description: "the version of openjdk that the application uses"
9+
exampleValues: ["8-jdk-alpine","11-jdk-alpine"]
810
variableDefaults:
911
- name: "VERSION"
1012
value: "8-jdk-alpine"

template/dockerfiles/csharp/draft.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
language: csharp
2+
displayName: C#
23
variables:
34
- name: "PORT"
45
description: "the port exposed in the application"
56
type: int
67
- name: "VERSION"
78
description: "the dotnet SDK version"
89
type: float
10+
exampleValues: ["3.1","4.0","5.0","6.0"]
911
variableDefaults:
1012
- name: "VERSION"
1113
value: "5.0"

template/dockerfiles/erlang/draft.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: erlang
2+
displayName: Erlang
23
nameOverrides:
34
- path: "dockerignore"
45
prefix: "."
@@ -8,8 +9,10 @@ variables:
89
type: int
910
- name: "BUILDERVERSION"
1011
description: "the version of erlang used during the builder stage to generate the executable"
12+
exampleValues: ["24.2-alpine"]
1113
- name: "VERSION"
1214
description: "the version of alpine used by the application"
15+
exampleValues: ["3.15"]
1316
variableDefaults:
1417
- name: "BUILDERVERSION"
1518
value: "24.2-alpine"

0 commit comments

Comments
 (0)