mirror of
https://github.com/helm/chart-testing.git
synced 2026-02-05 09:45:14 +01:00
add github grouping of log lines (#556)
see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines Signed-off-by: Joe Julian <me@joejulian.name>
This commit is contained in:
@@ -318,15 +318,23 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
fmt.Println(" Charts to be processed:")
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
if !t.config.GithubGroups {
|
||||
fmt.Println()
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
fmt.Println(" Charts to be processed:")
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
} else {
|
||||
util.GithubGroupsBegin(os.Stdout, "Charts to be processed")
|
||||
}
|
||||
for _, chart := range charts {
|
||||
fmt.Printf(" %s\n", chart)
|
||||
}
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
fmt.Println()
|
||||
if !t.config.GithubGroups {
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
fmt.Println()
|
||||
} else {
|
||||
util.GithubGroupsEnd(os.Stdout)
|
||||
}
|
||||
|
||||
repoArgs := map[string][]string{}
|
||||
|
||||
@@ -414,7 +422,12 @@ func (t *Testing) LintAndInstallCharts() ([]TestResult, error) {
|
||||
|
||||
// PrintResults writes test results to stdout.
|
||||
func (t *Testing) PrintResults(results []TestResult) {
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
if !t.config.GithubGroups {
|
||||
fmt.Println()
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
} else {
|
||||
util.GithubGroupsBegin(os.Stdout, "Test Results")
|
||||
}
|
||||
if results != nil {
|
||||
for _, result := range results {
|
||||
err := result.Error
|
||||
@@ -427,7 +440,11 @@ func (t *Testing) PrintResults(results []TestResult) {
|
||||
} else {
|
||||
fmt.Println("No chart changes detected.")
|
||||
}
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
if !t.config.GithubGroups {
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "-")
|
||||
} else {
|
||||
util.GithubGroupsEnd(os.Stdout)
|
||||
}
|
||||
}
|
||||
|
||||
// LintChart lints the specified chart.
|
||||
@@ -882,7 +899,7 @@ func (t *Testing) ValidateMaintainers(chart *Chart) error {
|
||||
func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string) {
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "=")
|
||||
|
||||
printDetails(namespace, "Events of namespace", ".", func(item string) error {
|
||||
t.printDetails(namespace, "Events of namespace", ".", func(item string) error {
|
||||
return t.kubectl.GetEvents(namespace)
|
||||
}, namespace)
|
||||
|
||||
@@ -901,7 +918,7 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
|
||||
}
|
||||
|
||||
for _, pod := range pods {
|
||||
printDetails(pod, "Description of pod", "~", func(item string) error {
|
||||
t.printDetails(pod, "Description of pod", "~", func(item string) error {
|
||||
return t.kubectl.DescribePod(namespace, pod)
|
||||
}, pod)
|
||||
|
||||
@@ -912,7 +929,7 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
|
||||
}
|
||||
|
||||
if t.config.PrintLogs {
|
||||
printDetails(pod, "Logs of init container", "-",
|
||||
t.printDetails(pod, "Logs of init container", "-",
|
||||
func(item string) error {
|
||||
return t.kubectl.Logs(namespace, pod, item)
|
||||
}, initContainers...)
|
||||
@@ -923,7 +940,7 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
|
||||
return
|
||||
}
|
||||
|
||||
printDetails(pod, "Logs of container", "-",
|
||||
t.printDetails(pod, "Logs of container", "-",
|
||||
func(item string) error {
|
||||
return t.kubectl.Logs(namespace, pod, item)
|
||||
},
|
||||
@@ -934,21 +951,29 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, "=")
|
||||
}
|
||||
|
||||
func printDetails(resource string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
|
||||
func (t *Testing) printDetails(resource string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
|
||||
for _, item := range items {
|
||||
item = strings.Trim(item, "'")
|
||||
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
fmt.Printf("==> %s %s\n", text, resource)
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
if !t.config.GithubGroups {
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
fmt.Printf("==> %s %s\n", text, resource)
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
} else {
|
||||
util.GithubGroupsBegin(os.Stdout, fmt.Sprintf("%s %s", text, resource))
|
||||
}
|
||||
|
||||
if err := printFunc(item); err != nil {
|
||||
fmt.Println("Error printing details:", err)
|
||||
return
|
||||
}
|
||||
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
fmt.Printf("<== %s %s\n", text, resource)
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
if !t.config.GithubGroups {
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
fmt.Printf("<== %s %s\n", text, resource)
|
||||
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
|
||||
} else {
|
||||
util.GithubGroupsEnd(os.Stdout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ type Configuration struct {
|
||||
ExcludeDeprecated bool `mapstructure:"exclude-deprecated"`
|
||||
KubectlTimeout time.Duration `mapstructure:"kubectl-timeout"`
|
||||
PrintLogs bool `mapstructure:"print-logs"`
|
||||
GithubGroups bool `mapstructure:"github-groups"`
|
||||
}
|
||||
|
||||
func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*Configuration, error) {
|
||||
@@ -173,9 +174,13 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C
|
||||
}
|
||||
|
||||
func printCfg(cfg *Configuration) {
|
||||
util.PrintDelimiterLineToWriter(os.Stderr, "-")
|
||||
fmt.Fprintln(os.Stderr, " Configuration")
|
||||
util.PrintDelimiterLineToWriter(os.Stderr, "-")
|
||||
if !cfg.GithubGroups {
|
||||
util.PrintDelimiterLineToWriter(os.Stderr, "-")
|
||||
fmt.Fprintln(os.Stderr, " Configuration")
|
||||
util.PrintDelimiterLineToWriter(os.Stderr, "-")
|
||||
} else {
|
||||
util.GithubGroupsBegin(os.Stderr, "Configuration")
|
||||
}
|
||||
|
||||
e := reflect.ValueOf(cfg).Elem()
|
||||
typeOfCfg := e.Type()
|
||||
@@ -191,7 +196,11 @@ func printCfg(cfg *Configuration) {
|
||||
fmt.Fprintf(os.Stderr, pattern, typeOfCfg.Field(i).Name, e.Field(i).Interface())
|
||||
}
|
||||
|
||||
util.PrintDelimiterLineToWriter(os.Stderr, "-")
|
||||
if !cfg.GithubGroups {
|
||||
util.PrintDelimiterLineToWriter(os.Stderr, "-")
|
||||
} else {
|
||||
util.GithubGroupsEnd(os.Stderr)
|
||||
}
|
||||
}
|
||||
|
||||
func findConfigFile(fileName string) (string, error) {
|
||||
|
||||
@@ -219,11 +219,15 @@ func BreakingChangeAllowed(left string, right string) (bool, error) {
|
||||
}
|
||||
|
||||
func PrintDelimiterLineToWriter(w io.Writer, delimiterChar string) {
|
||||
delim := make([]string, 120)
|
||||
for i := 0; i < 120; i++ {
|
||||
delim[i] = delimiterChar
|
||||
}
|
||||
fmt.Fprintln(w, strings.Join(delim, ""))
|
||||
fmt.Fprintln(w, strings.Repeat(delimiterChar, 120))
|
||||
}
|
||||
|
||||
func GithubGroupsBegin(w io.Writer, title string) {
|
||||
fmt.Fprintf(w, "::group::%s\n", title)
|
||||
}
|
||||
|
||||
func GithubGroupsEnd(w io.Writer) {
|
||||
fmt.Fprintln(w, "::endgroup::")
|
||||
}
|
||||
|
||||
func SanitizeName(s string, maxLength int) string {
|
||||
|
||||
Reference in New Issue
Block a user