Building a Fully Automated Daily Content Pipeline

Scheduled GitHub Actions, object storage, Playwright for images, ffmpeg for video and an API to post, the shape of a daily pipeline that runs unattended.

3 min read

A daily content pipeline is a small distributed system that happens to produce pictures. Every part of it is boring on its own, and the interesting work is making the whole thing recoverable, because it runs unattended and nobody is watching when it breaks.

What follows is the shape of one, described generically. The content is whatever you make; the architecture is the reusable part.

The shape

Scheduling on GitHub Actions

The runner is a fresh machine every time, which is a feature: nothing carries over, so nothing drifts. It is also the constraint, because there is no local state you can rely on.

on:
  schedule:
    # Cron is UTC and drifts up to ~15 min under load. Do not schedule at :00.
    - cron: '17 2 * * *'
  workflow_dispatch: {} # so a failed day can be re-run by hand

Two habits that matter more than they look:

  • Never rely on the schedule being exact. Ask for 02:17, not 02:00, and write the job so that running twice produces the same result.
  • Always add workflow_dispatch. The first time you need to re-run a day by hand, you will be glad it is a button.

Rendering images with a headless browser

Playwright is the pragmatic choice: you write HTML and CSS and screenshot it. If you can build a web page, you can build a template.

const page = await browser.newPage({ viewport: { width: 1080, height: 1080 } });
await page.setContent(html, { waitUntil: 'networkidle' });
// Fonts are the classic failure: wait for them explicitly or the render is wrong.
await page.evaluate(() => document.fonts.ready);
await page.screenshot({ path: 'out.png' });

The one non-obvious rule: wait for fonts explicitly. A headless render that races the font loader produces a correct-looking image in the wrong typeface, and it only happens on some days, which is the worst kind of bug.

Assembling video with ffmpeg

ffmpeg turns a sequence of stills and an audio track into something postable. It is worth learning the handful of commands rather than a wrapper library, because you will need to debug them.

The failure that catches people: ffmpeg needs an even number of pixels in both dimensions for most codecs, and an odd source silently produces a broken file on some encoders and not others.

Storage and the ledger

Artefacts go to object storage, never into the repository. A git history full of daily binaries is slow forever and cannot be cleaned up, the same reason media belongs in a bucket and not in git.

Then the part everyone skips until the first bad week: a ledger. One row or file per day, recording what was generated, its hash, and to which destinations it was posted. Without it you cannot answer the only question that matters when something looks wrong, did it not publish, or did it publish twice?

The posting adapters

One adapter per destination, each with the same interface: given an artefact from the ledger, publish or return a clear refusal. Keep the formatting rules for each destination inside its adapter, because they change often and they are nobody else’s business.

Rate limits belong here too, not in the scheduler. A destination that accepts ten a day and refuses the eleventh is a property of that adapter.

What breaks, and in what order

  1. 01

    It breaks because a dependency moved

    The browser updates, or the API changes a field. Pin versions, and log the version in the ledger so a bad day is attributable.

  2. 02

    It breaks because content generation returned nothing

    The script should fail loudly on empty input rather than publish an empty post. A guard clause here saves an embarrassing morning.

  3. 03

    It breaks because of a rate limit

    Handle 429 by deferring to the next run, not by retrying in a tight loop. The ledger is what makes deferral safe.

  4. 04

    It never breaks, and that is the problem

    An unattended pipeline that has run for a month without a single failure usually has a silent one in it. Log a heartbeat and read it.

An unattended pipeline is a runbook that executes itself, and it deserves the same discipline as one somebody else has to follow, the difference being that the only reader is whoever checks the log three weeks later, and they will have no context at all.

The whole system is under a few hundred lines. The value is not in the rendering or the uploading, both are commodity. It is in the ledger and the idempotence, which is the same lesson as keeping an internal tool honest: the unglamorous bookkeeping is what makes automation safe to leave alone.

On this page

Backups: the checks that matter are the ones nobody runs

A restoration drill is the only backup that has ever saved anyone. How to run one in an afternoon, and the three failures it will find.

4 min read

Supporting the Nepali (BS) Calendar in Business Software

Bikram Sambat is not a display format. How it changes date storage, period boundaries, fiscal years, reports, and the cases that only bite at year end.

3 min read

Closing Out Core System Development and Moving into AMC

What to lock down before annual maintenance begins: open defects, documentation, SLAs, the change-request backlog, and a handover that holds.

4 min read