I'm a huge fan of GitHub Actions. They're so simple but so effective at doing such a broad range of things. In short, you can tell GitHub do something on a computer everytime you push a commit to your repository (or to a branch on a specific repository like the
For today's post, I'll focus on how I used an action to automate deploying my static site built with Next.js to GitHub Pages.
Here's what I had to do:
- Build a Next.js blog following the detailed tutorial and store the code on a GitHub repository
- Create a workflow file in the repository with the following path:
- Specify that workflow file to export the static files whenever I push to
mainand commit the exported files to a separate branch called
gh-pages(you can just follow the workflow file I used)
- Manually add a
.nojekyllfile to the
gh-pagesbranch (this is to resolve this bug)
- Configure my repository Settings so that it sources the GitHub Pages build from the
And that's it, adding new blog posts is as simple as creating a new markdown file and pushing it to the main branch. The GitHub Action will handle all of the rest!
This is much nicer in behavior than my old site, which was built using Jekyll (a Ruby framework) and it's much less work than building a full application with Django to get high quality page loads. I’d add that I’m a huge fan of Django but I think for a static, fast, and lightweight site, Next.js my new go to!
I also occasionally blog on my personal site, where this post was originally published.