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:
@@ -77,6 +77,9 @@ func addCommonFlags(flags *pflag.FlagSet) {
|
||||
Prints the configuration to stderr (caution: setting this may
|
||||
expose sensitive data when helm-repo-extra-args contains passwords)`))
|
||||
flags.Bool("exclude-deprecated", false, "Skip charts that are marked as deprecated")
|
||||
flags.Bool("github-groups", false, heredoc.Doc(`
|
||||
Change the delimiters for github to create collapsible groups
|
||||
for command output`))
|
||||
}
|
||||
|
||||
func addCommonLintAndInstallFlags(flags *pflag.FlagSet) {
|
||||
|
||||
@@ -48,6 +48,8 @@ ct install [flags]
|
||||
--exclude-deprecated Skip charts that are marked as deprecated
|
||||
--excluded-charts strings Charts that should be skipped. May be specified multiple times
|
||||
or separate values with commas
|
||||
--github-groups Change the delimiters for github to create collapsible groups
|
||||
for command output
|
||||
--helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]
|
||||
--helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string
|
||||
(e.g. "--timeout 500s"
|
||||
|
||||
@@ -40,6 +40,8 @@ ct lint-and-install [flags]
|
||||
--exclude-deprecated Skip charts that are marked as deprecated
|
||||
--excluded-charts strings Charts that should be skipped. May be specified multiple times
|
||||
or separate values with commas
|
||||
--github-groups Change the delimiters for github to create collapsible groups
|
||||
for command output
|
||||
--helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]
|
||||
--helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string
|
||||
(e.g. "--timeout 500s"
|
||||
|
||||
@@ -50,6 +50,8 @@ ct lint [flags]
|
||||
--exclude-deprecated Skip charts that are marked as deprecated
|
||||
--excluded-charts strings Charts that should be skipped. May be specified multiple times
|
||||
or separate values with commas
|
||||
--github-groups Change the delimiters for github to create collapsible groups
|
||||
for command output
|
||||
--helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]
|
||||
--helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be
|
||||
specified on a per-repo basis with an equals sign as delimiter
|
||||
|
||||
@@ -20,6 +20,8 @@ ct list-changed [flags]
|
||||
--exclude-deprecated Skip charts that are marked as deprecated
|
||||
--excluded-charts strings Charts that should be skipped. May be specified multiple times
|
||||
or separate values with commas
|
||||
--github-groups Change the delimiters for github to create collapsible groups
|
||||
for command output
|
||||
-h, --help help for list-changed
|
||||
--print-config Prints the configuration to stderr (caution: setting this may
|
||||
expose sensitive data when helm-repo-extra-args contains passwords)
|
||||
|
||||
@@ -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