From 08117b665120e1266254894c0ca2fa5557eb2774 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 17 Jul 2024 11:00:41 -0700 Subject: [PATCH] ci: fix slack matrix notifications --- .github/workflows/e2e.yml | 42 ++++++++++++++++++++++++++++++ .github/workflows/reusable-e2e.yml | 9 ------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index aab15adf8f..bad91908b5 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -165,6 +165,48 @@ jobs: - e2e if: always() steps: + - name: Send slack message with results + uses: actions/github-script@v7 + if: ${{ github.event_name == 'schedule' || (github.event_name == 'push' && needs.e2e.result == 'failed') }} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_INTEGRATION_TESTING_WEBHOOK }} + with: + script: | + const {data} = await github.rest.actions.listJobsForWorkflowRunAttempt({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId, + attempt_number: ${{ github.run_attempt }}, + }); + + const e2eJobs = data.jobs.filter(job => job.name.includes('/') && job.conclusion != 'skipped'); + + const e2eResults = e2eJobs.map(job => { + const icon = job.conclusion === 'success' ? ':white_check_mark:' : ':x:'; + const cleanName = job.name.split("/")[0]; + return `${icon} ${cleanName}`; + }); + + const overallResultStr = '${{ needs.e2e.result }}'; + const overallResultPassing = overallResultStr === 'success' || overallResultStr === 'skipped'; + const overallResultIcon = overallResultPassing ? ':white_check_mark:' : ':x:'; + let overallResultText = ``; + if (context.eventName === 'push') { + overallResultText += ` for push to ${context.ref}`; + } else if (context.eventName === 'schedule') { + overallResultText += ` for scheduled run`; + } + const msg = `${overallResultIcon} ${overallResultText}\n${e2eResults.join('\n')}`; + + await fetch(process.env.SLACK_WEBHOOK_URL, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({text: msg}), + }); + + - run: | result="${{ needs.e2e.result }}" if [[ $result == "success" || $result == "skipped" ]]; then diff --git a/.github/workflows/reusable-e2e.yml b/.github/workflows/reusable-e2e.yml index d67f53db0e..ab2181f41b 100644 --- a/.github/workflows/reusable-e2e.yml +++ b/.github/workflows/reusable-e2e.yml @@ -100,15 +100,6 @@ jobs: name: ${{ inputs.make-target }}-docker-logs path: /tmp/logs.txt - - name: Notify Slack on Failure - if: failure() && (github.event_name == 'push' || github.event_name == 'schedule') - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,action,eventName,ref,workflow,job,took - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_CI_ALERTS }} - - name: Stop Private Network if: always() run: |