Skip to content

Commit 97883a5

Browse files
authored
Add GitHub Action step summary for better experience (#104)
1 parent 78aa037 commit 97883a5

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

commands/header_check.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
package commands
1919

2020
import (
21+
"fmt"
22+
"os"
23+
2124
"github.com/apache/skywalking-eyes/internal/logger"
2225
"github.com/apache/skywalking-eyes/pkg/header"
2326
"github.com/apache/skywalking-eyes/pkg/review"
@@ -43,6 +46,8 @@ var CheckCommand = &cobra.Command{
4346

4447
logger.Log.Infoln(result.String())
4548

49+
writeSummaryQuietly(&result)
50+
4651
if result.HasFailure() {
4752
if err := review.Header(&result, &Config); err != nil {
4853
logger.Log.Warnln("Failed to create review comments", err)
@@ -53,3 +58,19 @@ var CheckCommand = &cobra.Command{
5358
return nil
5459
},
5560
}
61+
62+
func writeSummaryQuietly(result *header.Result) {
63+
if summaryFileName := os.Getenv("GITHUB_STEP_SUMMARY"); summaryFileName != "" {
64+
if summaryFile, err := os.OpenFile(summaryFileName, os.O_WRONLY|os.O_APPEND, 0o644); err == nil {
65+
defer summaryFile.Close()
66+
_, _ = summaryFile.WriteString("# License Eye Summary\n")
67+
_, _ = summaryFile.WriteString(result.String())
68+
if result.HasFailure() {
69+
_, _ = summaryFile.WriteString(", the following files are lack of license headers:\n")
70+
for _, failure := range result.Failure {
71+
_, _ = summaryFile.WriteString(fmt.Sprintf("- %s\n", failure))
72+
}
73+
}
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)