From b7dda3435c3f2f355619fc52d385b241e765e0ea Mon Sep 17 00:00:00 2001 From: Maria A Nunez Date: Mon, 8 Jun 2026 15:16:46 -0400 Subject: [PATCH] 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 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 * 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 --------- Co-authored-by: Cursor Agent --- .github/workflows/server-ci-report.yml | 64 ++++++++++++++++++++------ 1 file changed, 49 insertions(+), 15 deletions(-) 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 != '
TestRetries
' && 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 != '
TestRetries
' + && 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###g' \ + | sed -E 's###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: >-
([^<]*)([^<]*)