github action + jekyll
在過去的jekyll網站部署中,流程為在本地撰寫md文件,跑一下bundle exec jekyll serve
取得編譯完成的網頁html檔案,再丟上去gh-page,每次手動都很麻煩。github 推出了自家的ci/cd 叫做github action,本教學教您如何透過github action自動編譯、部署jekyll 網頁到 gh-pages。
取得 github action token
- 取得新的 token https://github.com/settings/tokens/new
輸入 輸入token 到該目標倉庫
- 網頁點擊: settings » secrets
插入github action 腳本
- 在
.github/workflows
創建run.yml
文件 - 插入以下程式碼:
name: Build and deploy Jekyll site to GitHub Pages
on:
push:
branches:
- master
jobs:
github-pages:
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v2
- uses: helaili/jekyll-action@2.0.1
env:
JEKYLL_PAT: $
執行結果
debug 插曲
gem 套件版本問題
在本地端編譯都不是問題,但是在github action 編譯過程中卻遇到gem 版本不符的問題。
Starting the Jekyll Action
Your Gemfile has no gem server sources. If you need gems that are not already on
your machine, add a line like this to your Gemfile:
source 'https://rubygems.org'
Your bundle is locked to public_suffix (1.5.3), but that version could not be
found in any of the sources listed in your Gemfile. If you haven't changed
sources, that means the author of public_suffix (1.5.3) has removed it. You'll
need to update your bundle to a version other than public_suffix (1.5.3) that
hasn't been removed in order to install.
問題解決
在Gemfile
文件第一行添加來源,即可解決
source 'https://rubygems.org'
github action market 最多人在用的 aaction 不能用
https://github.com/marketplace/actions/jekyll-actions這是在market 最多人在用的版本,但該版本有致命的問題,無法自動部署 gh-pages 分支。 作者也說這有問題: 我嘗試了很久沒有看到問題的解決方案….
問題解決 直接換一個github action 程式碼吧 https://jekyllrb.com/docs/continuous-integration/github-actions/ 這是由jekyll 官方網站提供的版本。成功可以運作
參考文獻
Written on October 9, 2020