GitHub Pages workflow
This is a basic GitHub Pages workflow that builds and deploys a static site using GitHub Actions. This workflow is used on this site and is a good starting point for a simple static site.
Triggers
This workflow is triggered on push to the main
branch and through a manual trigger/dispatch.
1 2 3 4 5 |
|
Permissions
This workflow requires write permissions to the repository via an oidc token as well as GitHub Pages write permissions to request a GitHub Pages build.
1 2 3 |
|
Build job
The build job does what it says on the tin, it checks out the repository and installs the required dependencies, then builds a binary and runs it to generate the static site. Finally, it uploads the static files as an artifact.
By using the actions/setup-go action, we can install the required version of Go for the project and get caching of the Go modules used in the project for free.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Aside
I do plan on refactoring/extending this at some point to cache the binary and reuse it in a scheduled job to re-generate the static site instead of discarding it after each build. This would allow for a faster build and deploy process and would allow the fetched data ingested by the program to be up to date without needing to rebuild the entire binary. But that’s a problem for another day.
Deploy job
This job deploys the static site to GitHub Pages using the artifact generated in the build job.
This step uses the concurrency and environment features of GitHub Actions to ensure that only one deployment is waiting for approval at a time and to provide a link to the deployed site in the GitHub UI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Full Workflow
Full raw workflow can be found here.