Skip to content

Commit 24acd59

Browse files
committed
1 parent 08d0052 commit 24acd59

File tree

8 files changed

+77
-28
lines changed

8 files changed

+77
-28
lines changed

ct/cmd/root.go

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func addCommonFlags(flags *pflag.FlagSet) {
7777
Prints the configuration to stderr (caution: setting this may
7878
expose sensitive data when helm-repo-extra-args contains passwords)`))
7979
flags.Bool("exclude-deprecated", false, "Skip charts that are marked as deprecated")
80+
flags.Bool("github-groups", false, heredoc.Doc(`
81+
Change the delimiters for github to create collapsible groups
82+
for command output`))
8083
}
8184

8285
func addCommonLintAndInstallFlags(flags *pflag.FlagSet) {

doc/ct_install.md

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ ct install [flags]
4848
--exclude-deprecated Skip charts that are marked as deprecated
4949
--excluded-charts strings Charts that should be skipped. May be specified multiple times
5050
or separate values with commas
51+
--github-groups Change the delimiters for github to create collapsible groups
52+
for command output
5153
--helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]
5254
--helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string
5355
(e.g. "--timeout 500s"

doc/ct_lint-and-install.md

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ ct lint-and-install [flags]
4040
--exclude-deprecated Skip charts that are marked as deprecated
4141
--excluded-charts strings Charts that should be skipped. May be specified multiple times
4242
or separate values with commas
43+
--github-groups Change the delimiters for github to create collapsible groups
44+
for command output
4345
--helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]
4446
--helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string
4547
(e.g. "--timeout 500s"

doc/ct_lint.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ ct lint [flags]
5050
--exclude-deprecated Skip charts that are marked as deprecated
5151
--excluded-charts strings Charts that should be skipped. May be specified multiple times
5252
or separate values with commas
53+
--github-groups Change the delimiters for github to create collapsible groups
54+
for command output
5355
--helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]
5456
--helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be
5557
specified on a per-repo basis with an equals sign as delimiter

doc/ct_list-changed.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ ct list-changed [flags]
2020
--exclude-deprecated Skip charts that are marked as deprecated
2121
--excluded-charts strings Charts that should be skipped. May be specified multiple times
2222
or separate values with commas
23+
--github-groups Change the delimiters for github to create collapsible groups
24+
for command output
2325
-h, --help help for list-changed
2426
--print-config Prints the configuration to stderr (caution: setting this may
2527
expose sensitive data when helm-repo-extra-args contains passwords)

pkg/chart/chart.go

+44-19
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,23 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes
318318
}
319319
}
320320

321-
fmt.Println()
322-
util.PrintDelimiterLineToWriter(os.Stdout, "-")
323-
fmt.Println(" Charts to be processed:")
324-
util.PrintDelimiterLineToWriter(os.Stdout, "-")
321+
if !t.config.GithubGroups {
322+
fmt.Println()
323+
util.PrintDelimiterLineToWriter(os.Stdout, "-")
324+
fmt.Println(" Charts to be processed:")
325+
util.PrintDelimiterLineToWriter(os.Stdout, "-")
326+
} else {
327+
util.GithubGroupsBegin(os.Stdout, "Charts to be processed")
328+
}
325329
for _, chart := range charts {
326330
fmt.Printf(" %s\n", chart)
327331
}
328-
util.PrintDelimiterLineToWriter(os.Stdout, "-")
329-
fmt.Println()
332+
if !t.config.GithubGroups {
333+
util.PrintDelimiterLineToWriter(os.Stdout, "-")
334+
fmt.Println()
335+
} else {
336+
util.GithubGroupsEnd(os.Stdout)
337+
}
330338

331339
repoArgs := map[string][]string{}
332340

@@ -414,7 +422,12 @@ func (t *Testing) LintAndInstallCharts() ([]TestResult, error) {
414422

415423
// PrintResults writes test results to stdout.
416424
func (t *Testing) PrintResults(results []TestResult) {
417-
util.PrintDelimiterLineToWriter(os.Stdout, "-")
425+
if !t.config.GithubGroups {
426+
fmt.Println()
427+
util.PrintDelimiterLineToWriter(os.Stdout, "-")
428+
} else {
429+
util.GithubGroupsBegin(os.Stdout, "Test Results")
430+
}
418431
if results != nil {
419432
for _, result := range results {
420433
err := result.Error
@@ -427,7 +440,11 @@ func (t *Testing) PrintResults(results []TestResult) {
427440
} else {
428441
fmt.Println("No chart changes detected.")
429442
}
430-
util.PrintDelimiterLineToWriter(os.Stdout, "-")
443+
if !t.config.GithubGroups {
444+
util.PrintDelimiterLineToWriter(os.Stdout, "-")
445+
} else {
446+
util.GithubGroupsEnd(os.Stdout)
447+
}
431448
}
432449

433450
// LintChart lints the specified chart.
@@ -882,7 +899,7 @@ func (t *Testing) ValidateMaintainers(chart *Chart) error {
882899
func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string) {
883900
util.PrintDelimiterLineToWriter(os.Stdout, "=")
884901

885-
printDetails(namespace, "Events of namespace", ".", func(item string) error {
902+
t.printDetails(namespace, "Events of namespace", ".", func(item string) error {
886903
return t.kubectl.GetEvents(namespace)
887904
}, namespace)
888905

@@ -901,7 +918,7 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
901918
}
902919

903920
for _, pod := range pods {
904-
printDetails(pod, "Description of pod", "~", func(item string) error {
921+
t.printDetails(pod, "Description of pod", "~", func(item string) error {
905922
return t.kubectl.DescribePod(namespace, pod)
906923
}, pod)
907924

@@ -912,7 +929,7 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
912929
}
913930

914931
if t.config.PrintLogs {
915-
printDetails(pod, "Logs of init container", "-",
932+
t.printDetails(pod, "Logs of init container", "-",
916933
func(item string) error {
917934
return t.kubectl.Logs(namespace, pod, item)
918935
}, initContainers...)
@@ -923,7 +940,7 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
923940
return
924941
}
925942

926-
printDetails(pod, "Logs of container", "-",
943+
t.printDetails(pod, "Logs of container", "-",
927944
func(item string) error {
928945
return t.kubectl.Logs(namespace, pod, item)
929946
},
@@ -934,21 +951,29 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string
934951
util.PrintDelimiterLineToWriter(os.Stdout, "=")
935952
}
936953

937-
func printDetails(resource string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
954+
func (t *Testing) printDetails(resource string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
938955
for _, item := range items {
939956
item = strings.Trim(item, "'")
940957

941-
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
942-
fmt.Printf("==> %s %s\n", text, resource)
943-
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
958+
if !t.config.GithubGroups {
959+
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
960+
fmt.Printf("==> %s %s\n", text, resource)
961+
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
962+
} else {
963+
util.GithubGroupsBegin(os.Stdout, fmt.Sprintf("%s %s", text, resource))
964+
}
944965

945966
if err := printFunc(item); err != nil {
946967
fmt.Println("Error printing details:", err)
947968
return
948969
}
949970

950-
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
951-
fmt.Printf("<== %s %s\n", text, resource)
952-
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
971+
if !t.config.GithubGroups {
972+
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
973+
fmt.Printf("<== %s %s\n", text, resource)
974+
util.PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
975+
} else {
976+
util.GithubGroupsEnd(os.Stdout)
977+
}
953978
}
954979
}

pkg/config/config.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Configuration struct {
7171
ExcludeDeprecated bool `mapstructure:"exclude-deprecated"`
7272
KubectlTimeout time.Duration `mapstructure:"kubectl-timeout"`
7373
PrintLogs bool `mapstructure:"print-logs"`
74+
GithubGroups bool `mapstructure:"github-groups"`
7475
}
7576

7677
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
173174
}
174175

175176
func printCfg(cfg *Configuration) {
176-
util.PrintDelimiterLineToWriter(os.Stderr, "-")
177-
fmt.Fprintln(os.Stderr, " Configuration")
178-
util.PrintDelimiterLineToWriter(os.Stderr, "-")
177+
if !cfg.GithubGroups {
178+
util.PrintDelimiterLineToWriter(os.Stderr, "-")
179+
fmt.Fprintln(os.Stderr, " Configuration")
180+
util.PrintDelimiterLineToWriter(os.Stderr, "-")
181+
} else {
182+
util.GithubGroupsBegin(os.Stderr, "Configuration")
183+
}
179184

180185
e := reflect.ValueOf(cfg).Elem()
181186
typeOfCfg := e.Type()
@@ -191,7 +196,11 @@ func printCfg(cfg *Configuration) {
191196
fmt.Fprintf(os.Stderr, pattern, typeOfCfg.Field(i).Name, e.Field(i).Interface())
192197
}
193198

194-
util.PrintDelimiterLineToWriter(os.Stderr, "-")
199+
if !cfg.GithubGroups {
200+
util.PrintDelimiterLineToWriter(os.Stderr, "-")
201+
} else {
202+
util.GithubGroupsEnd(os.Stderr)
203+
}
195204
}
196205

197206
func findConfigFile(fileName string) (string, error) {

pkg/util/util.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,15 @@ func BreakingChangeAllowed(left string, right string) (bool, error) {
219219
}
220220

221221
func PrintDelimiterLineToWriter(w io.Writer, delimiterChar string) {
222-
delim := make([]string, 120)
223-
for i := 0; i < 120; i++ {
224-
delim[i] = delimiterChar
225-
}
226-
fmt.Fprintln(w, strings.Join(delim, ""))
222+
fmt.Fprintln(w, strings.Repeat(delimiterChar, 120))
223+
}
224+
225+
func GithubGroupsBegin(w io.Writer, title string) {
226+
fmt.Fprintf(w, "::group::%s\n", title)
227+
}
228+
229+
func GithubGroupsEnd(w io.Writer) {
230+
fmt.Fprintln(w, "::endgroup::")
227231
}
228232

229233
func SanitizeName(s string, maxLength int) string {

0 commit comments

Comments
 (0)