Skip to content

Commit 68a9d9d

Browse files
authored
T-17335 Create Linear issue on E2E workflow failure (#72)
1 parent 4a42556 commit 68a9d9d

1 file changed

Lines changed: 91 additions & 9 deletions

File tree

.github/workflows/test.yml

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,101 @@ jobs:
6666
env:
6767
LOGTAIL_API_TOKEN: ${{ matrix.config == 'examples/connection' && secrets.GLOBAL_E2E_API_TOKEN || secrets.LOGS_E2E_TEAM_TOKEN }}
6868

69-
notify-slack:
69+
notify-linear:
7070
if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.event_name == 'schedule') }}
7171
needs: [e2e_test]
7272
runs-on: ubuntu-latest
73+
permissions:
74+
contents: read
75+
actions: read
7376
steps:
74-
- name: Notify Slack
77+
- name: "Gather failure context"
78+
id: ctx
7579
env:
76-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
80+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7781
run: |
78-
curl -X POST "$SLACK_WEBHOOK_URL" \
82+
FAILED=$(gh api \
83+
"repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}/jobs" \
84+
--paginate \
85+
--jq '[.jobs[]
86+
| select(.conclusion == "failure")
87+
| "- **\(.name)** — failed at _\([.steps[] | select(.conclusion == "failure") | .name] | join(", "))_"]
88+
| join("\n")')
89+
90+
if [ -z "$FAILED" ]; then
91+
FAILED="_(no failed jobs reported by the API yet)_"
92+
fi
93+
94+
{
95+
echo "failed_jobs<<CTXEOF"
96+
echo "$FAILED"
97+
echo "CTXEOF"
98+
} >> "$GITHUB_OUTPUT"
99+
- name: "Create Linear issue"
100+
env:
101+
LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
102+
LINEAR_TEAM_ID: ${{ secrets.LINEAR_TEAM_ID }}
103+
LINEAR_STATUS_ID: ${{ secrets.LINEAR_STATUS_PLAN_ID }}
104+
LINEAR_PROJECT_ID: ${{ secrets.LINEAR_PROJECT_ID }}
105+
LINEAR_ASSIGNEE_ID: ${{ secrets.LINEAR_ASSIGNEE_ID }}
106+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
107+
RUN_ATTEMPT: ${{ github.run_attempt }}
108+
EVENT_NAME: ${{ github.event_name }}
109+
SHA: ${{ github.sha }}
110+
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
111+
FAILED_JOBS: ${{ steps.ctx.outputs.failed_jobs }}
112+
run: |
113+
SHORT_SHA="${SHA:0:7}"
114+
115+
# head_commit is only populated on push events; skip the line otherwise
116+
COMMIT_LINE="**Commit:** \`$SHORT_SHA\`"
117+
if [ -n "$COMMIT_MESSAGE" ]; then
118+
COMMIT_SUBJECT="$(printf '%s' "$COMMIT_MESSAGE" | head -n1)"
119+
COMMIT_LINE="**Commit:** \`$SHORT_SHA\` — $COMMIT_SUBJECT"
120+
fi
121+
122+
ATTEMPT_NOTE=""
123+
if [ "$RUN_ATTEMPT" != "1" ]; then
124+
ATTEMPT_NOTE=" (attempt #$RUN_ATTEMPT)"
125+
fi
126+
127+
TITLE="E2E failure: ${{ github.workflow }} (${{ github.repository }})"
128+
DESCRIPTION=$(cat <<EOF
129+
**${{ github.workflow }}** failed on \`${{ github.ref_name }}\` in \`${{ github.repository }}\` via \`$EVENT_NAME\`$ATTEMPT_NOTE
130+
131+
**Failing jobs:**
132+
$FAILED_JOBS
133+
134+
$COMMIT_LINE
135+
136+
[View failing run]($RUN_URL)
137+
EOF
138+
)
139+
140+
PAYLOAD=$(jq -n \
141+
--arg query 'mutation IssueCreate($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { identifier url } } }' \
142+
--arg title "$TITLE" \
143+
--arg description "$DESCRIPTION" \
144+
--arg teamId "$LINEAR_TEAM_ID" \
145+
--arg assigneeId "$LINEAR_ASSIGNEE_ID" \
146+
--arg stateId "$LINEAR_STATUS_ID" \
147+
--arg projectId "$LINEAR_PROJECT_ID" \
148+
'{
149+
query: $query,
150+
variables: {
151+
input: {
152+
title: $title,
153+
description: $description,
154+
teamId: $teamId,
155+
assigneeId: $assigneeId,
156+
stateId: $stateId,
157+
projectId: $projectId,
158+
priority: 2
159+
}
160+
}
161+
}')
162+
163+
curl -sSf -X POST https://api.linear.app/graphql \
164+
-H "Authorization: $LINEAR_API_KEY" \
79165
-H 'Content-Type: application/json' \
80-
-d "{
81-
\"username\": \"E2E tests in Telemetry Terraform\",
82-
\"icon_emoji\": \":warning:\",
83-
\"text\": \":red_circle: *${{ github.workflow }}* failed on \`${{ github.ref_name }}\`\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View failing run>\"
84-
}"
166+
-d "$PAYLOAD"

0 commit comments

Comments
 (0)