Skip to content

Commit f3b6a19

Browse files
heiskrCopilotCopilot
authored
Link failure issue in Slack alerts, create issue first (#62386)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: heiskr <1221423+heiskr@users.noreply.github.com> Copilot-Session: 97c049ec-cd3e-470b-821e-1717cc6026d7 Copilot-Session: 2f4f0395-3f7a-47d0-a470-eefd32720b22 Copilot-Session: 80d768a6-3069-432e-aae6-4d9cbd1e38be
1 parent 1ccadae commit f3b6a19

39 files changed

Lines changed: 320 additions & 170 deletions

.github/actions/create-workflow-failure-issue/action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ inputs:
1010
default: github/docs-engineering
1111
required: false
1212

13+
outputs:
14+
issue_url:
15+
description: URL of the created or updated workflow-failure issue (empty if creation failed).
16+
value: ${{ steps.create-new.outputs.issue_url || steps.comment-existing.outputs.issue_url }}
17+
1318
runs:
1419
using: composite
1520
steps:
@@ -31,6 +36,7 @@ runs:
3136
echo "existing_issue=$existing" >> "$GITHUB_OUTPUT"
3237
3338
- name: Comment on existing issue
39+
id: comment-existing
3440
if: steps.check-existing.outputs.existing_issue != ''
3541
shell: bash
3642
env:
@@ -57,8 +63,10 @@ runs:
5763
gh issue comment "$ISSUE_NUMBER" \
5864
--repo "$ISSUE_REPO" \
5965
--body "$body"
66+
echo "issue_url=$GITHUB_SERVER_URL/$ISSUE_REPO/issues/$ISSUE_NUMBER" >> "$GITHUB_OUTPUT"
6067
6168
- name: Create workflow failure issue
69+
id: create-new
6270
if: steps.check-existing.outputs.existing_issue == ''
6371
shell: bash
6472
env:
@@ -86,9 +94,10 @@ runs:
8694
This issue was automatically created by the create-workflow-failure-issue action to enable automated diagnosis.
8795
EOF
8896
)
89-
gh issue create \
97+
url=$(gh issue create \
9098
--repo "$ISSUE_REPO" \
9199
--label "workflow-failure" \
92100
--label "workflow-generated" \
93101
--title "[Workflow Failure] $WORKFLOW_NAME" \
94-
--body "$body"
102+
--body "$body")
103+
echo "issue_url=$url" >> "$GITHUB_OUTPUT"

.github/actions/slack-alert/action.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,61 @@ inputs:
1010
default: CG5MJHMB2 # docs-alerts
1111
required: false
1212
message:
13-
description: The message to send to Slack
14-
default: The last '${{ github.workflow }}' run failed. See ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
13+
description: >-
14+
Optional message override. When set, it is sent verbatim. When empty (the
15+
default), a standard multi-line failure message is built from the run
16+
context, plus a link to the failure issue if issue_url is provided.
17+
default: ''
18+
required: false
19+
issue_url:
20+
description: >-
21+
Optional link to the tracking failure issue (e.g. the output of the
22+
create-workflow-failure-issue action). Appended to the default message.
23+
Ignored when a custom message is provided.
24+
default: ''
1525
required: false
1626

1727
runs:
1828
using: composite
1929
steps:
30+
# Build the Slack text here so the default message can be multi-line (real
31+
# newlines) and conditionally include the issue link. A caller-supplied
32+
# message is passed through verbatim for backward compatibility.
33+
- name: Build Slack message
34+
id: build
35+
shell: bash
36+
env:
37+
MESSAGE: ${{ inputs.message }}
38+
ISSUE_URL: ${{ inputs.issue_url }}
39+
SOURCE_REPO: ${{ github.repository }}
40+
WORKFLOW_NAME: ${{ github.workflow }}
41+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
42+
EVENT_NAME: ${{ github.event_name }}
43+
GIT_REF: ${{ github.ref }}
44+
ACTOR: ${{ github.actor }}
45+
run: |
46+
# Escape Slack mrkdwn control chars in interpolated context fields so a
47+
# crafted branch/ref (e.g. containing <!channel>) can't inject mentions.
48+
esc() { printf '%s' "$1" | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g'; }
49+
# Unique heredoc delimiter so a custom message can't collide with it.
50+
delim="SLACK_EOF_${RANDOM}${RANDOM}"
51+
{
52+
printf 'text<<%s\n' "$delim"
53+
if [ -n "$MESSAGE" ]; then
54+
printf '%s\n' "$MESSAGE"
55+
else
56+
printf ':actions: *Workflow failure* in %s: %s\n' "$(esc "$SOURCE_REPO")" "$(esc "$WORKFLOW_NAME")"
57+
printf 'on %s · %s · by %s\n' "$(esc "$EVENT_NAME")" "$(esc "$GIT_REF")" "$(esc "$ACTOR")"
58+
printf 'Run: %s\n' "$RUN_URL"
59+
if [ -n "$ISSUE_URL" ]; then
60+
printf 'Issue: %s\n' "$ISSUE_URL"
61+
else
62+
printf ':warning: No issue created\n'
63+
fi
64+
fi
65+
printf '%s\n' "$delim"
66+
} >> "$GITHUB_OUTPUT"
67+
2068
- name: Send Slack notification if workflow fails
2169
uses: slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c # v3.0.3
2270
with:
@@ -25,4 +73,4 @@ runs:
2573
errors: true
2674
payload: |
2775
channel: ${{ toJSON(inputs.slack_channel_id) }}
28-
text: ${{ toJSON(inputs.message) }}
76+
text: ${{ toJSON(steps.build.outputs.text) }}

.github/workflows/benchmark-pages.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ jobs:
157157
echo "Done creating issue"
158158
fi
159159
160-
- uses: ./.github/actions/slack-alert
160+
- uses: ./.github/actions/create-workflow-failure-issue
161+
id: create-failure-issue
161162
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
162163
with:
163-
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
164+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
164165

165-
- uses: ./.github/actions/create-workflow-failure-issue
166+
- uses: ./.github/actions/slack-alert
166167
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
167168
with:
168-
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
169+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
170+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

.github/workflows/changelog-agent.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,14 @@ jobs:
736736
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
737737
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
738738

739-
- uses: ./.github/actions/slack-alert
739+
- uses: ./.github/actions/create-workflow-failure-issue
740+
id: create-failure-issue
740741
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
741742
with:
742-
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
743+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
743744

744-
- uses: ./.github/actions/create-workflow-failure-issue
745+
- uses: ./.github/actions/slack-alert
745746
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
746747
with:
747-
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
748+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
749+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

.github/workflows/codeql.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ jobs:
3737
- uses: github/codeql-action/analyze@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7
3838
continue-on-error: true
3939

40-
- uses: ./.github/actions/slack-alert
40+
- uses: ./.github/actions/create-workflow-failure-issue
41+
id: create-failure-issue
4142
if: ${{ failure() && github.event_name != 'pull_request' }}
4243
with:
43-
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
44+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
4445

45-
- uses: ./.github/actions/create-workflow-failure-issue
46+
- uses: ./.github/actions/slack-alert
4647
if: ${{ failure() && github.event_name != 'pull_request' }}
4748
with:
48-
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
49+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
50+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

.github/workflows/content-pipelines.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,14 @@ jobs:
187187
--label "workflow-generated,content-pipeline-update,ready-for-doc-review,skip FR board"
188188
fi
189189
190-
- uses: ./.github/actions/slack-alert
190+
- uses: ./.github/actions/create-workflow-failure-issue
191+
id: create-failure-issue
191192
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
192193
with:
193-
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
194+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
194195

195-
- uses: ./.github/actions/create-workflow-failure-issue
196+
- uses: ./.github/actions/slack-alert
196197
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
197198
with:
198-
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
199+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
200+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

.github/workflows/copy-api-issue-to-internal.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,16 @@ jobs:
7474
OLD_ISSUE: ${{ github.event.issue.html_url }}
7575

7676
- name: Check out repo
77-
if: ${{ failure() && github.event_name != 'workflow_dispatch' && github.repository == 'github/docs-internal' }}
77+
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
7878
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
79+
- uses: ./.github/actions/create-workflow-failure-issue
80+
id: create-failure-issue
81+
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
82+
with:
83+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
84+
7985
- uses: ./.github/actions/slack-alert
80-
if: ${{ failure() && github.event_name != 'workflow_dispatch' && github.repository == 'github/docs-internal' }}
86+
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
8187
with:
8288
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
89+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

.github/workflows/create-changelog-pr.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ jobs:
159159
core.info(`Failed to assign PR to @${context.payload.comment.user.login}: ${err.message}`);
160160
}
161161
162-
- uses: ./.github/actions/slack-alert
162+
- uses: ./.github/actions/create-workflow-failure-issue
163+
id: create-failure-issue
163164
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
164165
with:
165-
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
166+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
166167

167-
- uses: ./.github/actions/create-workflow-failure-issue
168+
- uses: ./.github/actions/slack-alert
168169
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
169170
with:
170-
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
171+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
172+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

.github/workflows/delete-orphan-translation-files.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,14 @@ jobs:
155155
fi
156156
fi
157157
158-
- uses: ./.github/actions/slack-alert
158+
- uses: ./.github/actions/create-workflow-failure-issue
159+
id: create-failure-issue
159160
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
160161
with:
161-
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
162+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
162163

163-
- uses: ./.github/actions/create-workflow-failure-issue
164+
- uses: ./.github/actions/slack-alert
164165
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
165166
with:
166-
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
167+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
168+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

.github/workflows/docs-review-collect.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ jobs:
4242
REVIEWER: 'docs-reviewers'
4343
FEATURE: 'Audit log event descriptions'
4444

45-
- uses: ./.github/actions/slack-alert
45+
- uses: ./.github/actions/create-workflow-failure-issue
46+
id: create-failure-issue
4647
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
4748
with:
48-
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
49+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
4950

50-
- uses: ./.github/actions/create-workflow-failure-issue
51+
- uses: ./.github/actions/slack-alert
5152
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
5253
with:
53-
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
54+
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
55+
issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}

0 commit comments

Comments
 (0)