mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Build/Test Tools: Restore Slack notifications for older branches.
In [51921], the GitHub Actions workflows were updated to utilize the Slack notifications workflow as a callable one instead of on the `workflow_run` event. This eliminated the need for an additional “Slack Notifications” workflow run for every completed workflow, but only when other workflows are updated as well. This resulted in notifications from older branches breaking, as the changes in [51921] were not backported. Instead of backporting the needed changes now (the Slack workflow is still being polished), this commit partially restores the `workflow_run` event for older branches so that notifications will resume. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51934 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
aa37d5ba15
commit
22bb0fee98
40
.github/workflows/slack-notifications.yml
vendored
40
.github/workflows/slack-notifications.yml
vendored
@ -6,6 +6,22 @@
|
||||
name: Slack Notifications
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows:
|
||||
- Code Coverage Report
|
||||
- Coding Standards
|
||||
- End-to-end Tests
|
||||
- JavaScript Tests
|
||||
- PHP Compatibility
|
||||
- PHPUnit Tests
|
||||
- Test NPM
|
||||
- Test old branches
|
||||
types:
|
||||
- completed
|
||||
branches:
|
||||
- '[3-4].[0-9]'
|
||||
- '5.[0-8]'
|
||||
|
||||
workflow_call:
|
||||
secrets:
|
||||
SLACK_GHA_SUCCESS_WEBHOOK:
|
||||
@ -21,6 +37,9 @@ on:
|
||||
description: 'The Slack webhook URL for a failed build.'
|
||||
required: true
|
||||
|
||||
env:
|
||||
CURRENT_BRANCH: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref_name }}
|
||||
|
||||
jobs:
|
||||
# Gathers the details needed for Slack notifications.
|
||||
#
|
||||
@ -28,8 +47,11 @@ jobs:
|
||||
# submit data to Slack webhook URLs configured to post messages.
|
||||
#
|
||||
# Performs the following steps:
|
||||
# - Retrieves the workflow ID (if necessary).
|
||||
# - Retrieves the workflow URL (if necessary).
|
||||
# - Retrieves the previous workflow run and stores its conclusion.
|
||||
# - Sets the previous conclusion as an output.
|
||||
# - Prepares the commit message.
|
||||
# - Constructs and stores a message payload as an output.
|
||||
prepare:
|
||||
name: Prepare notifications
|
||||
@ -42,6 +64,7 @@ jobs:
|
||||
steps:
|
||||
- name: Get the workflow ID
|
||||
id: current-workflow-id
|
||||
if: ${{ github.event_name == 'push' }}
|
||||
uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
|
||||
with:
|
||||
script: |
|
||||
@ -55,6 +78,7 @@ jobs:
|
||||
- name: Get the workflow URL
|
||||
id: current-workflow-url
|
||||
uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
|
||||
if: ${{ github.event_name == 'push' }}
|
||||
with:
|
||||
script: |
|
||||
const workflow_run = await github.rest.actions.getWorkflowRun({
|
||||
@ -72,8 +96,8 @@ jobs:
|
||||
const previous_runs = await github.rest.actions.listWorkflowRuns({
|
||||
owner: '${{ github.repository_owner }}',
|
||||
repo: 'wordpress-develop',
|
||||
workflow_id: ${{ steps.current-workflow-id.outputs.result }},
|
||||
branch: '${{ github.ref_name }}',
|
||||
workflow_id: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.workflow_id || steps.current-workflow-id.outputs.result }},
|
||||
branch: '${{ env.CURRENT_BRANCH }}',
|
||||
per_page: 1,
|
||||
page: 2,
|
||||
});
|
||||
@ -87,21 +111,21 @@ jobs:
|
||||
id: commit-message
|
||||
run: |
|
||||
COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\"/g'
|
||||
${{ github.event.head_commit.message }}
|
||||
${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_commit.message || github.event.head_commit.message }}
|
||||
EOF
|
||||
)
|
||||
echo "::set-output name=commit_message_escaped::${COMMIT_MESSAGE}"
|
||||
|
||||
- name: Construct payload and store as an output
|
||||
id: create-payload
|
||||
run: echo "::set-output name=payload::{\"workflow_name\":\"${{ github.workflow }}\",\"ref_name\":\"${{ github.ref_name }}\",\"run_url\":\"${{ steps.current-workflow-url.outputs.result }}\",\"commit_message\":\"${{ steps.commit-message.outputs.commit_message_escaped }}\"}"
|
||||
run: echo "::set-output name=payload::{\"workflow_name\":\"${{ github.workflow }}\",\"ref_name\":\"${{ env.CURRENT_BRANCH }}\",\"run_url\":\"${{ github.event_name == 'workflow_run' && github.event.workflow_run.html_url || steps.current-workflow-url.outputs.result }}\",\"commit_message\":\"${{ steps.commit-message.outputs.commit_message_escaped }}\"}"
|
||||
|
||||
# Posts notifications when a workflow fails.
|
||||
failure:
|
||||
name: Failure notifications
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ prepare ]
|
||||
if: ${{ failure() }}
|
||||
if: ${{ github.event_name == 'push' && failure() || github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure' }}
|
||||
|
||||
steps:
|
||||
- name: Post failure notifications to Slack
|
||||
@ -116,7 +140,7 @@ jobs:
|
||||
name: Fixed notifications
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ prepare ]
|
||||
if: ${{ needs.prepare.outputs.previous_conclusion == 'failure' && success() }}
|
||||
if: ${{ needs.prepare.outputs.previous_conclusion == 'failure' && ( github.event_name == 'push' && success() || github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' ) }}
|
||||
|
||||
steps:
|
||||
- name: Post failure notifications to Slack
|
||||
@ -131,7 +155,7 @@ jobs:
|
||||
name: Success notifications
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ prepare ]
|
||||
if: ${{ success() }}
|
||||
if: ${{ github.event_name == 'push' && success() || github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' }}
|
||||
|
||||
steps:
|
||||
- name: Post success notifications to Slack
|
||||
@ -146,7 +170,7 @@ jobs:
|
||||
name: Cancelled notifications
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ prepare ]
|
||||
if: ${{ cancelled() }}
|
||||
if: ${{ github.event_name == 'push' && cancelled() || github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'cancelled' }}
|
||||
|
||||
steps:
|
||||
- name: Post cancelled notifications to Slack
|
||||
|
||||
Loading…
Reference in New Issue
Block a user