Skip to content

Commit 700d4e9

Browse files
committed
Add GitHub Actions workflow
1 parent aeca783 commit 700d4e9

File tree

2 files changed

+43
-66
lines changed

2 files changed

+43
-66
lines changed

.github/workflows/deploy.yml

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,49 @@
1-
name: Hexo Auto Deploy
1+
name: Deploy Hexo-theme-snippet to GitHub Pages
22

33
on:
44
push:
5-
branches:
6-
- dev
7-
workflow_dispatch:
8-
9-
env:
10-
GIT_USER: shenliyang
11-
GIT_EMAIL: 14257483+shenliyang@users.noreply.github.com
12-
GIT_DEPLOY_REPO: shenliyang/shenliyang.github.io
13-
GIT_DEPLOY_BRANCH: master
14-
15-
GITEE_USER: shenliyang
16-
GITEE_DEPLOY_REPO: shenliyang/shenliyang
17-
GITEE_DEPLOY_BRANCH: master
18-
19-
GIT_SOURCE_REPO: git@github.com:shenliyang/shenliyang.github.io.git
20-
GITEE_DESTINATION_REPO: git@gitee.com:shenliyang/shenliyang.git
5+
branches: [dev] # 只在dev分支推送时触发
216

227
jobs:
23-
build:
24-
name: Build on node ${{ matrix.node_version }} and ${{ matrix.os }}
8+
build-and-deploy:
259
runs-on: ubuntu-latest
26-
if: github.event.repository.owner.id == github.event.sender.id
27-
strategy:
28-
matrix:
29-
os: [ubuntu-18.04]
30-
node_version: [14.x]
31-
10+
3211
steps:
33-
- name: Checkout
34-
uses: actions/checkout@v2
35-
36-
- name: Checkout deploy repo
37-
uses: actions/checkout@v2
38-
with:
39-
repository: ${{ env.GIT_DEPLOY_REPO }}
40-
ref: ${{ env.GIT_DEPLOY_BRANCH }}
41-
path: .deploy_git
42-
43-
- name: Use Node.js ${{ matrix.node_version }}
44-
uses: actions/setup-node@v1
45-
with:
46-
node-version: ${{ matrix.node_version }}
47-
48-
- name: Configuration environment
49-
env:
50-
HEXO_DEPLOY_PRI: ${{secrets.HEXO_DEPLOY_PRI}}
51-
run: |
52-
sudo timedatectl set-timezone "Asia/Shanghai"
53-
sudo apt-get update
54-
sudo apt-get install libnotify-bin
55-
mkdir -p ~/.ssh/
56-
echo "$HEXO_DEPLOY_PRI" > ~/.ssh/id_rsa
57-
chmod 600 ~/.ssh/id_rsa
58-
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
59-
# ssh-keyscan -t rsa gitee.com >> ~/.ssh/known_hosts
60-
git config --global user.name $GIT_USER
61-
git config --global user.email $GIT_EMAIL
62-
63-
- name: Install dependencies
64-
run: |
65-
npm install hexo-cli gulp-cli hexo-deployer-git -g
66-
npm install
67-
hexo clean && hexo g
68-
gulp
69-
70-
- name: Deploy hexo
71-
run: |
72-
npm run deploy
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
ref: dev # 明确指定检出dev分支
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: '20' # Hexo推荐使用Node.js 12+
21+
22+
- name: Install Hexo and dependencies
23+
run: |
24+
npm install -g hexo-cli
25+
npm install
26+
27+
- name: Build static files
28+
run: |
29+
hexo clean
30+
hexo generate
31+
32+
# 部署到gh-pages分支
33+
- name: Deploy to GitHub Pages
34+
uses: peaceiris/actions-gh-pages@v3
35+
with:
36+
github_token: ${{ secrets.GITHUB_TOKEN }}
37+
publish_dir: ./public # Hexo默认生成的静态文件目录
38+
publish_branch: gh-pages # 部署的目标分支
39+
40+
# 或者如果你想部署到main分支的docs文件夹
41+
# - name: Deploy to docs folder
42+
# run: |
43+
# mkdir -p docs
44+
# cp -r public/* docs/
45+
# git config --global user.name "GitHub Actions"
46+
# git config --global user.email "actions@github.com"
47+
# git add docs
48+
# git commit -m "Update GitHub Pages"
49+
# git push

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ plugins:
7575
deploy:
7676
type: git
7777
repo: https://github.com/shenliyang/shenliyang.github.io.git
78-
branch: master
78+
branch: gh-pages

0 commit comments

Comments
 (0)