Skip to content

Sites

A repository can deploy static sites as well as publish packages: a plugin marketplace's signed index, a documentation site, anything that is a directory of files. rab.yml declares each site once, in terms that do not name a host, and lists the hosts it goes to. rab renders what each host needs, deploys, and then fetches files back to check that the host serves what was built.

sites:
  - name: marketplace
    root: _site                    # the built directory, from the repository root
    build: python3 scripts/build_site.py --out _site   # optional
    cache:                         # how long clients and CDNs may keep a path
      - { path: /index.json, max_age: 60 }
      - { path: /index.json.minisig, max_age: 60 }
      - { path: /keys/*, max_age: 300 }
      - { path: /packages/*.json, max_age: 31536000, immutable: true }
    headers:                       # extra response headers
      - { path: /*, set: { X-Content-Type-Options: nosniff } }
    verify: [index.json, index.json.minisig]   # fetched back after deploying
    targets:
      - kind: cloudflare
        project: rs-rich-marketplace           # the Worker's name
        domain: marketplace.buchochelliq-labs.com
      - kind: github-pages

sites: is optional, and a rab.yml may have sites: and no packages:. Such a repository has nothing to release: check validates its sites, and tag and the release gate refuse (rab.yml lists no packages, only sites).

Sites are deployed by their own workflow, not by a release run: usually on every push to main (see The workflow).

The descriptor

Field Required Meaning
name yes The site's name: lowercase letters, digits, - and _. Unique in the file.
root yes The built directory, as a path from the repository root (_site, site). Not ., and not outside the repository.
build no A bash command, run from the repository root, that writes the site into root. SITE is the site's name and OUT the absolute path of root. Without it, something else builds the site (a CI job) and passes the directory to deploy (--dir, or the action's dir).
cache no A list of {path, max_age, immutable}: see Cache and headers.
headers no A list of {path, set: {Header: value}}.
verify no Files in the built directory (paths relative to it, e.g. index.json) to fetch back after a deploy. See Verification.
targets yes The hosts, each a mapping with a kind and that kind's fields.

Every target takes an optional name (default: its kind), which is how commands and the action pick it. Two targets of one kind (a staging and a production Worker, say) need names of their own:

    targets:
      - { kind: cloudflare, name: staging, project: docs-staging }
      - { kind: cloudflare, name: production, project: docs, domain: docs.example.com }

Every target also takes an optional verify_timeout: how many seconds verification waits for the host to serve a new deploy, 0 to 1800 (0 fetches once and does not wait). Without it, the host's default applies: 900 for GitHub Pages, 60 for Cloudflare.

      - { kind: github-pages, verify_timeout: 600 }   # a large site Pages is slow to switch to

Cache and headers

A path is a pattern from the site's root: it starts with /, may hold one *, which matches any characters (/ included), and nothing else special (no :placeholder, query or fragment). /keys/* matches /keys/a.pub; /packages/*.json matches /packages/rs-rich-0.2.0.json.

  • cache: max_age is whole seconds, 0 to 31536000 (a year). immutable: true says the file at that path never changes (a content-addressed or versioned name). Each entry becomes Cache-Control: public, max-age=N (, immutable); max_age: 0 becomes public, max-age=0, must-revalidate.
  • headers: response headers to add. Header names are checked, values are one line of text. Cache-Control belongs in cache.

Hosts add up the headers of every rule that matches a path; Cloudflare joins two values of one header with a comma. So check refuses two rules that can match the same path and set the same header (/* and /packages/*.json both in cache, for example). Rules for different headers may overlap: above, /* adds X-Content-Type-Options to every file, including those cache covers.

Only hosts that serve headers apply these: GitHub Pages ignores both.

What check refuses

  • a site without name, root or targets, a name listed twice, or a field the descriptor does not have;
  • an unknown target kind, a target missing a field its kind needs or carrying one it does not take, two targets with one name, and each kind's own value checks (a Worker name, a host name, an https:// URL);
  • a verify_timeout that is not whole seconds from 0 to 1800;
  • a path pattern that is not one, or has two *; a max_age that is not whole seconds in range (YAML's true is not a number); an immutable that is not true or false; two rules that set one header on overlapping paths;
  • a verify entry that is not a file path inside the built directory;
  • a credential. Any key under sites: that names one (token, secret, password, api_key, account_id, authorization, cookie, ...), header names included, is refused. Credentials come from the environment only.

Targets

Cloudflare

      - kind: cloudflare
        project: rs-rich-marketplace           # required: the Worker's name
        domain: marketplace.buchochelliq-labs.com   # optional

The site is deployed as a Worker with static assets, Cloudflare's current recommendation for static sites: an assets-only Worker (no script) named project. rab writes _headers into the built directory from cache and headers, writes a wrangler config to a temporary directory, and runs

wrangler deploy --config <temporary>/wrangler.json

The deploy-site action installs wrangler from deploy-site/package-lock.json, which locks wrangler and every package it pulls in, each with its integrity hash, so a deploy runs exactly the reviewed code. It runs npm ci --ignore-scripts into a temporary directory (never into .github/rab/, which vendored checks) and passes that wrangler to site deploy in RAB_WRANGLER. Run by hand without RAB_WRANGLER, site deploy uses npx --yes wrangler@<version>, the same exact version (WRANGLER_VERSION in release.py, which a test keeps equal to the lock) but with its dependencies resolved at run time. A new rab moves both; Dependabot proposes lock updates. The config is:

{
  "name": "rs-rich-marketplace",
  "compatibility_date": "<pinned with wrangler>",
  "assets": {"directory": "<the built directory>", "html_handling": "auto-trailing-slash",
             "not_found_handling": "404-page"},
  "workers_dev": false,
  "preview_urls": false,
  "routes": [{"pattern": "marketplace.buchochelliq-labs.com", "custom_domain": true}]
}
  • With domain, the Worker is served on it as a Custom Domain (Cloudflare creates the DNS record and certificate; the zone must be on the same account) and its workers.dev URL is off.
  • Without domain, it is served on its workers.dev URL, which wrangler prints and rab verifies against.
  • A path with no file gets the nearest 404.html with status 404, as on GitHub Pages.

wrangler reads _headers from the directory and never uploads it as a page. site plan shows the _headers and the config without deploying.

The credentials are read from the environment, never from rab.yml, and never printed:

Variable Value
CLOUDFLARE_API_TOKEN An API token (below).
CLOUDFLARE_ACCOUNT_ID The account's ID (the dashboard's account home shows it).

A deploy without either stops before running wrangler, naming the missing one.

Setting up Cloudflare

  1. The account and zone. For a custom domain, the domain's zone (buchochelliq-labs.com) must be on the Cloudflare account that will own the Worker. The Worker needs no other set-up: the first deploy creates it.
  2. An API token. In the dashboard, My Profile → API Tokens → Create Token → Create Custom Token:

    • Account → Workers Scripts → Edit, for the account (this deploys the Worker and its assets);
    • with a domain: Zone → Workers Routes → Edit, for that zone only (adding a Custom Domain needs it; see Cloudflare's permissions). Cloudflare's docs list this as the permission for routes and Custom Domains; if a first deploy is refused creating the domain's DNS record, add Zone → DNS → Edit for the same zone.

    Limit it to the one account and zone, and give it an expiry you will renew. Do not use the account's Global API Key. 3. GitHub. Create an environment named cloudflare (Settings → Environments), limit it to the main branch, and add the environment secrets CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID (the ID is not secret, but keeping both in one place is simpler). Add required reviewers if a person should approve each deploy.

GitHub Pages

      - kind: github-pages
        url: https://docs.example.com/    # optional: where Pages serves the site

The deploy-site action uploads the built directory with actions/upload-pages-artifact and deploys it with actions/deploy-pages, both pinned by commit. The repository's Pages source must be GitHub Actions (Settings → Pages → Build and deployment), and the deploy job needs pages: write and id-token: write, in the github-pages environment, and should have actions: read (below).

deploy-pages looks the uploaded artifact up by name right after the upload, and GitHub's listing can lag an upload by seconds: rs-rich-cli's docs deploy once failed one second after uploading, with No artifacts named "github-pages" were found for this workflow run. So the action first waits (up to two minutes) until the run's artifacts list github-pages, which needs actions: read; without it, it warns and deploys without waiting. It then runs deploy-pages, and if that fails quickly, as the lookup does, runs it again: three attempts, 20 then 30 seconds apart. An attempt that fails after running for more than two minutes got past the lookup (a deploy that timed out, say) and is not retried, so a real failure does not cost three deploy timeouts.

Pages ignores cache and headers. It sets its own Cache-Control (ten minutes) and reads no _headers; site plan lists both under ignored. Deploy to Cloudflare when the cache policy matters, as for the marketplace's immutable package files. render writes nothing for Pages, and removes a _headers rab wrote for another target, which Pages would serve as a page.

Verification uses the address deploy-pages reports. site verify without --url uses url, else https://<owner>.github.io/<repository>/ from GITHUB_REPOSITORY. A custom domain is set in the repository's Pages settings, not here.

Verification

After a deploy, each verify file is fetched from the site's address (https://<domain>/<file>, the workers.dev URL, or the Pages URL) with a cache-busting query (?rab-verify=...) and Cache-Control: no-cache, and its SHA-256 compared with the built file's. When a file still differs, the failure shows what was served: its first bytes, the address the request ended at after redirects, and the headers that say who served it and from which cache (server, via, age, x-cache, cf-cache-status, …). A host takes a while to serve a new deploy everywhere, so verification tries again until the target's window has passed, saying before each wait which files are not yet as built:

Host Window (verify_timeout) Waits between tries
Cloudflare 60 s 6 s (11 tries)
GitHub Pages 900 s 5, 10, 20, then 30 s (33 tries)

GitHub Pages gets the longer window because it can keep serving the old site for minutes after deploy-pages reports success: rs-rich-cli's docs deploy once failed verification after a minute. A target's verify_timeout replaces the window (the waits keep the host's pattern, the last one cut short to end on time); site verify --timeout replaces it for one run. A file that still differs at the end fails the deploy, listing each file's problem:

error: site marketplace: https://marketplace.buchochelliq-labs.com/ does not serve what was built, after 11 tries over 60 s:
  index.json: served sha256 44ea8e..., built ca8512...
  index.json.minisig: HTTP 404
(a host that is slow to switch to a new deploy needs a longer `verify_timeout` on the target, at most 1800 s)

Choose files that change when the site does and that a cache must not keep stale: for the marketplace, the signed index and its signature. A verify file the build lacks fails before anything is deployed.

Commands

release.py site plan [--site S] [--target T]
release.py site build --site S
release.py site render --site S --target T --dir DIR
release.py site deploy --site S --target T [--dir DIR] [--url URL] [--no-verify]
release.py site verify --site S --target T [--dir DIR] [--url URL] [--timeout SECONDS]
release.py site wait-artifact [--name github-pages] [--timeout 120]
  • plan prints JSON: per site and target, the target's kind and address, the files rendered for it (_headers), what it ignores, and for Cloudflare the wrangler config and command. Read-only.
  • build runs the site's build and prints the directory (and writes dir= to GITHUB_OUTPUT in Actions).
  • render writes the host's files into DIR and prints what it wrote; for Cloudflare it also writes the wrangler config to a temporary directory and prints its path. A _headers that rab did not write is refused, not overwritten: declare its rules in rab.yml. A build missing a verify file is refused: every host renders before it uploads, so it fails before anything is deployed.
  • deploy builds (when the site has a build and no --dir is given), renders, deploys and verifies. --url verifies against another address; --no-verify skips verification. GitHub Pages deploys only from the action (it needs the workflow's OIDC token).
  • verify fetches the verify files from --url (default: the target's domain or url) and compares them with --dir (default: the site's root), waiting for the host as Verification says; --timeout sets the window for this run.
  • wait-artifact, in a workflow only, waits until the run's artifacts (GITHUB_REPOSITORY, GITHUB_RUN_ID, with GITHUB_TOKEN) list --name, and writes listed=true|false to GITHUB_OUTPUT. It never fails the job: a token that cannot list artifacts, or a listing still without it after --timeout, is a warning. The action runs it before deploy-pages.

site kind --site S --target T prints a target's kind; the action uses it.

The deploy-site action

install copies it to .github/rab/deploy-site/, with the other actions, and vendored checks it.

Input Default Meaning
site required The site's name.
target required The target's name (its kind when it has none).
dir "" An already built directory. Empty: run the site's build and deploy its root.
verify "true" "false" deploys without verifying.
cloudflare-api-token "" Cloudflare: pass secrets.CLOUDFLARE_API_TOKEN.
cloudflare-account-id "" Cloudflare: pass secrets.CLOUDFLARE_ACCOUNT_ID.

Its output url is the address the site is served at. The Cloudflare credentials reach only the deploy step, as environment variables.

For Cloudflare it sets up Node 24 (no cache), installs the locked wrangler from package-lock.json (npm ci --ignore-scripts, into $RUNNER_TEMP), and runs site deploy with it. For GitHub Pages it runs site render, then upload-pages-artifact, waits for the artifact to be listed (site wait-artifact), runs deploy-pages (up to three times, see GitHub Pages) and site verify against the deployed URL.

The workflow

templates/sites.yml is a starting point; install does not write it. Copy it to .github/workflows/sites.yml, keep the deploy jobs for the targets you use, and set the site's name:

permissions:
  contents: read

jobs:
  build:            # builds once, so every target deploys the same bytes
    ...
  deploy-cloudflare:
    needs: build
    permissions:
      contents: read
    environment: cloudflare
    steps:
      - ...checkout, download the built site...
      - uses: ./.github/rab/deploy-site
        with:
          site: marketplace
          target: cloudflare
          dir: _built
          cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

  deploy-pages:
    needs: build
    permissions:
      contents: read
      actions: read     # to wait until the run lists the Pages artifact
      pages: write
      id-token: write
    environment: github-pages
    steps:
      - ...
      - uses: ./.github/rab/deploy-site
        with:
          site: marketplace
          target: github-pages
          dir: _built

Each deploy job runs in a protected environment named for its host, with only the permissions it needs: Cloudflare's job only reads the repository and gets the environment's secrets; Pages' job gets the Pages and OIDC permissions, read access to the run's artifacts, and no secrets. The build job holds no credentials.

The template already splits building from deploying. It does not go further and upload the Pages artifact in the build job, leaving only deploy-pages to the deploy job, though that is the usual Pages split and would remove the upload-then-deploy race. The Pages render (which removes a _headers rendered for Cloudflare) would have to run in the build job, the build job would upload two artifacts for two hosts, and deploy-site would need a deploy-only mode. Waiting for the artifact and retrying the deploy fixes the race without any of that.

A repository whose CI already builds the site (rs-rich-cli's versioned docs, built into ./site) can drop the build field and the template's build job and pass its own artifact as dir.

Adding a host

Each kind of host is one class in release.py, registered in SITE_HOSTS; the descriptor does not change. To add Fastly, S3 or Bunny:

  1. Subclass SiteHost and set kind, the target fields it requireds and allows (optional), and applies_headers (whether it serves cache and headers).
  2. target_errors(where, target): check its own field values.
  3. files(site, target): the files it reads from the built directory ({name: text}), rendered from header_rules(site); add new names to RENDERED_FILES so other hosts remove rab's copies. A host configured by API instead (S3 object metadata, say) returns {} and applies the rules in deploy.
  4. plan(site, target, directory): its config, for site plan.
  5. deploy(site, target, directory): deploy with credentials read from the environment (refuse, naming them, when missing; never print them), and return the URL to verify against. Run its CLI through an override variable, as RAB_WRANGLER does for wrangler, so tests can fake it.
  6. url(site, target): its address when known without deploying.
  7. Add it to SITE_HOSTS, give the deploy-site action the steps and inputs it needs (pinned actions only), document it here, and test it with a fake CLI and a fake fetch, as tests/test_sites.py does for Cloudflare.