Skip to content

Post-Build on trunk #150932

Post-Build on trunk

Post-Build on trunk #150932

name: CI Results
run-name: ${{ github.event.workflow.name }} on ${{ github.event.workflow_run.head_branch }}
on:
workflow_run:
types: [ 'completed' ]
workflows:
- Build
- Build Docker
- Tests
- Gardening
- Monorepo Auto-tagger
- Post-Build
- PR is up-to-date
- Update Jetpack Staging Test Sites
- Update Phan stubs
- k6 Tests for Jetpack Staging Test Sites
branches: [ 'trunk', 'prerelease', '*/branch-*' ]
jobs:
notify:
name: Notify failure
runs-on: ubuntu-latest
if: ${{ github.repository == 'Automattic/jetpack' && github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event != 'issues' && github.event.workflow_run.event != 'issue_comment' }}
steps:
- uses: actions/checkout@v4
- name: Generate message
id: message
run: |
source .github/files/gh-funcs.sh
# If this is triggered off of another "workflow_run" workflow, it'll always see the head_branch as "trunk".
# In that case, we assume it's setting display_title to be like "NAME on BRANCH" and extract the branch from there.
if jq -e '.workflow_run.event == "workflow_run"' "$GITHUB_EVENT_PATH" &>/dev/null; then
TITLE=$(jq -r '.workflow_run.display_title' "$GITHUB_EVENT_PATH")
BRANCH=${TITLE##* on }
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
DATA=$( jq -nc --slurpfile event "$GITHUB_EVENT_PATH" --arg branch "$BRANCH" '$event[0] as $e | $e.workflow_run as $run |
{
workflow_name: $e.workflow.name,
branch: $branch,
run_id: $run.id,
run_url: $run.html_url,
duration: ( ( $run.updated_at | fromdateiso8601 ) - ( $run.run_started_at | fromdateiso8601 ) | strftime( "%H:%M:%S" ) ),
}
' )
else
BRANCH=$(jq -r '.workflow_run.head_branch' "$GITHUB_EVENT_PATH")
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
DATA=$( jq -nc --slurpfile event "$GITHUB_EVENT_PATH" '$event[0] as $e | $e.workflow_run as $run |
( $run.head_commit.message | sub( "\n.*"; ""; "m" ) | match( " \\(#([0-9]+)\\)$" ).captures[0].string // null ) as $pr |
{
workflow_name: $e.workflow.name,
branch: $run.head_branch,
run_id: $run.id,
run_url: $run.html_url,
duration: ( ( $run.updated_at | fromdateiso8601 ) - ( $run.run_started_at | fromdateiso8601 ) | strftime( "%H:%M:%S" ) ),
commit: "\( $run.head_commit.id[0:8] ) \( $run.head_commit.message | sub( "\n.*"; ""; "m" ) )",
author: ( $run.head_commit.author.name ),
commit_url: "\( $run.head_repository.html_url )/commit/\( $run.head_commit.id )",
pr: $pr,
pr_url: ( if $pr then "\( $run.head_repository.html_url )/pull/\( $pr )" else null end )
}
' )
fi
jq -r '[
"### \( .workflow_name ) failed on \( .branch )",
"",
if .commit then "Commit: \( .commit )" else empty end,
if .author then "Author: \( .author )" else empty end,
"Duration: \( .duration )",
"",
(
[
"[Run #\( .run_id )](\( .run_url ))",
if .commit_url then "[Commit](\( .commit_url ))" else empty end,
if .pr then "[PR #\( .pr )](\( .pr_url ))" else empty end
] | join( " | " )
)
] | join( "\n" )' <<<"$DATA" >> $GITHUB_STEP_SUMMARY
gh_set_output message "$( jq -c '
{
icon_emoji: ":github-rejected:",
text: "*\( .workflow_name ) failed on \( .branch )*\n<\( .run_url )|Run #\( .run_id )>",
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: "*\( .workflow_name ) failed on \( .branch )*"
}
},
{
type: "context",
elements: [
if .commit then {
type: "plain_text",
text: "Commit: \( .commit )",
emoji: false
} else empty end,
if .author then {
type: "plain_text",
text: "Author: \( .author )",
emoji: false
} else empty end,
{
type: "plain_text",
text: "Duration: \( .duration )"
}
]
},
{
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
text: "Run #\( .run_id )"
},
url: .run_url
},
if .commit_url then {
type: "button",
text: {
type: "plain_text",
text: "Commit"
},
url: .commit_url
} else empty end,
if .pr then {
type: "button",
text: {
type: "plain_text",
text: "PR #\( .pr )"
},
url: .pr_url,
} else empty end
]
}
]
}
' <<<"$DATA" )"
- name: Send message to alerts channel
uses: slackapi/[email protected]
if: steps.message.outputs.branch == 'trunk'
with:
channel-id: ${{ secrets.SLACK_JP_ALERTS_CHANNEL }}
payload: ${{ steps.message.outputs.message }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}
- name: Send message to releases channel
uses: slackapi/[email protected]
if: contains( steps.message.outputs.branch, '/branch-' ) || steps.message.outputs.branch == 'prerelease'
with:
channel-id: ${{ secrets.SLACK_RELEASES_CHANNEL }}
payload: ${{ steps.message.outputs.message }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}