blog github actions config

0x00

blog 配置一下 github actions

0x01

前阵子发现 travis 已经失效,考虑配置一下 github actions

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
48
49
50
51
52
53
54
55
56
57
58
59
60
name: blog deploy

on:
push:
branches:
- blog # blog 分支 push 的时候才进行作业
paths:
- 'source/**'
- 'themes/**'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 12 ]
name: A job to deploy blog.
steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true # Checkout private submodules(themes or something else).

- name: 2. set node version
uses: actions/setup-node@master
with:
node-version: ${{ matrix.node-version }}

# Caching dependencies to speed up workflows. (GitHub will remove any cache entries that have not been accessed in over 7 days.)
- name: Cache node modules
uses: actions/cache@v1
id: cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci # 类似 npm install, 比 npm install 速度更快

# Deploy hexo blog website.
- name: update blog
env:
GITHUB_LOGIN: ronething
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./node_modules/hexo/bin/hexo clean && ./node_modules/hexo/bin/hexo g
cd ./public
git init
git config user.name "xxxx"
git config user.email "xxxx"
git add .
git commit -m "update blog"
git push --force --quiet https://$GITHUB_LOGIN:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git master:master

- name: echo
run: |
echo "update blog ok"

0x02

那么希望可以持续更新下 blog

Author: ronething
Link: https://blog.ronething.cn/20220522-github-actions.html
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.