Deploy Statamic Static Site Using GitHub Actions
I recently set up a new Statamic site using the Cool Writings starter kit (statamic/starter-kit-cool-writings). The official documentation walks you through local development and static site generation (SSG), but it doesn’t cover how to deploy to GitHub Pages. Here’s how to do that using GitHub Actions.
Update ssg.php to Customize Output Path
By default, Statamic SSG outputs to build, but we want to generate files in storage/static instead. Update your config/statamic/ssg.php:
'output_path' => base_path('storage/static'),
You want build files to be included too, so update config to do that:
'copy' => [
public_path('assets') => 'assets',
public_path('build') => 'build',
public_path('css') => 'css',
public_path('js') => 'js',
],
Generate Static Files
To build the static site, run:
php please ssg:generate
This will output all static content to storage/static. Make sure the folder is committed to version control (git add storage/static
).
Enable GitHub Pages & Generate Workflow
- Go to your GitHub repo settings → Pages.
- Choose GitHub Actions as your deployment source.
- GitHub will generate a starter workflow.
Update the generated workflow file to deploy files from the storage/static folder. Here’s a minimal example:
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload storage/static
path: 'storage/static'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
And that’s it! You’ll now have your Statamic static site automatically deployed to GitHub Pages every time you push to main. Just make sure to build files locally and commit generated content.