Building and deploying a custom site using GitHub Actions and GitHub Pages#
I figured out a minimal pattern for building a completely custom website using GitHub Actions and deploying the result to GitHub Pages.
First you need to enable GitHub Pages for the repository. Navigate to Settings -> Pages (or visit $repo/settings/pages
) and set the build source to “GitHub Actions”.
Here’s my minimal YAML recipe - save this in a .github/workflows/publish.yml
file:
1name: Publish site2
3on:4 push:5 workflow_dispatch:6
7permissions:8 contents: read9 pages: write10 id-token: write11
12jobs:13 build:14 runs-on: ubuntu-latest15 steps:16 - uses: actions/checkout@v417 - name: Build the site18 run: |19 mkdir _site20 echo '<h1>Hello, world!</h1>' > _site/index.html21 - name: Upload artifact22 uses: actions/upload-pages-artifact@v323 deploy:24 environment:25 name: github-pages26 url: ${{ steps.deployment.outputs.page_url }}27 runs-on: ubuntu-latest28 needs: build29 steps:30 - name: Deploy to GitHub Pages31 id: deployment32 uses: actions/deploy-pages@v4
Anything that goes in that _site/
directory will be published to the GitHub Pages site.
The permissions
are required:
contents: read
allows theactions/checkout
action to check out the repopages: write
enables writes to pagesid-token: write
one is needed by the actions/deploy-pages action for some reason
The default URL for the site will be https://$GITHUB_USERNAME.github.io/$REPO_NAME/
. You can set this to custom domain if you want.
github.com/simonw/minimal-github-pages-from-actions is an example repository that uses this exact YAML configuration. It publishes a site to https://simonw.github.io/minimal-github-pages-from-actions/.
Next steps#
You can combine this trick with scheduled workflows and Git scraping to create all sorts of interesting and useful things.
I’m using it to publish an Atom feed of recent California Brown Pelicans sightings on iNaturalist in my simonw/recent-california-brown-pelicans repository.
I also use it to publish my tools.simonwillison.net site with a custom colophon page - see this post for details.