Skip to content

Commit

Permalink
Merge branch 'develop' into remove_core_utils_from_evm
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantkumar1982 committed Dec 21, 2023
2 parents f3c97c9 + c5aa49b commit 090098d
Show file tree
Hide file tree
Showing 10 changed files with 490 additions and 171 deletions.
37 changes: 37 additions & 0 deletions .github/actions/notify-slack-jobs-result/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Notify Slack Jobs Result

Sends a Slack message to a specified channel detailing the results of one to many GHA job results using a regex. The job results will be grouped by the `github_job_name_regex` and displayed underneath the `message_title`, with the regex matching group displayed as an individual result. This is primarily designed for when you have test groups running in a matrix, and would like condensed reporting on their status by group. It's often accompanied by posting a Slack message before to start a thread, then attaching all the results to that thread like we do in the reporting section of the [live-testnet-test.yml workflow](../../workflows/live-testnet-tests.yml). Check out the example below, where we post an initial summary message, then use this action to thread together specific results:

```yaml
message_title: Optimism Goerli
github_job_name_regex: ^Optimism Goerli (?<cap>.*?) Tests$ # Note that the regex MUST have a capturing group named "cap"
```
![example](image.png)
## Inputs
```yaml
inputs:
github_token:
description: "The GitHub token to use for authentication (usually ${{ github.token }})"
required: true
github_repository:
description: "The GitHub owner/repository to use for authentication (usually ${{ github.repository }}))"
required: true
workflow_run_id:
description: "The workflow run ID to get the results from (usually ${{ github.run_id }})"
required: true
github_job_name_regex:
description: "The regex to use to match 1..many job name(s) to collect results from. Should include a capture group named 'cap' for the part of the job name you want to display in the Slack message (e.g. ^Client Compatability Test (?<cap>.*?)$)"
required: true
message_title:
description: "The title of the Slack message"
required: true
slack_channel_id:
description: "The Slack channel ID to post the message to"
required: true
slack_thread_ts:
description: "The Slack thread timestamp to post the message to, handy for keeping multiple related results in a single thread"
required: false
```
110 changes: 110 additions & 0 deletions .github/actions/notify-slack-jobs-result/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Notify Slack Jobs Result
description: Will send a notification in Slack for the result of a GitHub action run, typically for test results
inputs:
github_token:
description: "The GitHub token to use for authentication (usually github.token)"
required: true
github_repository:
description: "The GitHub owner/repository to use for authentication (usually github.repository))"
required: true
workflow_run_id:
description: "The workflow run ID to get the results from (usually github.run_id)"
required: true
github_job_name_regex:
description: "The regex to use to match 1..many job name(s) to collect results from. Should include a capture group named 'cap' for the part of the job name you want to display in the Slack message (e.g. ^Client Compatability Test (?<cap>.*?)$)"
required: true
message_title:
description: "The title of the Slack message"
required: true
slack_channel_id:
description: "The Slack channel ID to post the message to"
required: true
slack_bot_token:
description: "The Slack bot token to use for authentication which needs permission and an installed app in the channel"
required: true
slack_thread_ts:
description: "The Slack thread timestamp to post the message to, handy for keeping multiple related results in a single thread"
required: false

runs:
using: composite
steps:
- name: Get Results
shell: bash
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 at https://api.github.com/repos/${{inputs.github_repository}}/actions/runs/${{ inputs.workflow_run_id }}/jobs"
PARSED_RESULTS=$(curl \
-H "Authorization: Bearer ${{ inputs.github_token }}" \
'https://api.github.com/repos/${{inputs.github_repository}}/actions/runs/${{ inputs.workflow_run_id }}/jobs' \
| jq -r --arg pattern "${{ inputs.github_job_name_regex }}" '.jobs[]
| select(.name | test($pattern)) as $job
| $job.steps[]
| select(.name == "Run Tests")
| { conclusion: (if .conclusion == "success" then ":white_check_mark:" else ":x:" end), cap: ("*" + ($job.name | capture($pattern).cap) + "*"), html_url: $job.html_url }')
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,
cap: .cap,
html_url: .html_url
}
]
| map("{\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \"<\(.html_url)|\(.cap)>: \(.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: Post Results
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
env:
SLACK_BOT_TOKEN: ${{ inputs.slack_bot_token }}
with:
channel-id: ${{ inputs.slack_channel_id }}
payload: |
{
"thread_ts": "${{ inputs.slack_thread_ts }}",
"attachments": [
{
"color": "${{ steps.test-results.outputs.all_success == 'true' && '#2E7D32' || '#C62828' }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ inputs.message_title }} ${{ steps.test-results.outputs.all_success == 'true' && ':white_check_mark:' || ':x:'}}",
"emoji": true
}
},
{
"type": "divider"
},
${{ steps.test-results.outputs.results }}
]
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 090098d

Please sign in to comment.