Use Github Action for Jekyll Static Site
26 Mar 2023I used to use github pages for my jekyll blog post. There was a _site folder which contains the generated artifacts of my site.
I think have the artifacts added to the version control is not a good practice:
- The artifact is genrated, so I have duplications in my repo.
- If I change a template, all the pages in the artifacts will be changed. It will be hard for me to track my changes.
After read about the jekyll document. I decided to use Jekyll-aciton to generate my site with github action. The genrated files will be pushed to gh-pages
branch of my repo. And then I have to change the settings of my repo so it will use that branch for the static website:
The jekyll offical document about jekyll-aciton here is slightly outdated, I have to update my .github/jekyll-action.yml
file with the information from the README of the jekyll-action repo.
Here is the file I am currently using:
name: Build and deploy Jekyll site to GitHub Pages
on:
push:
branches:
- master # or master before October 2020
jobs:
github-pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile') }}
restore-keys: |
$-gems-
- uses: helaili/jekyll-action@v2 # Choose any one of the Jekyll Actions
with: # Some relative inputs of your action
token: $
target_branch: 'gh-pages'
The difference between this and the code from the offical website are:
- This uses v2 version of jekyll-action
- The target_branch is set to gh-pages