stagit

static page generator for git
git clone https://git.michaelneuper.com/stagit.git
README | Files | Log | Refs | LICENSE

stagit

My fork of stagit, plus the scripts that use it to publish https://git.michaelneuper.com, a static, read-only mirror of my public GitHub repos. The upstream README is in README.

Changes from upstream

The fork is based on stagit 1.3, and upstream releases are merged in rather than rebased onto. To see only the code changes: git diff 1.3 -- '*.c' Makefile. Upstream is only reachable over the git protocol, at git://git.codemadness.org/stagit.

Building the site

Needs libgit2, md4c, pandoc, chroma and the GitHub CLI (brew install libgit2 md4c pandoc chroma gh). Without chroma, file pages aren't syntax highlighted.

./build.sh
python3 -m http.server -d public

build.sh builds stagit with make, lists every public, non-fork, non-empty repo of the account gh is logged in to, fetches it into work/repos, and writes the site to public. Repos named in exclude are skipped. Environment variables:

stagit writes into the current directory, so to render a single repo without a full build:

make
mkdir -p /tmp/out && cd /tmp/out
path/to/stagit/stagit path/to/stagit/work/repos/<repo>.git

Deploying

.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. 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, 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:

    gh secret set CLOUDFLARE_API_TOKEN
    gh secret set CLOUDFLARE_ACCOUNT_ID
    
  3. Push to main, or run the workflow from the Actions tab.

  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.