diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 8edb2f281f..c111159d66 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -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() }} diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml index 9358fc9520..e74a0f36aa 100644 --- a/.github/workflows/end-to-end-tests.yml +++ b/.github/workflows/end-to-end-tests.yml @@ -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() }} diff --git a/.github/workflows/javascript-tests.yml b/.github/workflows/javascript-tests.yml index b1226bacca..8373ff66d6 100644 --- a/.github/workflows/javascript-tests.yml +++ b/.github/workflows/javascript-tests.yml @@ -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() }} diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index b5316fd1a6..a6b38f7ff5 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -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() }} diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index ae6abc3ce7..936c73ce63 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -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() }} diff --git a/.github/workflows/slack-notifications.yml b/.github/workflows/slack-notifications.yml index 2be16eb6ef..7611f72255 100644 --- a/.github/workflows/slack-notifications.yml +++ b/.github/workflows/slack-notifications.yml @@ -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 diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index 31f20b8bd3..a0abd2fb2a 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -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() }} diff --git a/.github/workflows/test-npm.yml b/.github/workflows/test-npm.yml index 3774ee2851..2a121f8efb 100644 --- a/.github/workflows/test-npm.yml +++ b/.github/workflows/test-npm.yml @@ -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() }} diff --git a/.github/workflows/test-old-branches.yml b/.github/workflows/test-old-branches.yml index 2bb5664a98..86b879ad79 100644 --- a/.github/workflows/test-old-branches.yml +++ b/.github/workflows/test-old-branches.yml @@ -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() }}