Note: Already Built GitHub Pages with Hexo
Set up access key for repo
Generate SSH keys
Open terminal and generate SSH keys by following command.
1 | ssh-keygen -f github-deploy-key |
Skip passphrase.
![SSH key generated on terminal](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/sshkeygen.png)
After generating, there should be 2 files.
![Private Key & Public Key](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/keyfile.png)
Set up private key
blog repo → Settings → Secrets → New secret
![Create new secret](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/newsecret.png)
Name: HEXO_DEPLOY_PRI
Value: All content in github-deploy-key
![Add Private Key as secret](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/enterHexoDeployPri.png)
⚠ Never upload or tell anyone Private Key. ⚠
Set up public key
blog repo → Settings → Deploy keys → add deploy key
![New deploy key](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/addDeployKeys.png)
Name: HEXO_DEPLOY_PUB
Value: All content in github-deploy-key.pub
Check “Allow write access” to enable push access
![Add Public Key as deploy key](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/deployKeysAddNew.png)
Build new workflow in github action
Create a workflow
Fisrt, set source branch as default branch.
Settings -> Branches -> Select your source branch -> Update
![Set Blog Source branch as default branch](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/setDefaultBranch.png)
Note: the workflow file will be created under default branch.
Action -> new workflow -> set up a workflow yourself
![Set up a workflow yourself](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/setWorkflowYourself.png)
Modify main.yml and commit
Replace “blog_source_branch”, “username”, “username@email.address“ with your own info.
1 | name: HEXO CI |
Note: Hexo CI creates a Virtual Machine and deploy website for you.
Commit main.yml into default branch.
![Commit main.yml into default branch](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/commitMainYAML.png)
Config Hexo deploy
Open “_config.yml” on local.
Change git repositary from http form to ssh form.
Deploy branch should be “master”.
![Deploy config](/2020/06/15/Github-Actions-CI-for-Hexo-Github-Page/configDeploySSH.png)
Known Issues
CI does not tiggered after push
- Check if source branch is set as trigger branch in main.yml
- Check if .github/workflows/main.yml locates under source branch
CI deploy hexo failed with no access
- Make sure keys are entered correctly
- Allow write access on Public Key
Deploy hexo failed with TypeError: line.matchAll is not a function
- Using node.js version above 12.0
Reference
https://help.github.com/en/actions
https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html
https://op30132.github.io/2020/02/05/github-action/