@@ -422,19 +422,25 @@ func main() {
422422 // Build standalone yaml file for this group
423423 {
424424 output := & bytes.Buffer {}
425- for i , tempInfo := range templateGroup .Templates {
425+ for _ , tempInfo := range templateGroup .Templates {
426426 if tempInfo .Predicate == nil || tempInfo .Predicate (templateOptions , false ) {
427427 name := tempInfo .Name
428428 t , err := template .New (name ).ParseFiles (filepath .Join (options .TemplatesDir , group , name ))
429429 if err != nil {
430430 log .Fatalf ("Failed to parse template %s: %v" , name , err )
431431 }
432- if i > 0 {
433- output .WriteString ("\n ---\n \n " )
432+ // Execute to tmp buffer
433+ tmpBuf := & bytes.Buffer {}
434+ t .Execute (tmpBuf , templateOptions )
435+ // Add tmp buffer to output, unless empty
436+ if strings .TrimSpace (tmpBuf .String ()) != "" {
437+ if output .Len () > 0 {
438+ output .WriteString ("\n ---\n \n " )
439+ }
440+ output .WriteString (fmt .Sprintf ("## %s/%s\n " , group , name ))
441+ tmpBuf .WriteTo (output )
442+ output .WriteString ("\n " )
434443 }
435- output .WriteString (fmt .Sprintf ("## %s/%s\n " , group , name ))
436- t .Execute (output , templateOptions )
437- output .WriteString ("\n " )
438444 }
439445 }
440446
@@ -457,19 +463,25 @@ func main() {
457463 // Build helm template file for this group
458464 {
459465 output := & bytes.Buffer {}
460- for i , tempInfo := range templateGroup .Templates {
466+ for _ , tempInfo := range templateGroup .Templates {
461467 if tempInfo .Predicate == nil || tempInfo .Predicate (chartTemplateOptions , true ) {
462468 name := tempInfo .Name
463469 t , err := template .New (name ).ParseFiles (filepath .Join (options .TemplatesDir , group , name ))
464470 if err != nil {
465471 log .Fatalf ("Failed to parse template %s: %v" , name , err )
466472 }
467- if i > 0 {
468- output .WriteString ("\n ---\n \n " )
473+ // Execute to tmp buffer
474+ tmpBuf := & bytes.Buffer {}
475+ t .Execute (tmpBuf , templateOptions )
476+ // Add tmp buffer to output, unless empty
477+ if strings .TrimSpace (tmpBuf .String ()) != "" {
478+ if output .Len () > 0 {
479+ output .WriteString ("\n ---\n \n " )
480+ }
481+ output .WriteString (fmt .Sprintf ("## %s/%s\n " , group , name ))
482+ tmpBuf .WriteTo (output )
483+ output .WriteString ("\n " )
469484 }
470- output .WriteString (fmt .Sprintf ("## %s/%s\n " , group , name ))
471- t .Execute (output , chartTemplateOptions )
472- output .WriteString ("\n " )
473485 }
474486 }
475487
0 commit comments