-
Notifications
You must be signed in to change notification settings - Fork 438
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
[DNM] test adding slack notification for test summaries #10211
Open
jbohanon
wants to merge
8
commits into
main
Choose a base branch
from
jbohanon/test-summaries-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4407e34
test adding slack notification
jbohanon 27c838a
appease the error messages?
jbohanon f36c483
don't use outdated stack overflow code
jbohanon 37b4046
uhh
jbohanon b512a51
try this again I guess?
jbohanon de6a98e
idiot...
jbohanon be2d1d5
pass in the secret from the top-level workflow
jbohanon 7a32f65
separate script
jbohanon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Helper script designed to send a cohesive Slack notification about the result of a collection of GitHub workflows | ||
// This is a simpler variant of notify-from-json.go, due to some issues we | ||
// encountered around the accuracy of the notification: https://github.com/solo-io/solo-projects/issues/5191 | ||
// | ||
// This works by: | ||
// 1. Read in the test summary | ||
// 2. Send a Slack notification with the contents | ||
// | ||
// Example usage: | ||
// export SLACKBOT_BEARER=${{ secrets.SLACKBOT_BEARER }} | ||
// export SLACK_CHANNEL=C0314KESVNV | ||
// go run .github/workflows/helpers/notify/slack_test_summary.go ./_test/test_log/go-test-summary | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"time" | ||
) | ||
|
||
const ( | ||
postMessageEndpoint = "https://slack.com/api/chat.postMessage" | ||
) | ||
|
||
type Payload struct { | ||
Channel string `json:"channel"` | ||
Text string `json:"text"` | ||
} | ||
|
||
func main() { | ||
summaryFile := os.Args[1] | ||
fmt.Printf("slack_test_summary.go invoked with: %v", summaryFile) | ||
|
||
b, err := os.ReadFile(summaryFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
mustSendSlackText(string(b)) | ||
} | ||
|
||
func mustSendSlackText(text string) { | ||
fmt.Printf("send slack message with text: %s", text) | ||
mustSendSlackMessage(Payload{ | ||
Channel: os.ExpandEnv("$SLACK_CHANNEL"), | ||
Text: os.ExpandEnv(text), | ||
}) | ||
} | ||
|
||
func mustSendSlackMessage(data Payload) { | ||
payloadBytes, err := json.Marshal(data) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodPost, postMessageEndpoint, bytes.NewReader(payloadBytes)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
req.Header.Set("Authorization", os.ExpandEnv("Bearer $SLACKBOT_BEARER")) | ||
|
||
var netClient = &http.Client{ | ||
Timeout: time.Second * 10, | ||
} | ||
|
||
resp, err := netClient.Do(req) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
fmt.Println(resp.Status) | ||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(string(b)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my summarize wasnt always before? woof