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

[DNM] test adding slack notification for test summaries #10211

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ inputs:
matrix-label:
required: true
description: The version of the matrix being used - used to name artifacts to prevent filename collisions
slackbot-bearer:
required: true
description: The secret bearer token for the slackbot integration

runs:
using: "composite"
Expand All @@ -37,6 +40,7 @@ runs:
shell: bash
run: make go-test
- name: Summarize tests
if: ${{ always() }}
Copy link
Contributor

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

# Print out a summary of ALL tests run under this action. In the future we can use this tool
# with the --json flag to export the results for centralized processing.
shell: bash
Expand All @@ -53,3 +57,12 @@ runs:
with:
name: go-test-summary-${{ inputs.cluster-name }}-${{ inputs.matrix-label }}-attempt-${{ github.run_attempt }}
path: ./_test/test_log/go-test-summary
- name: Send Slack Message
if: ${{ always() }}
env:
SLACKBOT_BEARER: ${{ inputs.slackbot-bearer }}
# SLACK_CHANNEL: C04CJMXAH7A #edge-nightly-results by default
SLACK_CHANNEL: C0314KESVNV #slack-integration-testing for testing
shell: bash
run: |
go run .github/workflows/helpers/notify/slack_test_summary.go './_test/test_log/go-test-summary'
85 changes: 85 additions & 0 deletions .github/workflows/helpers/notify/slack_test_summary.go
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))

}
1 change: 1 addition & 0 deletions .github/workflows/nightly-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jobs:
run-regex: ${{ matrix.test.go-test-run-regex }}
istio-version: ${{ steps.dotenv.outputs.istio_version }}
matrix-label: ${{ matrix.version-files.label }}
slackbot-bearer: ${{ secrets.SLACKBOT_BEARER }}

end_to_end_tests_main:
name: End-to-End (branch=main, cluster=${{ matrix.test.cluster-name }}, version=${{ matrix.version-files.label }} )
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-kubernetes-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ jobs:
run-regex: ${{ matrix.test.go-test-run-regex }}
istio-version: ${{ steps.dotenv.outputs.istio_version }}
matrix-label: "pr"
slackbot-bearer: ${{ secrets.SLACKBOT_BEARER }}
Loading