Make WordPress Core


Ignore:
Timestamp:
10/29/2021 07:59:05 PM (3 years ago)
Author:
desrosj
Message:

Build/Test Tools: Adjust Slack notifications for scheduled and workflow_dispatch events.

This makes the needed adjustments to fix Slack notifications for scheduled and workflow_dispatch events. The data needed to send notifications for these events are stored in different locations, or need to be accessed through API requests.

Follow up to [51921], [51937].
See #53363.

File:
1 edited

Legend:

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

    r51952 r51953  
    6565      - name: Get the workflow ID
    6666        id: current-workflow-id
    67         if: ${{ github.event_name == 'push' }}
     67        if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
    6868        uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
    6969        with:
    7070          script: |
    7171            const workflow_run = await github.rest.actions.getWorkflowRun({
    72               owner: '${{ github.repository_owner }}',
    73               repo: 'wordpress-develop',
     72              owner: context.repo.owner,
     73              repo: context.repo.repo,
    7474              run_id: ${{ github.run_id }},
    7575            });
    7676            return workflow_run.data.workflow_id;
    77 
    78       - name: Get the workflow URL
    79         id: current-workflow-url
    80         uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
    81         if: ${{ github.event_name == 'push' }}
    82         with:
    83           script: |
    84             const workflow_run = await github.rest.actions.getWorkflowRun({
    85               owner: '${{ github.repository_owner }}',
    86               repo: 'wordpress-develop',
    87               run_id: ${{ github.run_id }},
    88             });
    89             return workflow_run.data.html_url;
    9077
    9178      - name: Get details about the previous workflow run
     
    9582          script: |
    9683            const previous_runs = await github.rest.actions.listWorkflowRuns({
    97               owner: '${{ github.repository_owner }}',
    98               repo: 'wordpress-develop',
     84              owner: context.repo.owner,
     85              repo: context.repo.repo,
    9986              workflow_id: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.workflow_id || steps.current-workflow-id.outputs.result }},
    10087              branch: '${{ env.CURRENT_BRANCH }}',
     
    10895        run: echo "::set-output name=previous_conclusion::${{ steps.previous-result.outputs.result }}"
    10996
     97      - name: Get the commit message
     98        id: current-commit-message
     99        uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
     100        if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
     101        with:
     102          script: |
     103            const commit_details = await github.rest.repos.getCommit({
     104              owner: context.repo.owner,
     105              repo: context.repo.repo,
     106              ref: '${{ github.sha }}'
     107            });
     108            return commit_details.data.commit.message;
     109
    110110      - name: Prepare commit message.
    111111        id: commit-message
    112112        run: |
    113           COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\"/g' | sed 's/\$/\\$/g'
    114           ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_commit.message || github.event.head_commit.message }}
     113          COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\\\"/g' | sed 's/\$/\\$/g'
     114          ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_commit.message || ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && fromJson( steps.current-commit-message.outputs.result ) || github.event.head_commit.message }}
    115115          EOF
    116116          )
     
    119119      - name: Construct payload and store as an output
    120120        id: create-payload
    121         run: echo "::set-output name=payload::{\"workflow_name\":\"${{ github.event_name == 'workflow_run' && github.event.workflow_run.name || github.workflow }}\",\"ref_name\":\"${{ env.CURRENT_BRANCH }}\",\"run_url\":\"${{ github.event_name == 'workflow_run' && github.event.workflow_run.html_url || steps.current-workflow-url.outputs.result }}\",\"commit_message\":\"${{ steps.commit-message.outputs.commit_message_escaped }}\"}"
     121        run: echo "::set-output name=payload::{\"workflow_name\":\"${{ github.event_name == 'workflow_run' && github.event.workflow_run.name || github.workflow }}\",\"ref_name\":\"${{ env.CURRENT_BRANCH }}\",\"run_url\":\"https://github.com/WordPress/wordpress-develop/runs/${{ github.event_name == 'workflow_run' && github.event.workflow_run.id || github.run_id }}\",\"commit_message\":\"${{ steps.commit-message.outputs.commit_message_escaped }}\"}"
    122122
    123123  # Posts notifications when a workflow fails.
Note: See TracChangeset for help on using the changeset viewer.