Jekyll GitHub Actions
I had wanted to add a new collection to this site with a categorized view of various code snippets to collect for posterity. I was inspired by Alexandru Nedelcu’s snippet section where he has a similar collection of unstructured code dumps.
Previously, this site leveraged the simple setup provided by GitHub, which makes setting up a GitHub Pages site with Jekyll, hosted directly from a GitHub repository, quick and painless. The default setup gives you quite a bit in terms of low barrier blogging. For example, GitHub builds the site automatically on push to your repo and enables some Jekyll plugins by default. However, if your needs extends beyond this set of plugins, GitHub Pages cannot build sites using unsupported plugins. If you want to use unsupported plugins, you need to generate the site locally and push the static files to GitHub.
When I program, I don’t typically store machine generated source or compiled binaries in
my version control system. I see the statically generated site through a similar lens and
felt it wasn’t something I wanted to manage myself. So I did some digging and found a
page on the Jekyll documentation site for setting up jekyll-actions, which
should be able to do the work for me instead. The generated site will still be stored in
my repo in order for GitHub to be able to serve the site, however, it’ll be sequestered
to the gh-pages
branch and completely managed by the workflow. A compromise I can happily
live with. In order to get the new workflow to function, I needed to make some configuration
changes to my repo. First, as the documentation site states, I needed to create a Personal
Access Token. After that was configured as a secret for my repo, I was able to push the
first commit to test the action and make sure the pipeline worked as expected. The
action can be configured with the following snippet:
where JEKYLL_PAT
represents the secret that was created for my repo. After this commit was
built, I saw that the action created a new gh-pages
branch in my repository with the statically
generated site contents. I then changed the source branch in the Setting tab under GitHub Pages
to reflect the new branch that GitHub should use to publish my site contents. After this was
complete, I was able to easily add the new snippets section to my blog.
Here’s to more forthcoming contributions!