-
Notifications
You must be signed in to change notification settings - Fork 0
525 lines (487 loc) · 23.7 KB
/
fly-deploy.yml
File metadata and controls
525 lines (487 loc) · 23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
#
# Pipeline shape: the deploy is split into a build phase that pushes
# images to registry.fly.io in parallel, and a release phase that points
# each Fly app at the pre-built image. The build phase is the slow part
# (~3 min on Fly's remote builder); decoupling it from release lets us
# build the shared hover/hover-worker image once instead of twice, and
# build the analysis image concurrently rather than after.
#
# Ordering invariant (preserved from the original workflow): hover-analysis
# (lighthouse consumer) must be live before hover-worker (lighthouse
# producer) starts XADDing onto the per-job lighthouse stream. The
# release-worker job declares needs: [release-analysis] to enforce this.
name: Fly Deploy
on:
push:
branches:
- main
paths-ignore:
- "**.md"
- "docs/**"
- "webflow-designer-extension/**"
- "webflow-designer-extension-cli/**"
- "LICENSE"
- ".gitignore"
- "CHANGELOG.md"
- "SECURITY.md"
- "Roadmap.md"
- "QandA.md"
# Workflow-level lock: only one full deploy run for this group is in
# flight at a time. cancel-in-progress: false so a second push to main
# queues behind the first rather than aborting it mid-release.
concurrency:
group: deploy-group
cancel-in-progress: false
jobs:
# ───────── Build phase ───────────────────────────────────────────────
# Two image builds run in parallel. The shared image carries both the
# API binary (cmd/app) and the worker binary (cmd/worker) — see
# Dockerfile lines 19–20 — so it is reused by both release-api and
# release-worker. The analysis image has its own runtime (Debian +
# Chromium) and is built independently.
build-shared:
name: Build hover image (API + worker)
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
image: ${{ steps.build.outputs.image }}
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Build and push hover image
id: build
env:
IMAGE_LABEL: deployment-${{ github.run_id }}-${{ github.run_attempt }}
run: |
flyctl deploy --build-only --push \
--image-label "$IMAGE_LABEL" \
--app hover
echo "image=registry.fly.io/hover:${IMAGE_LABEL}" >> "$GITHUB_OUTPUT"
build-analysis:
name: Build hover-analysis image
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
image: ${{ steps.build.outputs.image }}
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Build and push hover-analysis image
id: build
env:
IMAGE_LABEL: deployment-${{ github.run_id }}-${{ github.run_attempt }}
run: |
flyctl deploy --build-only --push \
--image-label "$IMAGE_LABEL" \
--config fly.analysis.toml \
--app hover-analysis
echo "image=registry.fly.io/hover-analysis:${IMAGE_LABEL}" >> "$GITHUB_OUTPUT"
# ───────── Release phase ─────────────────────────────────────────────
# release-api and release-analysis fan out in parallel as soon as their
# builds are ready. release-worker waits on release-analysis so the
# consumer is healthy before the producer starts publishing.
release-api:
name: Release hover (API)
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [build-shared]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Sync secrets to Fly (API app)
run: |
flyctl secrets set \
DATABASE_URL="$DATABASE_URL" \
DATABASE_DIRECT_URL="$DATABASE_DIRECT_URL" \
SUPABASE_JWT_SECRET="$SUPABASE_JWT_SECRET" \
SUPABASE_SERVICE_ROLE_KEY="$SUPABASE_SERVICE_ROLE_KEY" \
SENTRY_DSN="$SENTRY_DSN" \
LOOPS_API_KEY="$LOOPS_API_KEY" \
SLACK_CLIENT_SECRET="$SLACK_CLIENT_SECRET" \
WEBFLOW_CLIENT_SECRET="$WEBFLOW_CLIENT_SECRET" \
GOOGLE_CLIENT_SECRET="$GOOGLE_CLIENT_SECRET" \
OTEL_EXPORTER_OTLP_HEADERS="$OTEL_EXPORTER_OTLP_HEADERS" \
ARCHIVE_ACCESS_KEY_ID="$ARCHIVE_ACCESS_KEY_ID" \
ARCHIVE_SECRET_ACCESS_KEY="$ARCHIVE_SECRET_ACCESS_KEY" \
ARCHIVE_ENDPOINT="$ARCHIVE_ENDPOINT" \
GRAFANA_CLOUD_USER="$GRAFANA_CLOUD_USER" \
GRAFANA_CLOUD_API_KEY="$GRAFANA_CLOUD_API_KEY" \
REDIS_URL="$REDIS_URL" \
STRIPE_SECRET_KEY="$STRIPE_SECRET_KEY" \
STRIPE_WEBHOOK_SECRET="$STRIPE_WEBHOOK_SECRET" \
STRIPE_PUBLISHABLE_KEY="$STRIPE_PUBLISHABLE_KEY" \
--stage
- name: Release API app
env:
IMAGE: ${{ needs.build-shared.outputs.image }}
run: |
flyctl deploy --image "$IMAGE" --app hover
# Reap stale-image machines left behind by the new release —
# see PR #369 for why deploy alone isn't enough.
flyctl scale count 1 --process-group app -a hover --yes
release-analysis:
name: Release hover-analysis
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [build-analysis]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Sync secrets to Fly (analysis app)
run: |
# hover-analysis consumes the per-job lighthouse streams written
# by the dispatcher and writes audit metrics back to
# lighthouse_runs. Only secrets actually referenced by the
# analysis binary are synced; user-facing auth secrets are
# deliberately excluded.
flyctl secrets set \
--app hover-analysis \
DATABASE_URL="$DATABASE_URL" \
DATABASE_DIRECT_URL="$DATABASE_DIRECT_URL" \
REDIS_URL="$REDIS_URL" \
SENTRY_DSN="$SENTRY_DSN" \
OTEL_EXPORTER_OTLP_HEADERS="$OTEL_EXPORTER_OTLP_HEADERS" \
GRAFANA_CLOUD_USER="$GRAFANA_CLOUD_USER" \
GRAFANA_CLOUD_API_KEY="$GRAFANA_CLOUD_API_KEY" \
ARCHIVE_ACCESS_KEY_ID="$ARCHIVE_ACCESS_KEY_ID" \
ARCHIVE_SECRET_ACCESS_KEY="$ARCHIVE_SECRET_ACCESS_KEY" \
ARCHIVE_ENDPOINT="$ARCHIVE_ENDPOINT" \
--stage
- name: Release analysis app
env:
IMAGE: ${{ needs.build-analysis.outputs.image }}
run: |
flyctl deploy --image "$IMAGE" \
--config fly.analysis.toml \
--app hover-analysis
release-worker:
name: Release hover-worker
runs-on: blacksmith-4vcpu-ubuntu-2404
# Waits on build-shared for the image, and on release-analysis for
# the consumer-before-producer invariant.
needs: [build-shared, release-analysis]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Sync secrets to Fly (worker app)
run: |
# hover-worker consumes Redis streams, executes crawls, persists
# to Postgres + R2. Only secrets actually referenced by the
# worker binary are synced here; user-facing auth secrets
# (Supabase JWT, Slack/Webflow/Google OAuth client secrets) are
# deliberately excluded.
flyctl secrets set \
--app hover-worker \
DATABASE_URL="$DATABASE_URL" \
DATABASE_DIRECT_URL="$DATABASE_DIRECT_URL" \
REDIS_URL="$REDIS_URL" \
SENTRY_DSN="$SENTRY_DSN" \
OTEL_EXPORTER_OTLP_HEADERS="$OTEL_EXPORTER_OTLP_HEADERS" \
GRAFANA_CLOUD_USER="$GRAFANA_CLOUD_USER" \
GRAFANA_CLOUD_API_KEY="$GRAFANA_CLOUD_API_KEY" \
ARCHIVE_ACCESS_KEY_ID="$ARCHIVE_ACCESS_KEY_ID" \
ARCHIVE_SECRET_ACCESS_KEY="$ARCHIVE_SECRET_ACCESS_KEY" \
ARCHIVE_ENDPOINT="$ARCHIVE_ENDPOINT" \
--stage
- name: Release worker app
# Reuses the hover image from build-shared — Dockerfile compiles
# both binaries, fly.worker.toml selects the worker entrypoint.
env:
IMAGE: ${{ needs.build-shared.outputs.image }}
run: |
flyctl deploy --image "$IMAGE" \
--config fly.worker.toml \
--app hover-worker
# ───────── Pool reconcile ───────────────────────────────────────────
# Pool top-up runs in its own job so downstream autoscaler releases
# only block on the deploy itself, not on the (much slower) clone-
# start-stop cycle for each pre-warmed machine. IMAGE_LABEL is derived
# from the built image tag rather than github.run_attempt — if this
# job is retried, run_attempt bumps but build-*.outputs.image still
# points to the prior build's tag. Recomputing IMAGE_LABEL from
# run_attempt would cause the reconciler to mistake the just-deployed
# machines for stragglers and destroy them.
reconcile-analysis-pool:
name: Reconcile hover-analysis pool
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [build-analysis, release-analysis]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Reap stale-image machines and top up to 10 stopped clones
env:
IMAGE: ${{ needs.build-analysis.outputs.image }}
run: |
IMAGE_LABEL="${IMAGE##*:}"
bash scripts/fly-reconcile-pool.sh hover-analysis "$IMAGE_LABEL" 10
reconcile-worker-pool:
name: Reconcile hover-worker pool
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [build-shared, release-worker]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Reap stale-image machines and top up to 5 stopped clones
env:
IMAGE: ${{ needs.build-shared.outputs.image }}
run: |
IMAGE_LABEL="${IMAGE##*:}"
bash scripts/fly-reconcile-pool.sh hover-worker "$IMAGE_LABEL" 5
# ───────── Autoscaler release ────────────────────────────────────────
# fly-autoscaler 0.3.x targets one Fly app per autoscaler instance, so
# worker and analysis each get their own app. Both jobs run after their
# target's release succeeds — if the target's pool isn't reconciled,
# fly-autoscaler has no machines to start/stop. They run in parallel
# since the two autoscaler apps are independent.
release-autoscaler-worker:
name: Release hover-autoscaler-worker
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [reconcile-worker-pool]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Load fly-autoscaler tokens from 1Password
# Loaded inline (not in the shared fly-setup composite) so review-app
# CI doesn't need these 1Password fields to exist.
uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
FAS_API_TOKEN_WORKER: op://Good Native/hover-fly/FAS_API_TOKEN_WORKER
FAS_PROMETHEUS_TOKEN: op://Good Native/hover-fly/FAS_PROMETHEUS_TOKEN
- name: Sync secrets to autoscaler app
run: |
# Guard against blank tokens. 1Password's load-secrets-action
# fails loudly on missing fields, but an empty-but-present field
# would otherwise stage a blank FAS_API_TOKEN and silently break
# autoscaler authentication after deploy.
if [ -z "$FAS_API_TOKEN_WORKER" ]; then
echo "❌ FAS_API_TOKEN_WORKER is empty. Check op://Good Native/hover-fly/FAS_API_TOKEN_WORKER" >&2
exit 1
fi
if [ -z "$FAS_PROMETHEUS_TOKEN" ]; then
echo "❌ FAS_PROMETHEUS_TOKEN is empty. Check op://Good Native/hover-fly/FAS_PROMETHEUS_TOKEN" >&2
exit 1
fi
flyctl secrets set \
--app hover-autoscaler-worker \
FAS_API_TOKEN="$FAS_API_TOKEN_WORKER" \
FAS_PROMETHEUS_TOKEN="$FAS_PROMETHEUS_TOKEN" \
--stage
- name: Deploy hover-autoscaler-worker
run: |
flyctl deploy \
--config fly.autoscaler-worker.toml \
--app hover-autoscaler-worker
release-autoscaler-analysis:
name: Release hover-autoscaler-analysis
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [reconcile-analysis-pool]
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/fly-setup
with:
op-service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
- name: Load fly-autoscaler tokens from 1Password
# Loaded inline (not in the shared fly-setup composite) so review-app
# CI doesn't need these 1Password fields to exist.
uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
FAS_API_TOKEN_ANALYSIS:
op://Good Native/hover-fly/FAS_API_TOKEN_ANALYSIS
FAS_PROMETHEUS_TOKEN: op://Good Native/hover-fly/FAS_PROMETHEUS_TOKEN
- name: Sync secrets to autoscaler app
run: |
# Guard against blank tokens. 1Password's load-secrets-action
# fails loudly on missing fields, but an empty-but-present field
# would otherwise stage a blank FAS_API_TOKEN and silently break
# autoscaler authentication after deploy.
if [ -z "$FAS_API_TOKEN_ANALYSIS" ]; then
echo "❌ FAS_API_TOKEN_ANALYSIS is empty. Check op://Good Native/hover-fly/FAS_API_TOKEN_ANALYSIS" >&2
exit 1
fi
if [ -z "$FAS_PROMETHEUS_TOKEN" ]; then
echo "❌ FAS_PROMETHEUS_TOKEN is empty. Check op://Good Native/hover-fly/FAS_PROMETHEUS_TOKEN" >&2
exit 1
fi
flyctl secrets set \
--app hover-autoscaler-analysis \
FAS_API_TOKEN="$FAS_API_TOKEN_ANALYSIS" \
FAS_PROMETHEUS_TOKEN="$FAS_PROMETHEUS_TOKEN" \
--stage
- name: Deploy hover-autoscaler-analysis
run: |
flyctl deploy \
--config fly.autoscaler-analysis.toml \
--app hover-autoscaler-analysis
# ───────── Annotation ────────────────────────────────────────────────
# if: always() so a partial deploy still produces an annotation for
# observability. Annotation is best-effort — failures here log a
# warning but do not fail the workflow.
annotate:
name: Post deploy annotation to Grafana
runs-on: blacksmith-4vcpu-ubuntu-2404
needs:
[
release-api,
release-analysis,
release-worker,
release-autoscaler-worker,
release-autoscaler-analysis,
]
if: always()
steps:
- name: Load Grafana annotation secrets
continue-on-error: true
uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
GRAFANA_URL: op://Good Native/hover-runtime/GRAFANA_URL
GRAFANA_SA_TOKEN: op://Good Native/hover-runtime/GRAFANA_SA_TOKEN
- name: Post deploy annotation to Grafana
# Best-effort: a Grafana outage logs a warning but does not fail
# the workflow. Commit-message and ref are passed via env vars
# (not direct ${{ ... }} interpolation) to avoid shell-injection
# via crafted commit messages — see GitHub Actions injection
# guidance.
continue-on-error: true
env:
COMMIT_SHA: ${{ github.sha }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
REPO: ${{ github.repository }}
REF_NAME: ${{ github.ref_name }}
WORKFLOW_FILE: fly-deploy.yml
COMMIT_TAG_CAP: "20"
GH_TOKEN: ${{ github.token }}
run: |
set -o pipefail
if [ -z "${GRAFANA_URL:-}" ] || [ -z "${GRAFANA_SA_TOKEN:-}" ]; then
echo "::warning title=Grafana annotation skipped::GRAFANA_URL or GRAFANA_SA_TOKEN missing; skipping annotation."
exit 0
fi
short_sha="${COMMIT_SHA:0:7}"
commit_url="https://github.com/${REPO}/commit/${COMMIT_SHA}"
# PR detection — merge commits from GitHub include "(#NNN)" in
# the subject. Look up the PR via gh api so we get the canonical
# title rather than whatever shorthand appeared in the commit
# message.
pr_number="$(printf '%s' "$COMMIT_MESSAGE" | grep -oE '#[0-9]+' | head -n1 | tr -d '#' || true)"
pr_section=""
extra_tags_json='[]'
if [ -n "${pr_number}" ]; then
pr_json="$(gh api "repos/${REPO}/pulls/${pr_number}" 2>/dev/null || true)"
if [ -n "$pr_json" ] && [ "$(printf '%s' "$pr_json" | jq -r '.number // empty')" = "$pr_number" ]; then
pr_title="$(printf '%s' "$pr_json" | jq -r '.title')"
pr_url="$(printf '%s' "$pr_json" | jq -r '.html_url')"
pr_section="$(printf '## PR\n%s\n%s\n\n' "$pr_title" "$pr_url")"
extra_tags_json="$(jq -cn --arg pr "pr:${pr_number}" '[$pr]')"
fi
fi
# Commit range since previous successful deploy — walk workflow
# runs for this workflow file on main and pick the most recent
# success that isn't the current commit.
prev_sha="$(gh api "repos/${REPO}/actions/workflows/${WORKFLOW_FILE}/runs?branch=main&status=success&per_page=10" \
--jq "[.workflow_runs[] | select(.head_sha != \"${COMMIT_SHA}\")][0].head_sha" 2>/dev/null || true)"
commits_body=""
commit_tags_json='[]'
if [ -n "$prev_sha" ] && [ "$prev_sha" != "null" ]; then
compare_json="$(gh api "repos/${REPO}/compare/${prev_sha}...${COMMIT_SHA}" --paginate 2>/dev/null || true)"
if [ -n "$compare_json" ]; then
commits_body="$(printf '%s' "$compare_json" | jq -r '.commits[] | "\(.sha[0:7]) \(.commit.message | split("\n")[0])"')"
commit_tags_json="$(printf '%s' "$compare_json" | jq -c --argjson cap "${COMMIT_TAG_CAP}" '[.commits[].sha[0:7] | "commit:" + .] | .[0:$cap]')"
fi
fi
# Fallback — first deploy, or compare API unavailable: show the
# head commit only.
if [ -z "$commits_body" ]; then
first_line="$(printf '%s' "$COMMIT_MESSAGE" | head -n1)"
commits_body="$(printf '%s %s' "$short_sha" "$first_line")"
commit_tags_json="$(jq -cn --arg t "commit:${short_sha}" '[$t]')"
fi
# Derive service tags from the files changed in this deploy
# range. Falls back to the single-commit API when no compare
# range is available.
changed_files=""
if [ -n "$compare_json" ]; then
changed_files="$(printf '%s' "$compare_json" | jq -r '.files[].filename' 2>/dev/null || true)"
fi
if [ -z "$changed_files" ]; then
changed_files="$(gh api "repos/${REPO}/commits/${COMMIT_SHA}" --jq '.files[].filename' 2>/dev/null || true)"
fi
service_tags_json='[]'
# cmd/app is the API server; cmd/hover is the CLI tool.
if printf '%s\n' "$changed_files" | grep -qE '^(cmd/app/|internal/(api|archive|auth|cache|loops|notifications|storage|techdetect|util)/|web/)'; then
service_tags_json="$(jq -cn --argjson t "$service_tags_json" '$t + ["service:hover"]')"
fi
if printf '%s\n' "$changed_files" | grep -qE '^cmd/worker/'; then
service_tags_json="$(jq -cn --argjson t "$service_tags_json" '$t + ["service:hover-worker"]')"
fi
# hover-analysis surface: the analysis binary itself, its image
# config, fly app config, and the lighthouse package modules
# that only it consumes (runner). The shared lighthouse pieces
# (sampler, scheduler) are picked up by the broader internal/...
# clause below since the worker imports them too.
if printf '%s\n' "$changed_files" | grep -qE '^(cmd/analysis/|Dockerfile\.analysis|fly\.analysis\.toml|\.fly/review_apps\.analysis\.toml|internal/lighthouse/runner\.go)'; then
service_tags_json="$(jq -cn --argjson t "$service_tags_json" '$t + ["service:hover-analysis"]')"
fi
# Shared internal packages used by every service. Lighthouse
# producer code lives in internal/lighthouse and is imported by
# the worker; the consumer (analysis) imports the runner.
if printf '%s\n' "$changed_files" | grep -qE '^internal/(broker|crawler|db|jobs|lighthouse|logging|observability)/'; then
service_tags_json="$(jq -cn --argjson t "$service_tags_json" '$t + ["service:hover","service:hover-worker","service:hover-analysis"]')"
fi
if printf '%s\n' "$changed_files" | grep -qE '^(cmd/hover/|webflow-designer-extension-cli/|npm/)'; then
service_tags_json="$(jq -cn --argjson t "$service_tags_json" '$t + ["service:hover-cli"]')"
fi
if printf '%s\n' "$changed_files" | grep -qE '^(grafana/|\.github/|scripts/)'; then
service_tags_json="$(jq -cn --argjson t "$service_tags_json" '$t + ["service:grafana"]')"
fi
if printf '%s\n' "$changed_files" | grep -qE '^supabase/'; then
service_tags_json="$(jq -cn --argjson t "$service_tags_json" '$t + ["service:supabase"]')"
fi
# Fallback — unrecognised paths: tag every service conservatively.
if [ "$service_tags_json" = "[]" ]; then
service_tags_json='["service:hover","service:hover-worker","service:hover-analysis"]'
fi
body_text="$(printf '%s## Commits\n%s\n%s' "$pr_section" "$commits_body" "$commit_url")"
tags_json="$(jq -cn \
--arg ref "$REF_NAME" \
--arg sha "$short_sha" \
--argjson extra "$extra_tags_json" \
--argjson commits "$commit_tags_json" \
--argjson services "$service_tags_json" \
'(["deploy","env:production",
("branch:" + $ref), ("commit:" + $sha)] + $services + $extra + $commits) | unique')"
now_ms=$(($(date +%s) * 1000))
payload="$(jq -n \
--argjson time "$now_ms" \
--arg text "$body_text" \
--argjson tags "$tags_json" \
'{time: $time, tags: $tags, text: $text}')"
if ! curl --fail --silent --show-error \
--connect-timeout 5 --max-time 15 \
-X POST "${GRAFANA_URL%/}/api/annotations" \
-H "Authorization: Bearer ${GRAFANA_SA_TOKEN}" \
-H "Content-Type: application/json" \
-d "$payload"; then
echo "::warning title=Grafana annotation failed::Deploy succeeded but annotation POST failed. Check GRAFANA_URL and GRAFANA_SA_TOKEN in 1Password."
fi