Github Actions
# 博客自动部署
name: Build and Update Github Pages
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
# 配置Node环境
- name: Use Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: "18.16.0"
# 拉取代码
- uses: actions/checkout@v4
# 安装hexo和生成静态文件
- name: Build
run: |
npm i -g hexo-cli
npm i
hexo generate
# 部署文件
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
repository-name: <Pages分支>
ssh-key: ${{ secrets.ACTION_DEPLOY_KEY }}
folder: ./public
single-commit: true
force: true
branch: master
# 拉取Pages网页分支
- uses: actions/checkout@v4
with:
repository: <Pages分支>
ssh-key: ${{ secrets.ACTION_DEPLOY_KEY }}
ref: master
# 清除提交记录
- name: Clear
run: |
git config --global user.email "[email protected]"
git config --global user.name "example"
git checkout --orphan temp_branch
git add -A
git commit -m "Keep only latest commit"
git branch -D master
git branch -m master
git push -f origin master
上次更新: 2025/03/22, 03:52:10