Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action step summary for better experience #104

Merged
merged 1 commit into from
May 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
}
}
}