commit 455166a3ac10114e734f87eef3a7dece3e7f4cbb
parent 2bd8f70f8c431276c718fbc89342329cf4492ba3
Author: Michael Neuper <michael@michaelneuper.com>
Date: Thu, 29 Oct 2026 09:36:37 +0200
start runs from a cron trigger
Diffstat:
5 files changed, 67 insertions(+), 15 deletions(-)
diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml
@@ -1,10 +1,10 @@
name: mirror
+# The schedule is in cron/wrangler.jsonc: GitHub disables scheduled
+# workflows in public repos after 60 days without commits.
on:
push:
branches: [main]
- schedule:
- - cron: "23 */6 * * *"
workflow_dispatch:
permissions:
@@ -55,3 +55,9 @@ jobs:
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
+
+ - name: Deploy the schedule
+ run: npx --yes wrangler@4.151.3 deploy -c cron/wrangler.jsonc
+ env:
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
+ CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
diff --git a/.gitignore b/.gitignore
@@ -3,4 +3,4 @@
/stagit-index
/work/
/public/
-/.wrangler/
+.wrangler/
diff --git a/README.md b/README.md
@@ -63,19 +63,24 @@ without a full build:
`.github/workflows/mirror.yml` rebuilds the site on every push to `main`,
every 6 hours, and on demand, then deploys `public` to Cloudflare as a
-Worker with static assets, configured in `wrangler.jsonc`. Every run
-regenerates the site from scratch: stagit never rewrites an existing commit
-page, so incremental output would go stale after a force push or a
-description change. wrangler only uploads files whose contents changed, so
-redeploys stay small.
+Worker with static assets, configured in `wrangler.jsonc`. The 6-hourly
+runs are started by a second Worker with a cron trigger (`cron/`), since
+GitHub disables scheduled workflows in public repos after 60 days without
+commits.
+
+Every run regenerates the site from scratch: stagit never rewrites an
+existing commit page, so incremental output would go stale after a force
+push or a description change. wrangler only uploads files whose contents
+changed, so redeploys stay small.
The workflow mirrors the repos of whoever owns the GitHub repo it runs in.
To deploy your own copy:
-1. Put your hostname in `wrangler.jsonc` and `SITE_URL` in the workflow,
- and list any repos to skip in `exclude`. The domain must be a Cloudflare
- zone without DNS records for that hostname: the deploy creates its own
- record and HTTPS certificate, but fails if another record is in the way.
+1. Put your hostname in `wrangler.jsonc`, your GitHub repo in
+ `cron/wrangler.jsonc` and `SITE_URL` in the workflow, and list any repos
+ to skip in `exclude`. The domain must be a Cloudflare zone without DNS
+ records for that hostname: the deploy creates its own record and HTTPS
+ certificate, but fails if another record is in the way.
2. Create a Cloudflare API token from the "Edit Cloudflare Workers"
template, and add it and your account ID as repository secrets:
@@ -83,6 +88,7 @@ To deploy your own copy:
gh secret set CLOUDFLARE_ACCOUNT_ID
3. Push to `main`, or run the workflow from the Actions tab.
-
-GitHub disables scheduled workflows in public repos after 60 days without
-activity in the repo.
+4. Create a fine-grained GitHub token for this repo only, with "Actions"
+ set to read and write. In the Cloudflare dashboard, add it to the
+ `stagit-cron` Worker under Settings → Variables and Secrets, as a
+ secret named `GITHUB_TOKEN`.
diff --git a/cron/index.js b/cron/index.js
@@ -0,0 +1,20 @@
+// Starts the mirror workflow on GitHub, on the schedule in wrangler.jsonc.
+export default {
+ async scheduled(controller, env) {
+ const res = await fetch(
+ `https://api.github.com/repos/${env.GITHUB_REPO}/actions/workflows/mirror.yml/dispatches`,
+ {
+ method: "POST",
+ headers: {
+ Accept: "application/vnd.github+json",
+ Authorization: `Bearer ${env.GITHUB_TOKEN}`,
+ "User-Agent": "stagit-cron",
+ "X-GitHub-Api-Version": "2022-11-28",
+ },
+ body: JSON.stringify({ ref: "main" }),
+ },
+ );
+ if (!res.ok)
+ throw new Error(`workflow dispatch: ${res.status} ${await res.text()}`);
+ },
+};
diff --git a/cron/wrangler.jsonc b/cron/wrangler.jsonc
@@ -0,0 +1,20 @@
+// Starts .github/workflows/mirror.yml on a schedule. This is its own Worker
+// because a script in the site's Worker would get every request that matches
+// no file, instead of those getting the 404 page.
+{
+ "name": "stagit-cron",
+ "main": "index.js",
+ "compatibility_date": "2026-10-01",
+ "workers_dev": false,
+ "preview_urls": false,
+ "triggers": {
+ "crons": ["23 */6 * * *"]
+ },
+ // GITHUB_TOKEN is a secret, set in the dashboard.
+ "vars": {
+ "GITHUB_REPO": "michaelneuper/stagit"
+ },
+ "observability": {
+ "enabled": true
+ }
+}