Skip to content

Commit

Permalink
Add GitHub Action step summary for better experience (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
kezhenxu94 authored May 10, 2022
1 parent 78aa037 commit 97883a5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions commands/header_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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))
}
}
}
}
}

0 comments on commit 97883a5

Please sign in to comment.