mirror of
https://github.com/nexu-io/open-design.git
synced 2026-09-20 06:15:06 +08:00
f4fe5ad757
* feat(ci): bake pipeline slice 1 — previews-diff guard + single rolling PR Per specs/change/20260618-plugin-preview-bake-pipeline/spec.md rollout step 1 (the smallest change that stops the bleeding on the stacked bake-PR backlog). - scripts/plugin-previews-diff.mjs: decide whether a manifest's `previews` subtree changed, ignoring the per-run `generatedAt` timestamp. node:test coverage in plugin-previews-diff.test.mjs (the #4261 timestamp-only noise case, entry change, add/remove, key-order stability). - bake-plugin-previews.yml: open a review PR only when `previews` actually changed (was: whole-file `git diff` that fired every run because of generatedAt), and reuse ONE rolling branch (chore/plugin-previews) / force-update the open PR in place instead of stacking chore/plugin-previews-<run_id> per run. - guard.ts: allowlist the two new CI-only .mjs scripts. Deferred to later slices (same spec): pre-merge same-repo coupling job, release-cut full bake, tag-union GC, directory-layered artifact keys. * feat(ci): bake pipeline slices 2-4 — pre-merge coupling, release full bake, GC, directory keys Completes the spec (specs/change/20260618-plugin-preview-bake-pipeline) on top of slice 1, all in one PR (GC ships dry-run so staged ENABLEMENT still holds): - .github/actions/bake-previews: composite action for the shared render + R2 upload core, so the three bake workflows stop duplicating it. - bake-plugin-previews.yml (post-merge): refactored onto the composite; role is now uploader + fork path + nightly backstop (rolling PR unchanged). - bake-plugin-previews-pr.yml (slice 2): pre-merge bake for SAME-REPO PRs — renders, uploads, and commits the manifest INTO the author's branch so it rides with the code change. Loop guard checks the head COMMIT author (git log -1 %ae of head.sha, fetched via full checkout), not head.user.login, plus a no-op previews-diff guard. Forks fall through to post-merge. - bake-plugin-previews-release.yml (slice 3): release-cut full bake committing the authoritative manifest onto release/**, with paths-ignore + bot-author loop guards. - scripts/bake-plugin-previews.mjs (slice 4a): directory-layered, content- addressed keys <id>/<fingerprint>/preview.mp4 (+ poster.jpg), prefix-relative in the manifest. Daemon consumer already resolves base+key / path.join(dir,key) so no consumer change; reused flat entries are left untouched (additive). - scripts/plugin-previews-gc.mjs (slice 4b) + .github/workflows/ bake-plugin-previews-gc.yml: weekly R2 GC. Protected set = keys referenced by every tag + live release/** HEAD + main; deletes orphans older than a 90d grace window. DRY-RUN by default (needs --delete AND GC_ENABLE_DELETE=1). Pure protected-set/orphan logic covered by node:test. - guard.ts: allowlist the new CI-only .mjs files. * fix(ci): capture diff-guard result on its own line so a helper error fails the step Per review: `if [ "$(node plugin-previews-diff.mjs ...)" != changed ]` swallows the helper's exit 2 (bad args / unreadable manifest) inside command substitution, so an error reads as empty string → 'unchanged' branch → the manifest PR/commit is silently skipped despite a successful bake. Capture into diff_result on its own line (so `set -e` aborts on a helper error) and `case` on the value, treating unexpected output as a workflow failure. Applied to all three bake workflows. * fix(ci): satisfy actionlint — quote gc description colon + route PR/dispatch context through env - bake-plugin-previews-gc.yml: quote the `delete` input description (the '(default: ...)' colon broke YAML parsing) and pass dispatch inputs via env (GC_DELETE/GC_GRACE_DAYS) instead of interpolating into the run body. - bake-plugin-previews-pr.yml: route head.sha/head.ref through HEAD_SHA/HEAD_REF env vars to avoid the script-injection lint on untrusted PR context. * fix(ci): hard-gate the release bake job to release/** branches workflow_dispatch can fire from any ref; the commit step pushes the authoritative manifest to the triggering ref with contents:write, so a dispatch on main would write straight to main and bypass the release back-merge. Add a job-level `if: startsWith(github.ref, 'refs/heads/release/')` guard. * fix(ci): GC fails closed on partial protected-ref data Per review (non-blocking but real once deletion is armed): the GC workflow's protected-ref fetches ended with '|| true', so a transient fetch failure could leave the tag/release/main protected set incomplete and, with GC_ENABLE_DELETE=1, prune clips a live release/main still references. Drop the '|| true' (fail the job if the protected refs can't be fetched), and add a script-side guard that refuses to delete when the protected set is empty or origin/main's manifest is unreadable.
75 lines
3.0 KiB
YAML
75 lines
3.0 KiB
YAML
name: bake-plugin-previews-gc
|
|
|
|
# Weekly garbage collection of orphaned plugin-preview clips on R2 (spec slice
|
|
# 4b). Preview clips are immutable + content-addressed, so the bucket only grows;
|
|
# this prunes clips that NO live build references. The protected set is the union
|
|
# of object keys named by every git tag's manifest, every live release/** branch
|
|
# HEAD, and the current main manifest — so a clip a shipped/old client still
|
|
# points at is never deleted (see scripts/plugin-previews-gc.mjs).
|
|
#
|
|
# Ships in DRY-RUN: it only reports what it would delete. Arming real deletion
|
|
# needs BOTH the `delete` input AND the GC_ENABLE_DELETE env below — flip them
|
|
# only after eyeballing a few dry-run deletion lists.
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '0 6 * * 1' # Mondays 06:00 UTC
|
|
workflow_dispatch:
|
|
inputs:
|
|
delete:
|
|
description: 'Actually delete orphans (default: dry-run report only).'
|
|
type: boolean
|
|
default: false
|
|
grace-days:
|
|
description: Minimum age in days before an orphan may be deleted.
|
|
type: string
|
|
default: '90'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: bake-plugin-previews-gc
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
gc:
|
|
name: GC orphaned preview clips
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v6.0.2
|
|
with:
|
|
fetch-depth: 0 # need all tags + refs to build the protected set
|
|
|
|
- name: Fetch release branches + tags (fail closed)
|
|
# No `|| true`: these refs define the protected set. If we cannot fetch
|
|
# them, fail the job rather than GC from partial ref data — once deletion
|
|
# is armed, an incomplete protected set could prune clips a live release
|
|
# or main manifest still references.
|
|
run: |
|
|
git fetch --tags --force origin '+refs/heads/release/*:refs/remotes/origin/release/*'
|
|
git fetch origin main:refs/remotes/origin/main
|
|
|
|
- name: Garbage-collect (dry-run unless armed)
|
|
env:
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_AK }}
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_SK }}
|
|
AWS_DEFAULT_REGION: auto
|
|
AWS_EC2_METADATA_DISABLED: 'true'
|
|
R2_BUCKET: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_BUCKET }}
|
|
R2_ENDPOINT: ${{ secrets.CLOUDFLARE_R2_REPOSITORY_ASSETS_URL }}
|
|
# Second arming switch. Leave unset/empty to keep deletions disabled even
|
|
# if someone passes --delete; set to '1' here only when ready to prune.
|
|
GC_ENABLE_DELETE: ''
|
|
# Dispatch inputs via env (never interpolated into the script body) to
|
|
# avoid script injection.
|
|
GC_DELETE: ${{ github.event.inputs.delete }}
|
|
GC_GRACE_DAYS: ${{ github.event.inputs.grace-days }}
|
|
run: |
|
|
GRACE="${GC_GRACE_DAYS:-90}"
|
|
DELETE_FLAG=""
|
|
if [ "$GC_DELETE" = "true" ]; then DELETE_FLAG="--delete"; fi
|
|
node scripts/plugin-previews-gc.mjs --grace-days "$GRACE" $DELETE_FLAG
|