Skip to content

feat(alerts): deploy lifecycle alerts (start/end/fail) via ANS - #1474

Merged
jung-thomas merged 8 commits into
mainfrom
worktree-deploy-lifecycle-alerts
Aug 4, 2026
Merged

feat(alerts): deploy lifecycle alerts (start/end/fail) via ANS#1474
jung-thomas merged 8 commits into
mainfrom
worktree-deploy-lifecycle-alerts

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

What

Adds automatic team notifications when a PROD (and dev/qa) deploy starts, finishes, or fails, reusing the SAP Alert Notification (ANS) plumbing wired yesterday (@sap-tutorials/cds-alert-notification).

Why

Deploys were silent — the operator watched a terminal and nobody else knew. This surfaces each deploy lifecycle boundary as a push notification.

How

The ANS credentials are bound to the tutorials-srv CF app, but scripts/deploy-mta.cjs runs off-platform (workstation/CI) with no ANS binding. So the srv exposes an endpoint the deploy script pings:

  • POST /ops/deploy-event (new, srv/routes/deploy-events.js) — bearer-guarded by the existing contentAuthMiddleware (reuses CONTENT_API_KEY). Maps {phase, env, version, detail}alerting.raise(...). Fail-open: always 202 on a valid phase, 400 on a bad one; never blocks a deploy.
  • scripts/deploy-mta.cjs — new notifyDeploy() helper (native fetch, 5s timeout, never throws, never changes exit code) fired at three boundaries for all envs: start (before cf deploy), end (after the smoke gate passes), fail (on cf deploy or smoke-gate failure).
  • package.json — registers DeployStarted/DeployFinished/DeployFailed eventTypes + a dedicated email:devrel-deploys channel.

Routing

  • DeployStarted/DeployFinished → severity NOTICEemail:devrel-deploys only.
  • DeployFailed → severity ERRORemail:devrel-deploys and email:devrel-oncall (on-call should hear failed deploys).

Post-merge / operator TODO (not in this PR)

  1. Provision the devrel-deploys email action in ANS with the real distribution-list address (same pattern as devrel-oncall).
  2. Flip ChatSettings.alertsEnabled ON in the target env(s) via /admin-ui (default OFF).
  3. CONTENT_API_KEY must be present in the deploy env (it already is for content publish).

Caveats

  • Blue-green: a --strategy blue-green deploy pauses before the traffic swap and exits, so it emits start and (on failure) fail, but not an automatic finished — documented in the runbook + a warn line. Accepted for v1.
  • Self-suppression edge case (accepted by Tom): a deploy that flips alertsEnabled can suppress its own end/fail ping.

Testing

  • 13 new unit tests (route mapping, 202/400, fail-open, notifyDeploy bearer/never-reject/no-op, routing config) — all green.
  • Full suite: 7238 pass; the 28 failures are pre-existing and unrelated to this branch.
  • .deploy/mta.yaml minor version bump 1.10.0 → 1.11.0.

Spec: docs/superpowers/specs/2026-08-04-deploy-lifecycle-alerts-design.md
Plan: docs/superpowers/plans/2026-08-04-deploy-lifecycle-alerts.md

🤖 Generated with Claude Code

- Add notifyDeploy() async helper to scripts/deploy-mta.cjs: best-effort
  POST to ${cfg.srvUrl}/ops/deploy-event with Bearer auth, 5s AbortController
  timeout, never throws, no new npm deps (native fetch + AbortController).
- Wire deployVersion (from writeVersionFile or readMtaVersion on --skip-build)
  and fire at: start (before cf deploy), fail (cf deploy failure + smoke gate
  failure), end (after smoke passes). Blue-green paused path logs a warn that
  no auto "end" will fire.
- Guard require.main === module so tests can require() without running main().
- Export { notifyDeploy } for the test seam.
- Add scripts/__tests__/notify-deploy.test.js (3 tests: POST payload+auth,
  network-error never-rejects, no-op when apiKey absent).
- Fix vitest.config.ts unit project include patterns to match .test.js
  (was .test.ts only for scripts/__tests__/) and add globals:true so CJS
  test files get describe/it/expect/vi injected.
@jung-thomas
jung-thomas merged commit f5da07f into main Aug 4, 2026
6 checks passed
@jung-thomas
jung-thomas deleted the worktree-deploy-lifecycle-alerts branch August 4, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant