起因
每次写Action调试经常出错还麻烦,套用别人的例子呢,除了难找之外(毕竟不少都是私有库,想参考action也有点难),有些博客魔改的太多,配置了CMS的更麻烦,不少action例子基本不太能做到复制粘贴运行不出错,还是要靠自己一步步慢慢调。
另外这方面的文章较少,新手也容易掉坑,调起来也特麻烦,所以还是发表该贴,同时也是方便自己备忘。
该 action yml 解决两个痛点:
- 无需配置 ssh key、deploy key、personal access tokens
- 无需创建 gh-pages 分支
只需在仓库设置 Settings >GitHub Pages > GitHub Action

代码转载处及配置项
代码转载处:
hexo 部分,时间间隔太久了,参考过的其他出处也忘了,自己也改动很多。
这两个部分自动化部署都不需要配置 key,也不需要创建 gh-pages 分支,直接部署就行,方便很多。
Astro
https://github.com/hoochanlon/hoochanlon.github.io/blob/main/.github/workflows/deploy-base.yml
name: GitHub Pages Astro CI
on:
# 每次推送到 `main` 分支时触发这个“工作流程”
push:
branches: [ main ]
# 允许你在 GitHub 上的 Actions 标签中手动触发此“工作流程”
workflow_dispatch:
# 允许 job 克隆 repo 并创建一个 page deployment
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout your repository using git
uses: actions/checkout@v4
- name: Install, build, and upload your site
uses: withastro/action@v5 # 更新为最新的 withastro action 版本
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # 已是 v4 版本,确保版本匹配
hexo
https://github.com/hoochanlon/hoochanlon.github.io/releases/tag/hexo-butterfly-final
name: Build and Deploy to GitHub Pages
on:
push:
branches: [ master ]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22' # 推荐使用最新 LTS 版本
cache: 'npm'
- name: Install dependencies
run: |
npm ci
# 确保安装所有必需的渲染器
npm install hexo-renderer-pug hexo-renderer-stylus --save
- name: Build
run: |
npx hexo clean
npx hexo generate
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
|