Github Actions自动构建博客

新建Secret

在博客项目的的Secrets里面新建一个Secret,名为CI_PRIVATE_KEY,将内容设置为配置在GitHub中的公钥对应的私钥。

配置工作流

在项目根目录下新建.github/workflow/nodejs.yaml,内容为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Hexo CI

on:
push:
branches: hexo

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- name: Setup Source
uses: actions/[email protected]
with:
ref: hexo
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- name: Setup Hexo
env:
ACTION_DEPLOY_KEY: ${{ secrets.CI_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.email "[email protected]"
git config --global user.name "Jason210314"
npm install -g hexo
yarn install
- name: Hexo Deploy
run: |
hexo c
hexo g
hexo d
env:
CI: true

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×