DEV Community

Roberto Luna
Roberto Luna

Posted on

Automating Multi‑Channel Content Publishing with a JSON‑Driven Generator in a CI Pipeline

Automating Multi‑Channel Content Publishing with a JSON‑Driven Generator in a CI Pipeline

TL;DR: I added a tiny Node script that reads a single metadata.json file and spits out platform‑specific markdown and JSON payloads. The CI now finishes in seconds instead of hanging on a “building…” loop, and I have a reliable flag‑based record of what was published.


The Problem

Our content‑automation repo lives in a monorepo that also hosts a hotel‑IT‑ops dashboard. Every morning the CI pipeline would spin forever on the content‑automation job, printing:

[info] building...
[info] building...
...
Enter fullscreen mode Exit fullscreen mode

The root cause was simple: the pipeline expected a set of generated files (medium_en.md, substack_es.md, bluesky_en.json, etc.) that simply didn’t exist yet. Because the job tried to cat those files for the “publish” step, it kept waiting for the I/O to complete, which never happened. In addition, we had no single source of truth to know which platforms had already been generated, so the same content kept being re‑generated on every run, inflating the artifact size and confusing downstream steps.


What I Tried First

My first attempt was a manual copy‑paste workflow:

  1. Write the article in content/2026/11/19/content-automation/medium_en.md.
  2. Duplicate the file, translate it, rename to substack_en.md.
  3. Manually create a JSON payload for Bluesky.

I wrapped those steps in a Bash script:

#!/usr/bin/env bash
cp medium_en.md substack_en.md
# ... translate manually
echo '{"type":"progress","text":"..."}' > bluesky_en.json
Enter fullscreen mode Exit fullscreen mode

The script ran, but it was fragile:

  • No guarantee the files existed before the copy (CI would still fail).
  • No way to know if a platform had already been generated – the script kept overwriting files.
  • Translating the markdown manually broke the “single source of truth” principle we wanted.

I also tried a quick Node one‑liner that read the markdown and wrote copies, but I kept hitting a race condition where the CI step that published to Medium started before the generator finished, causing a “file not found” error.


The Implementation

1. Add a Structured Metadata File

I introduced content/2026/11/19/content-automation/metadata.json. The diff shows the key change:

-  "medium_generated": false,
-  "substack_generated": false,
+  "medium_generated": true,
+  "substack_generated": true,
Enter fullscreen mode Exit fullscreen mode

Now the CI can check these booleans to skip regeneration if the content already exists.

2. Create a Tiny Generator (scripts/generateContent.js)

// scripts/generateContent.js
const fs = require('fs');
const path = require('path');

const baseDir = path.resolve(__dirname, '..', 'content', '2026', '11', '19', 'content-automation');
const metaPath = path.join(baseDir, 'metadata.json');
const meta = JSON.parse(fs.readFileSync(metaPath, 'utf8'));

function writeIfNeeded(file, content, flag) {
  if (!meta[flag]) {
    fs.writeFileSync(file, content);
    console.log(`✔️  Generated ${path.basename(file)}`);
    meta[flag] = true;
  } else {
    console.log(`ℹ️  Skipping ${path.basename(file)} – already generated`);
  }
}

// 1️⃣ Medium (English)
const mediumEn = `I was watching the CI pipeline spin forever on a rainy Thursday, and the only thing that kept me from closing the terminal was the feeling that the whole content‑automation system was stuck.`;
writeIfNeeded(path.join(baseDir, 'medium_en.md'), mediumEn, 'medium_generated');

// 2️⃣ Substack (English)
const substackEn = `**Subject:** Week 1 Recap – PII‑free exports, Sentry live, and a sturdier AI Gateway 🚀

### What I built this week

I spent the last five days tightening the **content‑automation** pipeline...`;
writeIfNeeded(path.join(baseDir, 'substack_en.md'), substackEn, 'substack_generated');

// 3️⃣ Bluesky (English) – JSON payload
const blueskyEn = [
  {
    type: "progress",
    text: "Finally published the first auto‑generated article on Bluesky! 🚀"
  }
];
writeIfNeeded(
  path.join(baseDir, 'bluesky_en.json'),
  JSON.stringify(blueskyEn, null, 2),
  'bluesky_generated' // add this flag to metadata if needed
);

// Persist updated flags
fs.writeFileSync(metaPath, JSON.stringify(meta, null, 2));
Enter fullscreen mode Exit fullscreen mode

The script:

  • Reads metadata.json.
  • Generates each platform file only if its flag is false.
  • Updates the flags after a successful write, ensuring idempotency.

I added the new flag bluesky_generated to metadata.json (initially false). The generator is now part of the CI:

# .github/workflows/content.yml
jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Node
        uses: actions/setup-node@v3
        with:
          node-version: '20'
      - run: npm ci
      - run: node scripts/generateContent.js
Enter fullscreen mode Exit fullscreen mode

3. Populate the Platform Files (Diff Highlights)

content/2026/11/19/content-automation/medium_en.md (239 lines) – first 3 lines:

I was watching the CI pipeline spin forever on a rainy Thursday, and the only thing that kept me from closing the terminal was the feeling that the whole content‑automation system w...
Enter fullscreen mode Exit fullscreen mode

content/2026/11/19/content-automation/substack_en.md (66 lines) – header snippet:

**Subject:** Week 1 Recap – PII‑free exports, Sentry live, and a sturdier AI Gateway 🚀  

---  

### What I built this week  

I spent the last five days tightening the **content‑automation** pipeline...
Enter fullscreen mode Exit fullscreen mode

content/2026/11/19/content-automation/bluesky_en.json (17 lines) – final JSON:


json
[
  {
    "type": "progress",
    "text": "

---

*Part of my [Build in Public](https://dev.to/zaerohell) series — sharing the real process of building SaaS projects from Playa del Carmen, México.*

*Repo: `zaerohell/content-automation` · 2026-11-20*

\#playadev #buildinpublic
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The root cause you found is the part I liked most — the CI was not slow, it was waiting forever for medium_en.md, substack_es.md and bluesky_en.json files that did not exist yet. Using metadata.json flags like medium_generated and bluesky_generated to make the generator idempotent is a clean fix, and finishing in seconds instead of hanging on "building..." says a lot. One question: when a post is edited after it has already been published, do the flags flip back to false so the platforms get regenerated, or do you handle updates separately?