Make WordPress Core

Changeset 53108


Ignore:
Timestamp:
04/08/2022 01:57:44 PM (4 years ago)
Author:
desrosj
Message:

Build/Test Tools: Improve the accuracy of “fixed” Slack notifications.

This adjusts the logic of the Slack Notifications workflow to make the “fixed” notifications more reliable.

Currently, the workflow looks at the immediately preceding workflow run for the current branch. This fails to indicate that a workflow is fixed when other unrelated commits are made, and when rerunning the workflow after a false failure (timeout, etc.).

The workflow will now use the following logic to determine if something has been fixed:

  • When a workflow is rerun, the conclusion for the immediately preceding run attempt will now be used to determine if the current attempt has “fixed” the workflow.
  • When on the first run attempt for a workflow run, the workflow conclusion for the immediately preceding commit will be used.
  • When on the first run attempt for a workflow run and no preceding commits for the current branch are present (this is a fresh tag or branch), always consider it “fixed”.

Props davidbaumwald.
See #54742.

File:
1 edited

Legend:

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

    r53077 r53108  
    5353  #
    5454  # Performs the following steps:
    55   # - Retrieves the workflow ID (if necessary).
    56   # - Retrieves the workflow URL (if necessary).
    57   # - Retrieves the previous workflow run and stores its conclusion.
     55  # - Retrieves the current workflow run.
     56  # - Determine the conclusion of the previous workflow run or run attempt.
    5857  # - Sets the previous conclusion as an output.
    5958  # - Prepares the commit message.
     
    6968
    7069    steps:
    71       - name: Get the workflow ID
    72         id: current-workflow-id
     70      - name: Determine the status of the previous attempt
     71        id: previous-attempt-result
    7372        if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
    74         uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
     73        uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e # v6.0.0
    7574        with:
    7675          script: |
     
    8079              run_id: ${{ github.run_id }},
    8180            });
    82             return workflow_run.data.workflow_id;
    83 
    84       - name: Get details about the previous workflow run
    85         id: previous-result
    86         uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
    87         with:
    88           script: |
     81
     82            // When a workflow has been restarted to fix a failure, check the previous run attempt.
     83            if ( workflow_run.data.run_attempt > 1 ) {
     84              const previous_run = await github.rest.actions.getWorkflowRunAttempt({
     85                owner: context.repo.owner,
     86                repo: context.repo.repo,
     87                run_id: ${{ github.run_id }},
     88                attempt_number: workflow_run.data.run_attempt - 1
     89              });
     90
     91              return previous_run.data.conclusion;
     92            }
     93
     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
     101            // Otherwise, check the previous workflow run.
    89102            const previous_runs = await github.rest.actions.listWorkflowRuns({
    90103              owner: context.repo.owner,
    91104              repo: context.repo.repo,
    92               workflow_id: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.workflow_id || steps.current-workflow-id.outputs.result }},
     105              workflow_id: workflow_id,
    93106              branch: '${{ env.CURRENT_BRANCH }}',
    94               per_page: 1,
    95               page: 2,
     107              exclude_pull_requests: true,
    96108            });
    97109
    98             if ( previous_runs.data.total_count > 0 ) {
    99               return previous_runs.data.workflow_runs[0].conclusion;
    100             } else {
    101               // Use failure so all first time runs for a branch or tag are reported to Slack.
    102               return 'failure';
    103             }
     110            // This is the first workflow run for this branch or tag.
     111            if ( previous_runs.data.workflow_runs.length == 0 ) {
     112              return 'none';
     113            }
     114
     115            // Find the workflow run for the commit that immediately preceded this one.
     116            for ( let i = 0; i < previous_runs.data.workflow_runs.length; i++ ) {
     117              if ( previous_runs.data.workflow_runs[ i ].run_number == workflow_run.data.run_number ) {
     118                return previous_runs.data.workflow_runs[ i + 1 ].conclusion;
     119              }
     120            }
     121
     122            // Can't determine previous workflow conclusion.
     123            return 'unknown';
    104124
    105125      - name: Store previous conclusion as an output
    106126        id: previous-conclusion
    107         run: echo "::set-output name=previous_conclusion::${{ steps.previous-result.outputs.result }}"
     127        run: echo "::set-output name=previous_conclusion::${{ steps.previous-attempt-result.outputs.result }}"
    108128
    109129      - name: Get the commit message
    110130        id: current-commit-message
    111         uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
     131        uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e # v6.0.0
    112132        if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
    113133        with:
     
    143163    steps:
    144164      - name: Post failure notifications to Slack
    145         uses: slackapi/slack-github-action@410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0
     165        uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0
    146166        with:
    147167          payload: ${{ needs.prepare.outputs.payload }}
     
    155175    timeout-minutes: 5
    156176    needs: [ prepare ]
    157     if: ${{ needs.prepare.outputs.previous_conclusion == 'failure' && ( github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' || inputs.calling_status == 'success' ) && success() }}
     177    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() }}
    158178
    159179    steps:
    160180      - name: Post failure notifications to Slack
    161         uses: slackapi/slack-github-action@410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0
     181        uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0
    162182        with:
    163183          payload: ${{ needs.prepare.outputs.payload }}
     
    175195    steps:
    176196      - name: Post success notifications to Slack
    177         uses: slackapi/slack-github-action@410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0
     197        uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0
    178198        with:
    179199          payload: ${{ needs.prepare.outputs.payload }}
     
    191211    steps:
    192212      - name: Post cancelled notifications to Slack
    193         uses: slackapi/slack-github-action@410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0
     213        uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0
    194214        with:
    195215          payload: ${{ needs.prepare.outputs.payload }}
Note: See TracChangeset for help on using the changeset viewer.