mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 12:58:25 +01:00
Build/Test Tools: Remove the workflow_run
event from the Slack notification workflow.
The `workflow_run` event was added to restore Slack notifications for older branches (5.8 and older) without having to backport any changes while alternate approaches were explored. The workflow has been tested and refined as a reusable one in `trunk`, and this approach is superior to the `workflow_run` event in several ways. Primarily, the `workflow_run` event results in a separate workflow run being created for sending Slack notifications after the completion of each workflow triggered by `push`. When called as a reusable workflow, this does not happen and the additional jobs are instead added to the initial workflow. This makes which jobs are sending notifications for the current workflow more clear, and reduces the amount of noise (less workflow runs overall). The `workflow_run` event also makes some data available in different ways than `push` events. By removing it, much of the logic within the workflow can be simplified. See #56095. git-svn-id: https://develop.svn.wordpress.org/trunk@53591 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f1b3ce0902
commit
d75d6ca550
40
.github/workflows/slack-notifications.yml
vendored
40
.github/workflows/slack-notifications.yml
vendored
@ -6,22 +6,6 @@
|
||||
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:
|
||||
inputs:
|
||||
calling_status:
|
||||
@ -43,7 +27,7 @@ on:
|
||||
required: true
|
||||
|
||||
env:
|
||||
CURRENT_BRANCH: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref_name }}
|
||||
CURRENT_BRANCH: ${{ github.ref_name }}
|
||||
|
||||
jobs:
|
||||
# Gathers the details needed for Slack notifications.
|
||||
@ -69,7 +53,6 @@ jobs:
|
||||
steps:
|
||||
- name: Determine the status of the previous attempt
|
||||
id: previous-attempt-result
|
||||
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
|
||||
uses: actions/github-script@7a5c598405937d486b0331594b5da2b14db670da # v6.1.0
|
||||
with:
|
||||
script: |
|
||||
@ -91,18 +74,11 @@ jobs:
|
||||
return previous_run.data.conclusion;
|
||||
}
|
||||
|
||||
let workflow_id = '';
|
||||
if ( ${{ github.event_name == 'workflow_run' }} ) {
|
||||
workflow_id = '${{ github.event.workflow_run.workflow_id }}';
|
||||
} else {
|
||||
workflow_id = workflow_run.data.workflow_id;
|
||||
}
|
||||
|
||||
// Otherwise, check the previous workflow run.
|
||||
const previous_runs = await github.rest.actions.listWorkflowRuns({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
workflow_id: workflow_id,
|
||||
workflow_id: workflow_run.data.workflow_id,
|
||||
branch: '${{ env.CURRENT_BRANCH }}',
|
||||
exclude_pull_requests: true,
|
||||
});
|
||||
@ -155,14 +131,14 @@ jobs:
|
||||
id: commit-message
|
||||
run: |
|
||||
COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\\\"/g' | sed 's/\$/\\$/g'
|
||||
${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_commit.message || ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && fromJson( steps.current-commit-message.outputs.result ) || github.event.head_commit.message }}
|
||||
${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && fromJson( steps.current-commit-message.outputs.result ) || 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.event_name == 'workflow_run' && github.event.workflow_run.name || github.workflow }}\",\"ref_name\":\"${{ env.CURRENT_BRANCH }}\",\"run_url\":\"https://github.com/WordPress/wordpress-develop/actions/runs/${{ github.event_name == 'workflow_run' && github.event.workflow_run.id || github.run_id }}/attempts/${{ github.event_name == 'workflow_run' && github.event.workflow_run.run_attempt || github.run_attempt }}\",\"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\":\"https://github.com/WordPress/wordpress-develop/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}\",\"commit_message\":\"${{ steps.commit-message.outputs.commit_message_escaped }}\"}"
|
||||
|
||||
# Posts notifications when a workflow fails.
|
||||
failure:
|
||||
@ -170,7 +146,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
needs: [ prepare ]
|
||||
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure' || inputs.calling_status == 'failure' || failure() }}
|
||||
if: ${{ inputs.calling_status == 'failure' || failure() }}
|
||||
|
||||
steps:
|
||||
- name: Post failure notifications to Slack
|
||||
@ -186,7 +162,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
needs: [ prepare ]
|
||||
if: ${{ contains( fromJson( '["failure", "cancelled", "none"]' ), needs.prepare.outputs.previous_conclusion ) && ( github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' || inputs.calling_status == 'success' ) && success() }}
|
||||
if: ${{ contains( fromJson( '["failure", "cancelled", "none"]' ), needs.prepare.outputs.previous_conclusion ) && inputs.calling_status == 'success' && success() }}
|
||||
|
||||
steps:
|
||||
- name: Post failure notifications to Slack
|
||||
@ -202,7 +178,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
needs: [ prepare ]
|
||||
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' || inputs.calling_status == 'success' && success() }}
|
||||
if: ${{ inputs.calling_status == 'success' && success() }}
|
||||
|
||||
steps:
|
||||
- name: Post success notifications to Slack
|
||||
@ -218,7 +194,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
needs: [ prepare ]
|
||||
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'cancelled' || inputs.calling_status == 'cancelled' || cancelled() }}
|
||||
if: ${{ inputs.calling_status == 'cancelled' || cancelled() }}
|
||||
|
||||
steps:
|
||||
- name: Post cancelled notifications to Slack
|
||||
|
Loading…
x
Reference in New Issue
Block a user