Skip to content

Commit

Permalink
adds Slack notification
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra committed Dec 18, 2023
1 parent 10b7a54 commit fe8957a
Showing 1 changed file with 157 additions and 2 deletions.
159 changes: 157 additions & 2 deletions .github/workflows/client-compatability-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
client: erigon
pyroscope_env: ci-smoke-ocr2-evm-simulated
runs-on: ubuntu-latest
name: ETH Smoke Tests ${{ matrix.product.name }}
name: Client Compatability Test ${{ matrix.product.name }}
steps:
- name: Checkout the repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand Down Expand Up @@ -253,4 +253,159 @@ jobs:
fi
else
echo "No test summary folder found. If no test failed or log collection wasn't explicitly requested this is correct. Exiting"
fi
fi
start-slack-thread:
name: Start Slack Thread
if: ${{ always() && needs.*.result != 'skipped' && needs.*.result != 'cancelled' }}
environment: integration
outputs:
thread_ts: ${{ steps.slack.outputs.thread_ts }}
permissions:
checks: write
pull-requests: write
id-token: write
contents: read
runs-on: ubuntu-latest
needs: [client-compatability-matrix]
steps:
- name: Debug Result
run: echo ${{ join(needs.*.result, ',') }}
- name: Main Slack Notification
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
id: slack
with:
channel-id: ${{ secrets.QA_SLACK_CHANNEL }}
payload: |
{
"attachments": [
{
"color": "${{ contains(join(needs.*.result, ','), 'failure') && '#C62828' || '#2E7D32' }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Live Smoke Test Results ${{ contains(join(needs.*.result, ','), 'failure') && ':x:' || ':white_check_mark:'}}",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ contains(join(needs.*.result, ','), 'failure') && 'Some tests failed, notifying <@U01Q4N37KFG> and <@U060CGGPY8H>' || 'All Good!' }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }}|${{ github.ref_name }}> | <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}> | <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Run>"
}
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.QA_SLACK_API_KEY }}

post-test-results-to-slack:
name: Post Test Results for ${{matrix.product}}-${{matrix.client}}
if: ${{ always() && needs.*.result != 'skipped' && needs.*.result != 'cancelled' }}
environment: integration
permissions:
checks: write
pull-requests: write
id-token: write
contents: read
runs-on: ubuntu-latest
needs: start-slack-thread
strategy:
fail-fast: false
matrix:
product: [ocr, ocr2]
client: [geth, besu, erigon]
steps:
- name: Get Results
id: test-results
run: |
# I feel like there's some clever, fully jq way to do this, but I ain't got the motivation to figure it out
echo "Querying test results"
PARSED_RESULTS=$(curl \
-H "Authorization: Bearer ${{ github.token }}" \
'https://api.github.com/repos/${{github.repository}}/actions/runs/${{ github.run_id }}/jobs' \
| jq -r --arg pattern "^Client Compatability Test (?<product>.*?)$" '.jobs[]
| select(.name | test($pattern)) as $job
| $job.steps[]
| select(.name == "Run Tests")
| { conclusion: (if .conclusion == "success" then ":white_check_mark:" else ":x:" end), product: ("*" + ($job.name | capture($pattern).product) + "*") }')
echo "Parsed Results:"
echo $PARSED_RESULTS
ALL_SUCCESS=true
echo "Checking for failures"
echo "$PARSED_RESULTS" | jq -s | jq -r '.[] | select(.conclusion != ":white_check_mark:")'
for row in $(echo "$PARSED_RESULTS" | jq -s | jq -r '.[] | select(.conclusion != ":white_check_mark:")'); do
ALL_SUCCESS=false
break
done
echo "Success: $ALL_SUCCESS"
echo all_success=$ALL_SUCCESS >> $GITHUB_OUTPUT
FORMATTED_RESULTS=$(echo $PARSED_RESULTS | jq -s '[.[]
| {
conclusion: .conclusion,
product: .product
}
]
| map("{\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \"\(.product): \(.conclusion)\"}}")
| join(",")')
echo "Formatted Results:"
echo $FORMATTED_RESULTS
# Cleans out backslashes and quotes from jq
CLEAN_RESULTS=$(echo "$FORMATTED_RESULTS" | sed 's/\\\"/"/g' | sed 's/^"//;s/"$//')
echo "Clean Results"
echo $CLEAN_RESULTS
echo results=$CLEAN_RESULTS >> $GITHUB_OUTPUT
- name: Test Details
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
with:
channel-id: ${{ secrets.QA_SLACK_CHANNEL }}
payload: |
{
"thread_ts": "${{ needs.start-slack-thread.outputs.thread_ts }}",
"attachments": [
{
"color": "${{ steps.test-results.outputs.all_success == 'true' && '#2E7D32' || '#C62828' }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{matrix.product}}-${{matrix.client}} ${{ steps.test-results.outputs.all_success == 'true' && ':white_check_mark:' || ':x:'}}",
"emoji": true
}
},
{
"type": "divider"
},
${{ steps.test-results.outputs.results }}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.QA_SLACK_API_KEY }}

0 comments on commit fe8957a

Please sign in to comment.