Skip to content

Commit 7cb6438

Browse files
Mlaz-codeCodexclaude
authored
ci: notify Paperclip on workflow failure (SHA-1698) (#251)
Add a "Notify on failure" step to the deploy-dev, deploy-prod, and upstream-notify workflows. On any failure of the primary work job the step extracts a SHA-NNNN identifier from the commit/branch and either comments+blocks the existing Paperclip issue or opens a new critical issue assigned to this repo's fallback agent for triage. The Paperclip PATCH/POST curl logic mirrors the api-adapters deploy-prod reference verbatim; only the human-readable echo text, fallback issue title, and assigneeAgentId differ per workflow/repo. The rollback-hint echo is kept only on deploy-prod (the sole workflow with a rollback path). Fixes SHA-1698 Type: ci Co-authored-by: Codex <codex@sharpapi.local> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f0b5402 commit 7cb6438

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

.github/workflows/deploy-dev.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,43 @@ jobs:
7979
echo "## Preview Deployment" >> $GITHUB_STEP_SUMMARY
8080
echo "**URL**: $DEPLOYMENT_URL" >> $GITHUB_STEP_SUMMARY
8181
82+
- name: Notify on failure
83+
if: failure()
84+
env:
85+
PAPERCLIP_API_URL: ${{ secrets.PAPERCLIP_API_URL }}
86+
PAPERCLIP_API_KEY: ${{ secrets.PAPERCLIP_API_KEY }}
87+
run: |
88+
echo "::error::Deployment to dev preview failed. Check the logs above for details."
89+
90+
# Extract Paperclip issue identifier from branch name or commit message
91+
COMMIT_MSG=$(git log -1 --format=%s ${{ github.sha }})
92+
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'SHA-\d+' | head -1)
93+
94+
# If no issue in commit message, check the merge branch name
95+
if [ -z "$ISSUE_ID" ]; then
96+
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'paperclip/(SHA-\d+)' | head -1 | sed 's|paperclip/||')
97+
fi
98+
99+
if [ -n "$ISSUE_ID" ] && [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
100+
# Comment on the existing issue
101+
COMMENT="## CI Deploy Failed\n\n**Workflow**: ${{ github.workflow }}\n**Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n**Commit**: \`${{ github.sha }}\`\n\nThe deploy to prod failed. Check the CI logs and fix the issue. Do NOT mark this issue as done until a successful deploy is verified."
102+
curl -sf -X PATCH "$PAPERCLIP_API_URL/issues/$ISSUE_ID" \
103+
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
104+
-H "Content-Type: application/json" \
105+
-d "$(jq -n --arg status "blocked" --arg comment "$COMMENT" '{status: $status, comment: $comment}')" || true
106+
echo "Commented on Paperclip issue $ISSUE_ID"
107+
elif [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
108+
# No issue found — create one assigned to Coordinator for triage
109+
curl -sf -X POST "$PAPERCLIP_API_URL/companies/953ff6b0-4d1b-4007-9859-8cb0a53629f6/issues" \
110+
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
111+
-H "Content-Type: application/json" \
112+
-d "$(jq -n \
113+
--arg title "CI Failed: docs.sharpapi.io (${{ github.ref_name }})" \
114+
--arg desc "GitHub Actions workflow **${{ github.workflow }}** failed.\n\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\nCommit: \`$(git log -1 --format='%h %s' ${{ github.sha }})\`\n\nInvestigate and fix." \
115+
'{title: $title, description: $desc, status: "todo", priority: "critical", assigneeAgentId: "3a976364-1186-4c30-a136-bba410c2209c"}')" || true
116+
echo "Created Paperclip issue for deploy failure"
117+
fi
118+
82119
health-check:
83120
name: Health Check
84121
needs: deploy-preview

.github/workflows/deploy-prod.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,44 @@ jobs:
118118
echo "**URL**: ${{ env.PRODUCTION_URL }}" >> $GITHUB_STEP_SUMMARY
119119
echo "**Deployment**: $DEPLOYMENT_URL" >> $GITHUB_STEP_SUMMARY
120120
121+
- name: Notify on failure
122+
if: failure()
123+
env:
124+
PAPERCLIP_API_URL: ${{ secrets.PAPERCLIP_API_URL }}
125+
PAPERCLIP_API_KEY: ${{ secrets.PAPERCLIP_API_KEY }}
126+
run: |
127+
echo "::error::Deployment to prod failed. Check the logs above for details."
128+
echo "To rollback, run this workflow manually with 'rollback' set to true."
129+
130+
# Extract Paperclip issue identifier from branch name or commit message
131+
COMMIT_MSG=$(git log -1 --format=%s ${{ github.sha }})
132+
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'SHA-\d+' | head -1)
133+
134+
# If no issue in commit message, check the merge branch name
135+
if [ -z "$ISSUE_ID" ]; then
136+
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'paperclip/(SHA-\d+)' | head -1 | sed 's|paperclip/||')
137+
fi
138+
139+
if [ -n "$ISSUE_ID" ] && [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
140+
# Comment on the existing issue
141+
COMMENT="## CI Deploy Failed\n\n**Workflow**: ${{ github.workflow }}\n**Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n**Commit**: \`${{ github.sha }}\`\n\nThe deploy to prod failed. Check the CI logs and fix the issue. Do NOT mark this issue as done until a successful deploy is verified."
142+
curl -sf -X PATCH "$PAPERCLIP_API_URL/issues/$ISSUE_ID" \
143+
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
144+
-H "Content-Type: application/json" \
145+
-d "$(jq -n --arg status "blocked" --arg comment "$COMMENT" '{status: $status, comment: $comment}')" || true
146+
echo "Commented on Paperclip issue $ISSUE_ID"
147+
elif [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
148+
# No issue found — create one assigned to Coordinator for triage
149+
curl -sf -X POST "$PAPERCLIP_API_URL/companies/953ff6b0-4d1b-4007-9859-8cb0a53629f6/issues" \
150+
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
151+
-H "Content-Type: application/json" \
152+
-d "$(jq -n \
153+
--arg title "CI Failed: docs.sharpapi.io (${{ github.ref_name }})" \
154+
--arg desc "GitHub Actions workflow **${{ github.workflow }}** failed.\n\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\nCommit: \`$(git log -1 --format='%h %s' ${{ github.sha }})\`\n\nInvestigate and fix." \
155+
'{title: $title, description: $desc, status: "todo", priority: "critical", assigneeAgentId: "3a976364-1186-4c30-a136-bba410c2209c"}')" || true
156+
echo "Created Paperclip issue for deploy failure"
157+
fi
158+
121159
rollback:
122160
name: Rollback
123161
runs-on: ubuntu-latest

.github/workflows/upstream-notify.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,40 @@ jobs:
9393
echo "**Commit**: ${{ github.event.client_payload.commit }}"
9494
echo "**Changed**: ${{ github.event.client_payload.changed_files }}"
9595
} >> "$GITHUB_STEP_SUMMARY"
96+
97+
- name: Notify on failure
98+
if: failure()
99+
env:
100+
PAPERCLIP_API_URL: ${{ secrets.PAPERCLIP_API_URL }}
101+
PAPERCLIP_API_KEY: ${{ secrets.PAPERCLIP_API_KEY }}
102+
run: |
103+
echo "::error::Upstream notification run failed. Check the logs above for details."
104+
105+
# Extract Paperclip issue identifier from branch name or commit message
106+
COMMIT_MSG=$(git log -1 --format=%s ${{ github.sha }})
107+
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'SHA-\d+' | head -1)
108+
109+
# If no issue in commit message, check the merge branch name
110+
if [ -z "$ISSUE_ID" ]; then
111+
ISSUE_ID=$(echo "$COMMIT_MSG" | grep -oP 'paperclip/(SHA-\d+)' | head -1 | sed 's|paperclip/||')
112+
fi
113+
114+
if [ -n "$ISSUE_ID" ] && [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
115+
# Comment on the existing issue
116+
COMMENT="## CI Deploy Failed\n\n**Workflow**: ${{ github.workflow }}\n**Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n**Commit**: \`${{ github.sha }}\`\n\nThe deploy to prod failed. Check the CI logs and fix the issue. Do NOT mark this issue as done until a successful deploy is verified."
117+
curl -sf -X PATCH "$PAPERCLIP_API_URL/issues/$ISSUE_ID" \
118+
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
119+
-H "Content-Type: application/json" \
120+
-d "$(jq -n --arg status "blocked" --arg comment "$COMMENT" '{status: $status, comment: $comment}')" || true
121+
echo "Commented on Paperclip issue $ISSUE_ID"
122+
elif [ -n "$PAPERCLIP_API_URL" ] && [ -n "$PAPERCLIP_API_KEY" ]; then
123+
# No issue found — create one assigned to Coordinator for triage
124+
curl -sf -X POST "$PAPERCLIP_API_URL/companies/953ff6b0-4d1b-4007-9859-8cb0a53629f6/issues" \
125+
-H "Authorization: Bearer $PAPERCLIP_API_KEY" \
126+
-H "Content-Type: application/json" \
127+
-d "$(jq -n \
128+
--arg title "CI Failed: docs.sharpapi.io (${{ github.ref_name }})" \
129+
--arg desc "GitHub Actions workflow **${{ github.workflow }}** failed.\n\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\nCommit: \`$(git log -1 --format='%h %s' ${{ github.sha }})\`\n\nInvestigate and fix." \
130+
'{title: $title, description: $desc, status: "todo", priority: "critical", assigneeAgentId: "3a976364-1186-4c30-a136-bba410c2209c"}')" || true
131+
echo "Created Paperclip issue for deploy failure"
132+
fi

0 commit comments

Comments
 (0)