WordPress.org

Make WordPress Core

Changeset 51921


Ignore:
Timestamp:
10/20/2021 02:40:47 PM (7 weeks ago)
Author:
desrosj
Message:

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.

Location:
trunk/.github/workflows
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/coding-standards.yml

    r51535 r51921  
    147147      - name: Ensure version-controlled files are not modified or deleted
    148148        run: git diff --exit-code
     149
     150  slack-notifications:
     151    name: Slack Notifications
     152    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     153    needs: [ phpcs, jshint ]
     154    if: ${{ always() }}
  • trunk/.github/workflows/end-to-end-tests.yml

    r51535 r51921  
    117117      - name: Ensure version-controlled files are not modified or deleted
    118118        run: git diff --exit-code
     119
     120  slack-notifications:
     121    name: Slack Notifications
     122    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     123    needs: [ e2e-tests ]
     124    if: ${{ always() }}
  • trunk/.github/workflows/javascript-tests.yml

    r51535 r51921  
    8686      - name: Ensure version-controlled files are not modified or deleted
    8787        run: git diff --exit-code
     88
     89  slack-notifications:
     90    name: Slack Notifications
     91    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     92    needs: [ test-js ]
     93    if: ${{ always() }}
  • trunk/.github/workflows/php-compatibility.yml

    r51535 r51921  
    8888      - name: Ensure version-controlled files are not modified or deleted
    8989        run: git diff --exit-code
     90
     91  slack-notifications:
     92    name: Slack Notifications
     93    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     94    needs: [ php-compatibility ]
     95    if: ${{ always() }}
  • trunk/.github/workflows/phpunit-tests.yml

    r51890 r51921  
    243243          WPT_REPORT_API_KEY: "${{ secrets.WPT_REPORT_API_KEY }}"
    244244        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
     245
     246  slack-notifications:
     247    name: Slack Notifications
     248    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     249    needs: [ test-php ]
     250    if: ${{ always() }}
  • trunk/.github/workflows/slack-notifications.yml

    r51709 r51921  
    11##
    2 # Posts messages to the Making WordPress Core Slack Instance by
    3 # submitting data to Slack webhook URLs received by Slack Workflows.
     2# A reusable workflow for posting messages to the Making WordPress
     3# Core Slack Instance by submitting data to Slack webhook URLs
     4# received by Slack Workflows.
    45##
    56name: Slack Notifications
    67
    78on:
    8   workflow_run:
    9     workflows:
    10       - Code Coverage Report
    11       - Coding Standards
    12       - End-to-end Tests
    13       - JavaScript Tests
    14       - PHP Compatibility
    15       - PHPUnit Tests
    16       - Test NPM
    17       - Test old branches
    18     types:
    19       - completed
    20     branches:
    21       - master
    22       - trunk
    23       - '[3-9].[0-9]'
     9  workflow_call:
    2410
    2511jobs:
     
    4228
    4329    steps:
     30      - name: Get the workflow ID
     31        id: current-workflow-id
     32        uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
     33        with:
     34          script: |
     35            const workflow_run = await github.actions.getWorkflowRun({
     36              owner: '${{ github.repository_owner }}',
     37              repo: 'wordpress-develop',
     38              run_id: ${{ github.run_id }},
     39            });
     40            return workflow_run.data.workflow_id;
     41
     42      - name: Get the workflow URL
     43        id: current-workflow-url
     44        uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
     45        with:
     46          script: |
     47            const workflow_run = await github.actions.getWorkflowRun({
     48              owner: '${{ github.repository_owner }}',
     49              repo: 'wordpress-develop',
     50              run_id: ${{ github.run_id }},
     51            });
     52            return workflow_run.data.html_url;
     53
    4454      - name: Get details about the previous workflow run
    4555        id: previous-result
    46         uses: actions/github-script@a3e7071a34d7e1f219a8a4de9a5e0a34d1ee1293 # v4.0.2
     56        uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
    4757        with:
    4858          script: |
    49             const workflow_runs = await github.actions.listWorkflowRuns({
    50               owner: context.repo.owner,
    51               repo: context.repo.repo,
    52               workflow_id: ${{ github.event.workflow_run.workflow_id }},
    53               branch: '${{ github.event.workflow_run.head_branch }}',
     59            const previous_runs = await github.actions.listWorkflowRuns({
     60              owner: '${{ github.repository_owner }}',
     61              repo: 'wordpress-develop',
     62              workflow_id: ${{ steps.current-workflow-id.outputs.result }},
     63              branch: '${{ github.ref_name }}',
    5464              per_page: 1,
    5565              page: 2,
    5666            });
    57             return workflow_runs.data.workflow_runs[0].conclusion;
     67            return previous_runs.data.workflow_runs[0].conclusion;
    5868
    5969      - name: Store previous conclusion as an output
     
    6575        run: |
    6676          COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\"/g'
    67           ${{ github.event.workflow_run.head_commit.message }}
     77          ${{ github.event.head_commit.message }}
    6878          EOF
    6979          )
     
    7282      - name: Construct payload and store as an output
    7383        id: create-payload
    74         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 }}\"}"
     84        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 }}\"}"
    7585
    7686  # Posts notifications when a workflow fails.
     
    7989    runs-on: ubuntu-latest
    8090    needs: [ prepare ]
    81     if: ${{ github.event.workflow_run.conclusion == 'failure' }}
     91    if: ${{ failure() }}
    8292
    8393    steps:
     
    94104    runs-on: ubuntu-latest
    95105    needs: [ prepare ]
    96     if: ${{ needs.prepare.outputs.previous_conclusion == 'failure' && github.event.workflow_run.conclusion == 'success' }}
     106    if: ${{ needs.prepare.outputs.previous_conclusion == 'failure' && success() }}
    97107
    98108    steps:
     
    109119    runs-on: ubuntu-latest
    110120    needs: [ prepare ]
    111     if: ${{ github.event.workflow_run.conclusion == 'success' }}
     121    if: ${{ success() }}
    112122
    113123    steps:
     
    124134    runs-on: ubuntu-latest
    125135    needs: [ prepare ]
    126     if: ${{ github.event.workflow_run.conclusion == 'cancelled' }}
     136    if: ${{ cancelled() }}
    127137
    128138    steps:
  • trunk/.github/workflows/test-coverage.yml

    r51868 r51921  
    169169          file: wp-code-coverage-multisite-clover-${{ github.sha }}.xml
    170170          flags: multisite,php
     171
     172  slack-notifications:
     173    name: Slack Notifications
     174    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     175    needs: [ test-coverage-report ]
     176    if: ${{ always() }}
  • trunk/.github/workflows/test-npm.yml

    r51535 r51921  
    155155      - name: Ensure version-controlled files are not modified or deleted during building and cleaning
    156156        run: git diff --exit-code
     157
     158  slack-notifications:
     159    name: Slack Notifications
     160    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     161    needs: [ test-npm, test-npm-macos ]
     162    if: ${{ always() }}
  • trunk/.github/workflows/test-old-branches.yml

    r51535 r51921  
    7070              ref: '${{ matrix.branch }}'
    7171            });
     72
     73  slack-notifications:
     74    name: Slack Notifications
     75    uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@master
     76    needs: [ dispatch-workflows-for-old-branches ]
     77    if: ${{ always() }}
Note: See TracChangeset for help on using the changeset viewer.