Skip to content

ci(assets): auto-fix image compression on PRs touching posts/assets/ #46

Description

@wab

Parent

#32 (asset pipeline migration milestone)

Problem

Future non-tech contributors will add images by dragging files into the repo (or via the planned content-authoring skills). Expecting them to run pnpm install && node scripts/optimize-assets.js --write locally is a non-starter — they don't have Node, won't remember the step, and a missed run silently bloats the new blob store.

Manual compression doesn't scale. The repo needs a guardrail.

What to build

GitHub Action that runs on every PR touching posts/assets/**:

  1. Checkout the PR branch with write permission (use a GitHub App token, or actions/checkout with persist-credentials + a PAT, or the built-in GITHUB_TOKEN configured with contents: write and pull-requests: write)
  2. pnpm install
  3. Run node scripts/optimize-assets.js --write (the generalised script from the sibling follow-up feat(assets): generalise compression script across all asset categories #45)
  4. If files changed: commit back to the PR branch with chore(assets): auto-compress images [skip ci], push
  5. If nothing changed: exit clean
  6. Post a sticky PR comment on first auto-fix with what was compressed and the size delta

Optional but valuable:

  • Add a [ci skip-compression] flag in PR body to bypass (escape hatch for intentional high-fidelity originals)
  • Cache node_modules to keep the action fast

Acceptance criteria

  • .github/workflows/optimize-assets.yml exists, triggers on pull_request paths matching posts/assets/**
  • Action commits compressed files back to the PR branch when reduction is non-trivial
  • Action is idempotent — second run on the same PR is a no-op
  • Sticky PR comment summarises what was compressed (only posted when something changed)
  • [ci skip-compression] in PR body bypasses the action
  • Action does not loop infinitely on its own commits (use [skip ci] or a path-based guard)

Blocked by

Notes

DX follow-up from #41 — companion to #45. Together they form the non-tech contributor flow: drag image into PR → CI compresses + commits back → reviewer sees the cleaned diff. No local Node setup required.

Same approach could later be extended to: lint frontmatter, validate Zod schemas, check for orphan references — this is the foundation for the broader "asset guardrails" theme.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready-for-agentScoped, dependencies clear, acceptance criteria explicit — grabbable by an AFK agent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions