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.

git-svn-id: https://develop.svn.wordpress.org/trunk@51953 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2021-10-29 19:59:05 +00:00
parent 5b1da06715
commit f28310aeda

View File

@ -64,38 +64,25 @@ jobs:
steps:
- name: Get the workflow ID
id: current-workflow-id
if: ${{ github.event_name == 'push' }}
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
with:
script: |
const workflow_run = await github.rest.actions.getWorkflowRun({
owner: '${{ github.repository_owner }}',
repo: 'wordpress-develop',
owner: context.repo.owner,
repo: context.repo.repo,
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
if: ${{ github.event_name == 'push' }}
with:
script: |
const workflow_run = await github.rest.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.rest.actions.listWorkflowRuns({
owner: '${{ github.repository_owner }}',
repo: 'wordpress-develop',
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.workflow_id || steps.current-workflow-id.outputs.result }},
branch: '${{ env.CURRENT_BRANCH }}',
per_page: 1,
@ -107,18 +94,31 @@ jobs:
id: previous-conclusion
run: echo "::set-output name=previous_conclusion::${{ steps.previous-result.outputs.result }}"
- name: Get the commit message
id: current-commit-message
uses: actions/github-script@441359b1a30438de65712c2fbca0abe4816fa667 # v5.0.0
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
with:
script: |
const commit_details = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: '${{ github.sha }}'
});
return commit_details.data.commit.message;
- name: Prepare commit message.
id: commit-message
run: |
COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\"/g' | sed 's/\$/\\$/g'
${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_commit.message || github.event.head_commit.message }}
COMMIT_MESSAGE=$(cat <<'EOF' | awk 'NR==1' | sed 's/`/\\`/g' | sed 's/\"/\\\\\\"/g' | sed 's/\$/\\$/g'
${{ 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 }}
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_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 }}\"}"
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 }}\"}"
# Posts notifications when a workflow fails.
failure: