An Astro scheduled rebuild is a cron job that triggers a fresh build of your static site at a fixed time, usually by sending a POST request to your host’s deploy hook from a GitHub Actions workflow with a schedule trigger. It is the simplest way to keep build-time data current: posts scheduled for a future date go live, past events drop off, and data fetched at build time refreshes, all without a server.
Key Takeaways
- Static Astro pages only change when you rebuild, so anything date-based needs a rebuild to update.
- Netlify, Vercel and Cloudflare Pages all offer deploy hooks: a secret URL that starts a build when you
POSTto it.- A GitHub Actions
scheduletrigger can call that hook on any cron, in UTC.- Keep the hook URL in a repository secret; anyone with it can trigger builds.
Why a static site needs a schedule
Astro renders static pages once, at build time. Code like this only runs during astro build:
---
// src/pages/events.astro
import { getCollection } from 'astro:content';
const now = new Date();
const upcoming = await getCollection('events', ({ data }) => data.start >= now);
---
now is the moment of the build, not the moment someone visits. If you deploy on Monday, an event that ended on Tuesday is still listed on Friday. The same applies to posts with a future pubDate that you filter out until their date, to “new” badges, and to anything loaded from an API with fetch() in frontmatter. A daily or hourly rebuild fixes all of these at once.
Step 1: create a deploy hook
Every major static host can give you a URL that starts a build:
| Host | Where to find it |
|---|---|
| Netlify | Site configuration, Build & deploy, Build hooks |
| Vercel | Project Settings, Git, Deploy Hooks |
| Cloudflare Pages | Project Settings, Builds, Deploy hooks |
Create one for your production branch and copy the URL. Store it in GitHub as a repository secret named DEPLOY_HOOK_URL (Settings, Secrets and variables, Actions).
Step 2: add a scheduled workflow
# .github/workflows/scheduled-rebuild.yml
name: Scheduled rebuild
on:
schedule:
- cron: '0 6 * * *' # every day at 06:00 UTC
workflow_dispatch: # also allow a manual run from the Actions tab
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- name: Call the deploy hook
run: curl --fail --silent --show-error -X POST "$HOOK"
env:
HOOK: ${{ secrets.DEPLOY_HOOK_URL }}
Commit it to your default branch; GitHub only runs scheduled workflows from there. --fail makes the job fail if the host rejects the request, so you see a red run instead of a silent miss.
The cron uses UTC. 0 6 * * * is 06:00 UTC daily; 0 * * * * is hourly; 30 5 * * 1 is 05:30 every Monday. Pick the slowest schedule that keeps your content correct, because every rebuild uses build minutes.
Option: build in Actions instead
If you already deploy from GitHub Actions rather than the host’s Git integration, put the schedule on your existing deploy workflow instead of calling a hook:
# .github/workflows/deploy.yml (excerpt)
on:
push:
branches: [main]
schedule:
- cron: '0 6 * * *'
The build step then runs on both pushes and the schedule. Our guide to GitHub Actions workflows for Astro has full deploy workflows, and caching node_modules/.astro with the CI build cache tip keeps scheduled builds quick.
Things that trip people up
- Schedules can run late. GitHub queues scheduled runs and they can start several minutes after the cron time during busy periods. Do not rely on minute-level precision.
- Inactive repositories. In public repositories, GitHub disables scheduled workflows after 60 days with no repository activity. A commit, or re-enabling the workflow, restarts them.
- Time zones in your code. The build runs in UTC too. Compare dates in UTC, or set
timeZoneexplicitly when you format them, so “today” means the same thing locally and in CI. - Rebuilds that change nothing. If content rarely changes, trigger builds from your CMS instead. See rebuilding Astro when CMS content changes.
When a schedule is the wrong tool
If data must be fresh within seconds, such as stock levels or prices, a schedule will always lag. Render that one route on demand with an adapter while the rest of the site stays static; hybrid rendering in Astro shows how. For hosting setup, see the static deployment docs. The same workflow works for any static build, including the Astro themes in our catalog.
FAQ
How do I rebuild an Astro site automatically every day?
Create a deploy hook in your host’s settings, save it as a GitHub secret, and add a workflow with on: schedule: - cron: '0 6 * * *' that sends a POST request to the hook with curl.
Can Netlify or Vercel rebuild on a schedule without GitHub Actions?
Both expose deploy hooks rather than a built-in cron for static rebuilds, so you need something to call the hook on a timer. GitHub Actions is the common choice; Netlify scheduled functions or a Cloudflare Workers cron trigger can also call it.
Does a scheduled rebuild publish future-dated posts?
Only if your code filters posts by date at build time, for example data.pubDate <= new Date(). The rebuild then includes each post on the first build after its date.
How often should I rebuild a static Astro site?
As rarely as your content allows. Daily suits events and scheduled posts; hourly suits feeds pulled from APIs. Anything needing faster updates is better served by on-demand rendering.