Build/Test Tools: Modify the Slack notifications workflow to be a reusable one.

The ability to reuse workflow files within GitHub Action workflows was recently added and allows for less code duplication.

In the context of WordPress Core, this also eliminates the need for an additional “Slack Notifications” workflow to run for every completed workflow.

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51921 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2021-10-20 14:40:47 +00:00
parent 40fd54aede
commit cbf2a1968f
9 changed files with 91 additions and 33 deletions

View File

@ -146,3 +146,9 @@ jobs:
- name: Ensure version-controlled files are not modified or deleted
run: git diff --exit-code
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ phpcs, jshint ]
if: ${{ always() }}

View File

@ -116,3 +116,9 @@ jobs:
- name: Ensure version-controlled files are not modified or deleted
run: git diff --exit-code
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ e2e-tests ]
if: ${{ always() }}

View File

@ -85,3 +85,9 @@ jobs:
- name: Ensure version-controlled files are not modified or deleted
run: git diff --exit-code
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ test-js ]
if: ${{ always() }}

View File

@ -87,3 +87,9 @@ jobs:
- name: Ensure version-controlled files are not modified or deleted
run: git diff --exit-code
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ php-compatibility ]
if: ${{ always() }}

View File

@ -242,3 +242,9 @@ jobs:
env:
WPT_REPORT_API_KEY: "${{ secrets.WPT_REPORT_API_KEY }}"
run: docker-compose run --rm -e WPT_REPORT_API_KEY -e WPT_PREPARE_DIR=/var/www -e WPT_TEST_DIR=/var/www php php test-runner/report.php
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ test-php ]
if: ${{ always() }}

View File

@ -1,26 +1,12 @@
##
# Posts messages to the Making WordPress Core Slack Instance by
# submitting data to Slack webhook URLs received by Slack Workflows.
# A reusable workflow for posting messages to the Making WordPress
# Core Slack Instance by submitting data to Slack webhook URLs
# received by Slack Workflows.
##
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:
- master
- trunk
- '[3-9].[0-9]'
workflow_call:
jobs:
# Gathers the details needed for Slack notifications.
@ -41,20 +27,44 @@ jobs:
payload: ${{ steps.create-payload.outputs.payload }}
steps:
- name: Get details about the previous workflow run
id: previous-result
uses: actions/github-script@a3e7071a34d7e1f219a8a4de9a5e0a34d1ee1293 # v4.0.2
- name: Get the workflow ID
id: current-workflow-id
uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
with:
script: |
const workflow_runs = await github.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: ${{ github.event.workflow_run.workflow_id }},
branch: '${{ github.event.workflow_run.head_branch }}',
const workflow_run = await github.actions.getWorkflowRun({
owner: '${{ github.repository_owner }}',
repo: 'wordpress-develop',
run_id: ${{ github.run_id }},
});
return workflow_run.data.workflow_id;
- name: Get the workflow URL
id: current-workflow-url
uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
with:
script: |
const workflow_run = await github.actions.getWorkflowRun({
owner: '${{ github.repository_owner }}',
repo: 'wordpress-develop',
run_id: ${{ github.run_id }},
});
return workflow_run.data.html_url;
- name: Get details about the previous workflow run
id: previous-result
uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
with:
script: |
const previous_runs = await github.actions.listWorkflowRuns({
owner: '${{ github.repository_owner }}',
repo: 'wordpress-develop',
workflow_id: ${{ steps.current-workflow-id.outputs.result }},
branch: '${{ github.ref_name }}',
per_page: 1,
page: 2,
});
return workflow_runs.data.workflow_runs[0].conclusion;
return previous_runs.data.workflow_runs[0].conclusion;
- name: Store previous conclusion as an output
id: previous-conclusion
@ -64,21 +74,21 @@ jobs:
id: commit-message
run: |
COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\"/g'
${{ 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.event.workflow_run.name }}\",\"ref_name\":\"${{ github.event.workflow_run.head_branch }}\",\"run_url\":\"${{ github.event.workflow_run.html_url }}\",\"commit_message\":\"${{ steps.commit-message.outputs.commit_message_escaped }}\"}"
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 }}\"}"
# Posts notifications when a workflow fails.
failure:
name: Failure notifications
runs-on: ubuntu-latest
needs: [ prepare ]
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
if: ${{ failure() }}
steps:
- name: Post failure notifications to Slack
@ -93,7 +103,7 @@ jobs:
name: Fixed notifications
runs-on: ubuntu-latest
needs: [ prepare ]
if: ${{ needs.prepare.outputs.previous_conclusion == 'failure' && github.event.workflow_run.conclusion == 'success' }}
if: ${{ needs.prepare.outputs.previous_conclusion == 'failure' && success() }}
steps:
- name: Post failure notifications to Slack
@ -108,7 +118,7 @@ jobs:
name: Success notifications
runs-on: ubuntu-latest
needs: [ prepare ]
if: ${{ github.event.workflow_run.conclusion == 'success' }}
if: ${{ success() }}
steps:
- name: Post success notifications to Slack
@ -123,7 +133,7 @@ jobs:
name: Cancelled notifications
runs-on: ubuntu-latest
needs: [ prepare ]
if: ${{ github.event.workflow_run.conclusion == 'cancelled' }}
if: ${{ cancelled() }}
steps:
- name: Post cancelled notifications to Slack

View File

@ -168,3 +168,9 @@ jobs:
with:
file: wp-code-coverage-multisite-clover-${{ github.sha }}.xml
flags: multisite,php
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ test-coverage-report ]
if: ${{ always() }}

View File

@ -154,3 +154,9 @@ jobs:
- name: Ensure version-controlled files are not modified or deleted during building and cleaning
run: git diff --exit-code
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ test-npm, test-npm-macos ]
if: ${{ always() }}

View File

@ -69,3 +69,9 @@ jobs:
workflow_id: '${{ matrix.workflow }}',
ref: '${{ matrix.branch }}'
});
slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
needs: [ dispatch-workflows-for-old-branches ]
if: ${{ always() }}