mirror of
https://github.com/mattermost/mattermost.git
synced 2026-08-26 21:27:40 -05:00
Move flaky test report from PR comment to Mattermost channel (#36965)
* Move flaky test report from PR comment to Mattermost channel Replace the github-script step that posted the flaky test summary as a PR comment with a step that posts the summary to a Mattermost channel via a new Mattermost incoming webhook (WEBHOOK_URL_FLAKY_TEST_MM). The HTML <table> summary is converted to a Markdown table, with content pipes escaped and HTML entities decoded. The existing custom flaky-test hub webhook is left untouched. Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> * Hoist github.server_url into SERVER_URL env var Keep all GitHub Actions context expressions in the step's env block for consistency, and build PR_URL purely from shell variables. Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor Agent
parent
27b2525e88
commit
b7dda3435c
@@ -112,24 +112,58 @@ jobs:
|
||||
include_passed: true
|
||||
check_annotations: true
|
||||
|
||||
- name: Report retried tests (pull request)
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
||||
if: ${{ steps.report.outputs.flaky_summary != '<table><tr><th>Test</th><th>Retries</th></tr></table>' && steps.report.outputs.failed == '0' && github.event.workflow_run.event == 'pull_request' }}
|
||||
- name: Report retried tests to Mattermost channel (pull request)
|
||||
if: >-
|
||||
steps.report.outputs.flaky_summary != '<table><tr><th>Test</th><th>Retries</th></tr></table>'
|
||||
&& steps.report.outputs.failed == '0'
|
||||
&& github.event.workflow_run.event == 'pull_request'
|
||||
&& env.WEBHOOK_URL_FLAKY_TEST_MM != ''
|
||||
continue-on-error: true
|
||||
env:
|
||||
FLAKY_SUMMARY: "${{ steps.report.outputs.flaky_summary }}"
|
||||
PR_NUMBER: "${{ steps.incoming-pr.outputs.NUMBER }}"
|
||||
TEST_NAME: "${{ matrix.test.name }}"
|
||||
WEBHOOK_URL_FLAKY_TEST_MM: ${{ secrets.WEBHOOK_URL_FLAKY_TEST_MM }}
|
||||
FLAKY_SUMMARY: ${{ steps.report.outputs.flaky_summary }}
|
||||
PR_NUMBER: ${{ steps.incoming-pr.outputs.NUMBER }}
|
||||
TEST_NAME: ${{ matrix.test.name }}
|
||||
REPO: ${{ github.repository }}
|
||||
WORKFLOW_RUN_HTML_URL: ${{ github.event.workflow_run.html_url }}
|
||||
with:
|
||||
script: |
|
||||
const body = `#### ⚠️ One or more flaky tests detected ⚠️\n* Workflow run: [github.com/mattermost/mattermost:${process.env.TEST_NAME}](${process.env.WORKFLOW_RUN_HTML_URL})\n* Double check your code to ensure you have not introduced a flaky test.\n\n${process.env.FLAKY_SUMMARY}`
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
run: |
|
||||
PR_URL="${SERVER_URL}/${REPO}/pull/${PR_NUMBER}"
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
issue_number: process.env.PR_NUMBER,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: body
|
||||
})
|
||||
# Convert the HTML <table> flaky summary into a Mattermost markdown table.
|
||||
# Escape content pipes FIRST (HTML tags contain no '|', so any '|' is cell
|
||||
# text), then strip tags, decode entities, and build delimiters.
|
||||
TABLE_MD=$(printf '%s' "$FLAKY_SUMMARY" \
|
||||
| sed -E 's#\|#\\|#g' \
|
||||
| sed -E 's#</tr>#\n#g; s#<tr>##g; s#</?t(head|body)>##g' \
|
||||
| sed -E 's#</?table>##g' \
|
||||
| sed -E 's#<#<#g; s#>#>#g; s#&#\&#g; s#"#"#g' \
|
||||
| sed -E 's#<th>([^<]*)</th>#| \1 #g; s#<td>([^<]*)</td>#| \1 #g' \
|
||||
| sed -E 's#[[:space:]]*$# |#' \
|
||||
| sed '/^[[:space:]|]*$/d')
|
||||
# Insert markdown header separator after the first (header) row
|
||||
TABLE_MD=$(printf '%s' "$TABLE_MD" \
|
||||
| awk 'NR==1{print; print "|---|---|"; next} {print}')
|
||||
|
||||
# Use real newlines; a literal "\n" renders verbatim in Mattermost.
|
||||
NL=$'\n'
|
||||
TEXT=":warning: **Flaky test(s) detected** in [${REPO}#${PR_NUMBER}](${PR_URL})"
|
||||
TEXT="${TEXT}${NL}_Test job:_ [${TEST_NAME}](${WORKFLOW_RUN_HTML_URL})${NL}${NL}${TABLE_MD}"
|
||||
|
||||
PAYLOAD=$(jq -n \
|
||||
--arg text "$TEXT" \
|
||||
'{
|
||||
username: "Flaky Test Report",
|
||||
icon_url: "https://mattermost.com/wp-content/uploads/2022/02/icon_WS.png",
|
||||
attachments: [{color: "#CCCC00", text: $text}]
|
||||
}')
|
||||
|
||||
curl -X POST -fsSL \
|
||||
--connect-timeout 5 \
|
||||
--max-time 30 \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$PAYLOAD" \
|
||||
"$WEBHOOK_URL_FLAKY_TEST_MM"
|
||||
|
||||
- name: Report retried tests to flaky-test webhook (pull request)
|
||||
if: >-
|
||||
|
||||
Reference in New Issue
Block a user