From 97883a58d0e1017a83d13e1f3de292408314ec05 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Tue, 10 May 2022 15:59:22 +0800 Subject: [PATCH] Add GitHub Action step summary for better experience (#104) --- commands/header_check.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/commands/header_check.go b/commands/header_check.go index e0ec2e1..7d99d6b 100644 --- a/commands/header_check.go +++ b/commands/header_check.go @@ -18,6 +18,9 @@ package commands import ( + "fmt" + "os" + "github.com/apache/skywalking-eyes/internal/logger" "github.com/apache/skywalking-eyes/pkg/header" "github.com/apache/skywalking-eyes/pkg/review" @@ -43,6 +46,8 @@ var CheckCommand = &cobra.Command{ logger.Log.Infoln(result.String()) + writeSummaryQuietly(&result) + if result.HasFailure() { if err := review.Header(&result, &Config); err != nil { logger.Log.Warnln("Failed to create review comments", err) @@ -53,3 +58,19 @@ var CheckCommand = &cobra.Command{ return nil }, } + +func writeSummaryQuietly(result *header.Result) { + if summaryFileName := os.Getenv("GITHUB_STEP_SUMMARY"); summaryFileName != "" { + if summaryFile, err := os.OpenFile(summaryFileName, os.O_WRONLY|os.O_APPEND, 0o644); err == nil { + defer summaryFile.Close() + _, _ = summaryFile.WriteString("# License Eye Summary\n") + _, _ = summaryFile.WriteString(result.String()) + if result.HasFailure() { + _, _ = summaryFile.WriteString(", the following files are lack of license headers:\n") + for _, failure := range result.Failure { + _, _ = summaryFile.WriteString(fmt.Sprintf("- %s\n", failure)) + } + } + } + } +}