Make WordPress Core


Ignore:
Timestamp:
06/30/2022 02:05:29 PM (2 years ago)
Author:
desrosj
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/slack-notifications.yml

    r53581 r53591  
    77
    88on:
    9   workflow_run:
    10     workflows:
    11       - Code Coverage Report
    12       - Coding Standards
    13       - End-to-end Tests
    14       - JavaScript Tests
    15       - PHP Compatibility
    16       - PHPUnit Tests
    17       - Test NPM
    18       - Test old branches
    19     types:
    20       - completed
    21     branches:
    22       - '[3-4].[0-9]'
    23       - '5.[0-8]'
    24 
    259  workflow_call:
    2610    inputs:
     
    4428
    4529env:
    46   CURRENT_BRANCH: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref_name }}
     30  CURRENT_BRANCH: ${{ github.ref_name }}
    4731
    4832jobs:
     
    7054      - name: Determine the status of the previous attempt
    7155        id: previous-attempt-result
    72         if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
    7356        uses: actions/github-script@7a5c598405937d486b0331594b5da2b14db670da # v6.1.0
    7457        with:
     
    9275            }
    9376
    94             let workflow_id = '';
    95             if ( ${{ github.event_name == 'workflow_run' }} ) {
    96               workflow_id = '${{ github.event.workflow_run.workflow_id }}';
    97             } else {
    98               workflow_id = workflow_run.data.workflow_id;
    99             }
    100 
    10177            // Otherwise, check the previous workflow run.
    10278            const previous_runs = await github.rest.actions.listWorkflowRuns({
    10379              owner: context.repo.owner,
    10480              repo: context.repo.repo,
    105               workflow_id: workflow_id,
     81              workflow_id: workflow_run.data.workflow_id,
    10682              branch: '${{ env.CURRENT_BRANCH }}',
    10783              exclude_pull_requests: true,
     
    156132        run: |
    157133          COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\\\"/g' | sed 's/\$/\\$/g'
    158           ${{ 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 }}
     134          ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && fromJson( steps.current-commit-message.outputs.result ) || github.event.head_commit.message }}
    159135          EOF
    160136          )
     
    163139      - name: Construct payload and store as an output
    164140        id: create-payload
    165         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 }}\"}"
     141        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 }}\"}"
    166142
    167143  # Posts notifications when a workflow fails.
     
    171147    timeout-minutes: 5
    172148    needs: [ prepare ]
    173     if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure' || inputs.calling_status == 'failure' || failure() }}
     149    if: ${{ inputs.calling_status == 'failure' || failure() }}
    174150
    175151    steps:
     
    187163    timeout-minutes: 5
    188164    needs: [ prepare ]
    189     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() }}
     165    if: ${{ contains( fromJson( '["failure", "cancelled", "none"]' ), needs.prepare.outputs.previous_conclusion ) && inputs.calling_status == 'success' && success() }}
    190166
    191167    steps:
     
    203179    timeout-minutes: 5
    204180    needs: [ prepare ]
    205     if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' || inputs.calling_status == 'success' && success() }}
     181    if: ${{ inputs.calling_status == 'success' && success() }}
    206182
    207183    steps:
     
    219195    timeout-minutes: 5
    220196    needs: [ prepare ]
    221     if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'cancelled' || inputs.calling_status == 'cancelled' || cancelled() }}
     197    if: ${{ inputs.calling_status == 'cancelled' || cancelled() }}
    222198
    223199    steps:
Note: See TracChangeset for help on using the changeset viewer.