The scheduler that can't publish anything
A static blog with no server, and a post merged on Sunday but dated Tuesday: how does it go live on Tuesday morning while I'm asleep?
On this page
I wanted to finish a post on Sunday, date it Tuesday, merge it and forget about it. On Tuesday morning it should just be live. This blog has no server, no admin panel and no database of posts, so something has to make that happen. Before I show you how, here’s the problem, so you can try solving it yourself.
The setup
This blog is an Astro site hosted on Cloudflare Workers. Every post is an MDX file in a GitHub
repo, with a pubDate in its front matter. The site builds to static HTML.
Cloudflare Workers Builds is connected to the repo. Every push to main triggers a build, and
the build is deployed. A merged pull request, a direct push or a typo fix all take the same path.
The setup
So the problem looks like this:
- Nothing runs between pushes. The live site is whatever the last build produced. If no one pushes, nothing changes.
- Cloudflare already deploys
mainon every push. That works, and I don’t want to replace it. - I don’t want to be at the keyboard. A post dated Tuesday should be live by 06:00 on Tuesday, while I’m asleep.
- A scheduled post must never appear early. Not as a page, and not in RSS, the sitemap, search or the email feed.
- “Tuesday” means Tuesday in Melbourne, daylight saving included.
The answers most people reach for
1. A GitHub Actions cron that builds and deploys
This was my first sketch, and it’s the obvious one. A scheduled workflow runs every night, works out which posts are due, builds the site and deploys it to Cloudflare with an API token. GitHub is at the centre and controls everything.
It works, but it costs more than it looks:
- There are now two deployers. Cloudflare still deploys on every push, so two systems publish the same site from two different builds. When they disagree, whichever ran last wins.
- A Cloudflare API token has to live in GitHub. That’s one more secret to rotate, scope and leak.
- The cron decides what’s public. If its “is this due?” logic has a bug, a post goes live early or never.
Answer 1: two deployers
2. Rebuild every day from the Cloudflare side
A deploy hook or a scheduled Worker that calls the build API every night. This is closer: only one system deploys. But a secret URL or token still has to live somewhere, the site rebuilds every night whether or not anything is due, and it’s still unclear which part decides what’s visible.
Answer 2: a nightly trigger
3. Check the date when the page is viewed
You could hide future posts with JavaScript, but the post is already in the HTML, the RSS feed and the sitemap. That’s a leak with extra steps. Or you could render pages on request and check the date there, which turns a static site into a dynamic one for a single feature.
Answer 3: hide it in the browser
The turn
Look at constraint 2 again. Cloudflare already builds and deploys every push. So the real question isn’t “how do I deploy on a schedule?” It’s this:
What’s the least GitHub has to do?
Not build and not deploy. It only has to push a commit, and an empty one will do. Cloudflare sees a push and builds as it always does. So the scheduler doesn’t publish anything. It just knocks.
That only works if the build itself knows which posts are due, so that decision moves into the build. It’s the idea the rest of this post is built on:
Who does what
Rule 1: the build decides what’s visible
Every build works out today’s date in Melbourne, once, at the start. A post is included only if
it isn’t a draft and its pubDate is on or before that day.
// src/lib/schedule.ts
export function isDue(pubDate: Date, today: string): boolean {
return publishDay(pubDate) <= today; // both 'YYYY-MM-DD' in Melbourne
}
// src/lib/posts.ts: every page, feed, sitemap and search index gets its posts here
export const today = melbourneToday();
export async function getPublishedPosts() {
return getCollection('posts', ({ data }) => !data.draft && isDue(data.pubDate, today));
}
today is read once per build. A build that runs past midnight can’t hide a post’s page and
still list it on the home page.
Every surface goes through getPublishedPosts(), so one filter covers everything. As a backstop,
a leak guard runs after every build. It scans the output for the URL of any hidden post and fails
the build if it finds one. A page added next year that forgets to use the filter still can’t
publish a post early.
The build also refuses impossible dates. YAML turns pubDate: 2026-11-31 into 1 December
without complaint, and the filter would faithfully publish the post on a day nobody chose. So
the build reads the raw date from the file and fails if the day doesn’t exist.
Because today is just a value, I can also ask what any day will look like.
PUBLISH_TODAY=2026-11-02 npm run build builds exactly what that day’s build will publish, leak
guard included.
The consequence matters more than the code:
No build can publish a post early. Running the build more often only wastes a few minutes of build time. It can never reveal anything. Everything that follows depends on this.
Rule 2: the job only knocks
Because of Rule 1, the job can be almost nothing. Every morning a scheduled GitHub Actions
workflow pushes an empty commit, chore(daily): rebuild for <today>. Cloudflare builds that push
like any other, the build works out today’s date, and whatever fell due appears.
It doesn’t have to be clever. If it runs twice, the second build publishes the same posts. If it runs late, the build still uses the right day. Nothing it does can reveal a post early, because it never touches the posts.
How a post goes live
Here’s the whole job:
# .github/workflows/publish.yml
name: Publish
on:
schedule:
- cron: '5 14 * * *' # three slots, all after midnight in Melbourne,
- cron: '5 16 * * *' # because GitHub starts scheduled runs late
- cron: '5 18 * * *'
workflow_dispatch: # a manual run always pushes
permissions:
contents: write
concurrency:
group: publish
cancel-in-progress: false
jobs:
daily-commit:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
- name: Commit and push to main
env:
SCHEDULED: ${{ github.event_name == 'schedule' }}
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
day=$(TZ=Australia/Melbourne date +%F)
message="chore(daily): rebuild for $day"
for attempt in 1 2 3; do
git fetch origin main || { sleep 10; continue; }
git reset --hard origin/main
if [ "$SCHEDULED" = true ]; then
if git log --since='3 days ago' --format=%s origin/main | grep -xF "$message" >/dev/null; then
echo "Already rebuilt for $day; nothing to do."
exit 0
fi
verdict=$(node scripts/rebuild-due.mjs) || verdict=rebuild
if [ "$verdict" = skip ]; then
echo "Every post due by $day is live; nothing to do."
exit 0
fi
fi
git commit --allow-empty -m "$message"
git push origin HEAD:main && exit 0
sleep 10
done
exit 1
At its core it’s the git commit --allow-empty and git push near the bottom. Everything else is
there for a reason, from the top:
- Three
cronlines. GitHub starts scheduled jobs late. The first version had one slot, at 02:30 Melbourne time, and over its first six days it started as late as 07:39, missing 06:00 on four of them. With three slots across the night, one usually lands in time. The first to run pushes. The others find today’s commit message onmainand stop. workflow_dispatchlets me run it by hand. A manual run always pushes.contents: write, and no secrets. The job uses only the built-inGITHUB_TOKEN. A push made with that token deliberately doesn’t start other GitHub Actions workflows, but that doesn’t matter: Cloudflare isn’t a workflow, and it gets the push webhook like any other push.- The
forloop. If someone else pushes in between, the job fetches again and retries, up to three times. rebuild-due.mjs. A push every morning would be 365 builds a year for a blog that publishes a few posts a month. So the script first checks whether any post is dated aftermain’s last commit and by today. Every push is built, so that commit’s day is the last build’s day, and a missed morning catches up the next day. This check decides whether to build, never what is live, so a mistake costs a wasted build or a late post, not an early one. If the script crashes or can’t read a date, the job pushes anyway.
The token is also why the knock comes from GitHub and not from a Worker cron. Once the build decides what’s visible, Answer 2’s nightly trigger would work too. But it would need a deploy hook URL or a Cloudflare token stored somewhere, and to check what’s due it would have to read the repo, which means a GitHub token as well. A workflow already sits next to the repo and gets its token for free.
Trade-offs I accepted
- A failed Cloudflare build isn’t retried. The job assumes the last commit built. Checking the live site would close that gap, but it would bring back the coupling this design avoids.
- Whole days only. A post goes live early in the morning, Melbourne time. There’s no “9:00 on Tuesday”.
- A bot pushes to
main, so on mornings a post goes live, I pull before my next push. - Moving a live post’s date into the future hides it again, but RSS readers that already fetched it keep it.
Why I trust it
That’s the whole scheduler: a date filter in the build, and a job that can only push an empty commit. It can’t publish anything by itself. It can only knock, and the build decides what goes live. Neither part can put a post live early. The worst a mistake in the job can do is waste a build or leave a post late, and when it’s unsure, it picks the wasted build.
So I can merge a post on Sunday and stop thinking about it. On Tuesday morning, it’s there.