ci(preview): preview-link PR comments — survive re-deploys, report deploy metadata #17

Merged
michalvankodev merged 3 commits from ci/preview-comment into redesign/00-foundation 2026-09-10 10:05:08 +02:00

What

Brings the <!-- preview-link --> PR comment feature onto the foundation line — rebased from the original ef5403a/74eaea7, then reworked after live verification exposed real bugs (2ad80d7).

The feature

After each preview deploy, one marker comment is upserted on the PR (POST first, PATCH on re-deploys — never spams). Teardown PATCHes it to "removed" so closed PRs carry no dead link. Best-effort: API failure → ::warning::, never fails the job.

The comment reports:

commit short SHA
deployed UTC timestamp
build duration (clock from npm install)
dist size total + ▲/▼ delta vs the previous deploy of that preview
changed vs prod rsync itemize count (hf hardlink = unchanged, excluded)
pages rendered html count
image cache % hit — prod-restored variants vs final dist count

Bugs found & fixed during verification

  1. Push-triggered re-deploys never updated the comment — github.event.pull_request is empty on push events, so PR_NUMBER/HEAD_SHA were blank. meta now resolves + outputs the PR number (jq lookup on open PRs); comment steps consume it either way.
  2. numfmt rejects negative deltas as options — human() now passes -- (caught live: the ▼ line rendered empty).
  3. Old teardown used the [ -z ] && { exit 0; } foot-gun — now an if.

Verified on the runner host (katelyn)

  • Exact step scripts executed with the runner's env (GITHUB_API_URL includes /api/v1 — confirmed via throwaway probe run #276)
  • POST → re-deploy PATCH (always exactly one marker comment) → teardown "removed" → scratch comment cleaned up
  • rsync itemize counting validated against a fixture (hf excluded, changed/new/deleted counted)
  • All run blocks pass bash -n
## What Brings the `<!-- preview-link -->` PR comment feature onto the foundation line — rebased from the original `ef5403a`/`74eaea7`, then **reworked after live verification exposed real bugs** (`2ad80d7`). ### The feature After each preview deploy, one marker comment is upserted on the PR (POST first, PATCH on re-deploys — never spams). Teardown PATCHes it to "removed" so closed PRs carry no dead link. Best-effort: API failure → `::warning::`, never fails the job. The comment reports: | | | |---|---| | commit | short SHA | | deployed | UTC timestamp | | build | duration (clock from `npm install`) | | dist size | total + ▲/▼ delta vs the previous deploy of that preview | | changed vs prod | rsync itemize count (`hf` hardlink = unchanged, excluded) | | pages | rendered html count | | image cache | % hit — prod-restored variants vs final dist count | ### Bugs found & fixed during verification 1. **Push-triggered re-deploys never updated the comment** — `github.event.pull_request` is empty on `push` events, so `PR_NUMBER`/`HEAD_SHA` were blank. `meta` now resolves + outputs the PR number (jq lookup on open PRs); comment steps consume it either way. 2. **`numfmt` rejects negative deltas as options** — `human()` now passes `--` (caught live: the ▼ line rendered empty). 3. Old teardown used the `[ -z ] && { exit 0; }` foot-gun — now an `if`. ### Verified on the runner host (katelyn) - Exact step scripts executed with the runner's env (`GITHUB_API_URL` includes `/api/v1` — confirmed via throwaway probe run #276) - POST → re-deploy PATCH (always exactly one marker comment) → teardown "removed" → scratch comment cleaned up - rsync itemize counting validated against a fixture (`hf` excluded, changed/new/deleted counted) - All run blocks pass `bash -n`
Upsert a marker comment (<!-- preview-link -->) via GITHUB_TOKEN after
deploy — POST first, PATCH on re-deploys (one comment per PR, no spam).
Teardown PATCHes it to 'removed' so closed PRs keep no dead link. Both
steps are best-effort (:⚠️: on API failure, never fail the job).
Tunnel host is the only Forgejo route; katelyn LAN ssh is host-admin
only; fj CLI installed and authenticated. No usernames, ports or key
material — those live in ~/.ssh/config and fish vars on phoebe.
ci(preview): comment survives re-deploys + reports deploy metadata
All checks were successful
preview / preview hostname (push) Successful in 0s
preview / build + deploy preview (push) Has been skipped
preview / teardown preview (push) Has been skipped
test / cargo test (push) Successful in 57s
preview / preview hostname (pull_request) Successful in 0s
preview / build + deploy preview (pull_request) Has been skipped
preview / teardown preview (pull_request) Successful in 0s
2ad80d7c36
- meta now resolves and outputs the PR number for push-triggered
  re-deploys (github.event.pull_request is empty on push events — the
  comment step used to silently skip them); comment/teardown steps take
  PR_NUMBER from meta either way
- deploy step captures previous preview size before rsync --delete plus
  new size, page count and UTC timestamp (GITHUB_ENV)
- comment upserts a marker comment with commit, deploy time, dist size
  delta (numfmt) and page count; teardown marks it removed
- HEAD_SHA falls back to github.sha on push events

🪦 Live preview

removed (PR closed)

<!-- preview-link --> ## 🪦 Live preview removed (PR closed)
michalvankodev merged commit d0243d8d42 into redesign/00-foundation 2026-09-10 10:05:08 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
michalvankodev/michalvankodev-site!17
No description provided.