diff --git a/.github/workflows/server-ci-report.yml b/.github/workflows/server-ci-report.yml
index 9f0335bc8fe..ca4dd45a65b 100644
--- a/.github/workflows/server-ci-report.yml
+++ b/.github/workflows/server-ci-report.yml
@@ -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 != '
' && 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 != ''
+ && 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 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##\n#g; s###g; s#?t(head|body)>##g' \
+ | sed -E 's#?table>##g' \
+ | sed -E 's#<#<#g; s#>#>#g; s#&#\g; s#"#"#g' \
+ | sed -E 's#| ([^<]*) | #| \1 #g; s#([^<]*) | #| \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: >-