@@ -21,6 +21,122 @@ func WriteErrorAnnotation(statusCode int, errorCode, message, ruleName string, r
2121 writeJobSummary (statusCode , errorCode , message , ruleName , retryAfter , details )
2222}
2323
24+ // WriteSuccessSummary writes a GitHub Actions job summary for successful deployment tracking
25+ func WriteSuccessSummary (action , environment , status , version , scmSha , deployURL string ) {
26+ // Only write summaries if running in GitHub Actions
27+ if os .Getenv ("GITHUB_ACTIONS" ) != "true" {
28+ return
29+ }
30+
31+ summaryPath := os .Getenv ("GITHUB_STEP_SUMMARY" )
32+ if summaryPath == "" {
33+ return
34+ }
35+
36+ // Build the summary
37+ var summary string
38+ summary += "## 🚀 Versioner Summary\n \n "
39+
40+ // Add key information
41+ summary += fmt .Sprintf ("- **Action:** %s\n " , action )
42+ summary += fmt .Sprintf ("- **Environment:** %s\n " , environment )
43+ summary += fmt .Sprintf ("- **Status:** %s\n " , formatStatus (status ))
44+ summary += fmt .Sprintf ("- **Version:** `%s`\n " , version )
45+
46+ if scmSha != "" {
47+ summary += fmt .Sprintf ("- **Git SHA:** `%s`\n " , scmSha )
48+ }
49+
50+ if deployURL != "" {
51+ summary += fmt .Sprintf ("\n [View Deployment Run →](%s)\n " , deployURL )
52+ }
53+
54+ // Write to file
55+ f , err := os .OpenFile (summaryPath , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
56+ if err != nil {
57+ // Silently fail - don't break the CLI if we can't write the summary
58+ return
59+ }
60+ defer f .Close ()
61+
62+ _ , _ = f .WriteString (summary )
63+ }
64+
65+ // WriteGenericErrorAnnotation writes a GitHub Actions error annotation for generic failures
66+ // (API errors, network errors, etc.)
67+ func WriteGenericErrorAnnotation (action , errorType , errorMessage string ) {
68+ // Only write annotations if running in GitHub Actions
69+ if os .Getenv ("GITHUB_ACTIONS" ) != "true" {
70+ return
71+ }
72+
73+ summaryPath := os .Getenv ("GITHUB_STEP_SUMMARY" )
74+ if summaryPath == "" {
75+ return
76+ }
77+
78+ // Write workflow command annotation
79+ title := fmt .Sprintf ("Versioner %s Failed" , action )
80+ escapedMessage := escapeWorkflowCommand (errorMessage )
81+ fmt .Fprintf (os .Stdout , "::error title=%s::%s\n " , title , escapedMessage )
82+
83+ // Build the summary
84+ var summary string
85+ summary += fmt .Sprintf ("## ❌ Versioner %s Failed\n \n " , action )
86+ summary += fmt .Sprintf ("### %s\n \n " , errorType )
87+ summary += fmt .Sprintf ("**Error:** %s\n \n " , errorMessage )
88+
89+ summary += "**Possible Causes:**\n "
90+ switch errorType {
91+ case "API Error" :
92+ summary += "- Invalid API key or authentication failure\n "
93+ summary += "- Validation error (check required fields)\n "
94+ summary += "- API service unavailable\n "
95+ summary += "- Rate limiting or quota exceeded\n "
96+ case "Network Error" :
97+ summary += "- Network connectivity issues\n "
98+ summary += "- DNS resolution failure\n "
99+ summary += "- API endpoint unreachable\n "
100+ summary += "- Timeout or connection refused\n "
101+ default :
102+ summary += "- Check error message above for details\n "
103+ }
104+
105+ summary += "\n **Action Required:**\n "
106+ summary += "- Verify your `VERSIONER_API_KEY` is set correctly\n "
107+ summary += "- Check network connectivity to Versioner API\n "
108+ summary += "- Review error message for specific guidance\n "
109+ summary += "- Contact support if issue persists\n "
110+
111+ // Write to file
112+ f , err := os .OpenFile (summaryPath , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
113+ if err != nil {
114+ // Silently fail - don't break the CLI if we can't write the summary
115+ return
116+ }
117+ defer f .Close ()
118+
119+ _ , _ = f .WriteString (summary )
120+ }
121+
122+ // formatStatus adds an emoji to the status for visual clarity
123+ func formatStatus (status string ) string {
124+ switch status {
125+ case "started" , "in_progress" :
126+ return "⏳ " + status
127+ case "completed" , "success" :
128+ return "✅ " + status
129+ case "failed" :
130+ return "❌ " + status
131+ case "aborted" , "cancelled" :
132+ return "🚫 " + status
133+ case "pending" :
134+ return "⏸️ " + status
135+ default :
136+ return status
137+ }
138+ }
139+
24140// writeWorkflowCommand outputs a GitHub Actions workflow command for error annotation
25141func writeWorkflowCommand (statusCode int , errorCode , message , ruleName string ) {
26142 // Format: ::error title=<title>::<message>
0 commit comments