Changeset 53108
- Timestamp:
- 04/08/2022 01:57:44 PM (4 years ago)
- File:
-
- 1 edited
-
trunk/.github/workflows/slack-notifications.yml (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/.github/workflows/slack-notifications.yml
r53077 r53108 53 53 # 54 54 # 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. 58 57 # - Sets the previous conclusion as an output. 59 58 # - Prepares the commit message. … … 69 68 70 69 steps: 71 - name: Get the workflow ID72 id: current-workflow-id70 - name: Determine the status of the previous attempt 71 id: previous-attempt-result 73 72 if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} 74 uses: actions/github-script@ 441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.073 uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e # v6.0.0 75 74 with: 76 75 script: | … … 80 79 run_id: ${{ github.run_id }}, 81 80 }); 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. 89 102 const previous_runs = await github.rest.actions.listWorkflowRuns({ 90 103 owner: context.repo.owner, 91 104 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, 93 106 branch: '${{ env.CURRENT_BRANCH }}', 94 per_page: 1, 95 page: 2, 107 exclude_pull_requests: true, 96 108 }); 97 109 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'; 104 124 105 125 - name: Store previous conclusion as an output 106 126 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 }}" 108 128 109 129 - name: Get the commit message 110 130 id: current-commit-message 111 uses: actions/github-script@ 441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0131 uses: actions/github-script@9ac08808f993958e9de277fe43a64532a609130e # v6.0.0 112 132 if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} 113 133 with: … … 143 163 steps: 144 164 - name: Post failure notifications to Slack 145 uses: slackapi/slack-github-action@ 410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0165 uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0 146 166 with: 147 167 payload: ${{ needs.prepare.outputs.payload }} … … 155 175 timeout-minutes: 5 156 176 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() }} 158 178 159 179 steps: 160 180 - name: Post failure notifications to Slack 161 uses: slackapi/slack-github-action@ 410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0181 uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0 162 182 with: 163 183 payload: ${{ needs.prepare.outputs.payload }} … … 175 195 steps: 176 196 - name: Post success notifications to Slack 177 uses: slackapi/slack-github-action@ 410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0197 uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0 178 198 with: 179 199 payload: ${{ needs.prepare.outputs.payload }} … … 191 211 steps: 192 212 - name: Post cancelled notifications to Slack 193 uses: slackapi/slack-github-action@ 410ae57cff5c6b682b106440be0e6c7eb8c98c9d # v1.16.0213 uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0 194 214 with: 195 215 payload: ${{ needs.prepare.outputs.payload }}
Note: See TracChangeset
for help on using the changeset viewer.