-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (58 loc) · 2.23 KB
/
main.go
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
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
"strings"
githubactions "github.com/sethvargo/go-githubactions"
"gopkg.in/yaml.v2"
)
const ChartFile = "Chart.yaml"
type Chart struct {
ApiVersion string `yaml:"apiVersion"`
Name string `yaml:"name"`
Version string `yaml:"version"`
KubeVersion string `yaml:"kubeVersion"`
Description string `yaml:"description"`
Type string `yaml:"type"`
Keywords []string `yaml:"keywords"`
Home string `yaml:"home"`
Sources []string `yaml:"sources"`
Dependencies []*Chart `yaml:"dependencies"`
Repository string `yaml:"repository"`
Icon string `yaml:"icon"`
AppVersion string `yaml:"appVersion"`
Deprecated bool `yaml:"deprecated"`
}
func main() {
chartPath := path.Join(os.Getenv("INPUT_PATH"), ChartFile)
fmt.Println(fmt.Sprintf(`Reading values from "%s" file.`, chartPath))
chartData, readChartError := ioutil.ReadFile(chartPath)
if readChartError != nil {
log.Fatalf("Chart Read Error: %v", readChartError)
}
chart := Chart{}
yamlParseError := yaml.Unmarshal([]byte(chartData), &chart)
if yamlParseError != nil {
log.Fatalf("YAML Parse Error: %v", yamlParseError)
}
githubactions.SetOutput("apiVersion", chart.ApiVersion)
githubactions.SetOutput("name", chart.Name)
githubactions.SetOutput("version", chart.Version)
githubactions.SetOutput("kubeVersion", chart.KubeVersion)
githubactions.SetOutput("description", chart.Description)
githubactions.SetOutput("type", chart.Type)
githubactions.SetOutput("keywords", fmt.Sprintf("%s", strings.Join(chart.Keywords[:], ",")))
githubactions.SetOutput("home", chart.Home)
githubactions.SetOutput("sources", fmt.Sprintf("%s", strings.Join(chart.Sources[:], ",")))
githubactions.SetOutput("repository", chart.Repository)
githubactions.SetOutput("icon", chart.Icon)
githubactions.SetOutput("appVersion", chart.AppVersion)
githubactions.SetOutput("deprecated", fmt.Sprintf("%t", chart.Deprecated))
for _, dependency := range chart.Dependencies {
githubactions.SetOutput(fmt.Sprintf(`dependencies_%s_version`, dependency.Name), dependency.Version)
githubactions.SetOutput(fmt.Sprintf(`dependencies_%s_repository`, dependency.Name), dependency.Repository)
}
}