惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
M
MIT News - Artificial intelligence
D
Docker
量子位
T
Tailwind CSS Blog
人人都是产品经理
人人都是产品经理
月光博客
月光博客
有赞技术团队
有赞技术团队
J
Java Code Geeks
A
About on SuperTechFans
P
Proofpoint News Feed
Jina AI
Jina AI
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
V
V2EX
GbyAI
GbyAI
F
Fortinet All Blogs

新锐博客

vscode连接cnb并推送仓库 - 新锐博客 twikoo不用token查询文章浏览量 - 新锐博客 基于Astro构建的支持对话与生图的Web应用 - 新锐博客 deepseek-v4-flash-0731使用体验 - 新锐博客 基元律动免费送68元额度 - 新锐博客 Linux更换软件源 - 新锐博客 华为鸿蒙7.0花粉beta版发布 - 新锐博客 使用测速脚本测一下服务器带宽 - 新锐博客 trae告别白嫖时代,auto也需排队了 - 新锐博客 流量不够用?大流量卡免费领 - 新锐博客 推荐一个免费在线图片处理网站 - 新锐博客 AI清理C盘的优缺点 - 新锐博客 twikoo不算bug的bug - 新锐博客 最近网站的一些变动 - 新锐博客 腾讯EO开始发多余套餐啦!速领 - 新锐博客 hi168停止对个人用户的运营 - 新锐博客 哪吒监控曝高危漏洞,请尽快升级 - 新锐博客 IndexDB实现大文件下载的思路 - 新锐博客 鱼鱼api使用教程 - 新锐博客 服务器安装Dokploy替代vercel - 新锐博客 对于近几年的电视剧的无力吐槽 - 新锐博客 关于网站被攻击的后续 - 新锐博客 使用sessionStorage给音乐播放进度存储 - 新锐博客 修复了一些bug,网站基本上趋于稳定了 - 新锐博客 AI模型掺水?如何辨别真假? - 新锐博客 感谢一九云给我防住了攻击 - 新锐博客 对一些新手使用AI编程的建议 - 新锐博客 Edgeone标记过期和直接删除有何区别? - 新锐博客 用Navigation Timing API给博客添加上加载时间 - 新锐博客 使用 Astro 自建博客,从零开始鏖战 14 小时 - 新锐博客
Github Action自动部署hexo网站 - 新锐博客
莫忘 · 2025-09-07 · via 新锐博客

前言

最近把自己的hexo网站上传到了github上,然后就兴趣上来想构建一下看看,于是就用AI写了一个脚本,可以把构建的文件生成到别的分支上。

只需要将脚本放到.github/workflows/目录下的文件下即可,文件名可以自己随便取,然后将代码放进去

name: Hexo Build and Deploy to Pages Branch

on:
  release:
    types: [created]
  workflow_dispatch:
    inputs:
      buildEnvironment:
        description: '构建环境'
        required: true
        default: 'production'
        type: choice
        options:
          - production
          - development
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: write  # 增加写权限,解决权限不足问题
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
          fetch-depth: 0  # 拉取完整历史,避免git操作失败
          
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
      
      - name: Install dependencies
        run: npm ci
      
      - name: Install Hexo CLI
        run: npm install -g hexo-cli
      
      - name: Build Hexo site
        run: hexo generate
        env:
          NODE_ENV: ${{ github.event.inputs.buildEnvironment || 'production' }}
      
      - name: Clean pages branch (if exists)
        run: |
          git fetch origin pages || true
          git checkout pages || git checkout --orphan pages
          git rm -rf . || true
        continue-on-error: true  # 分支不存在时也继续执行
      
      - name: Copy build files
        run: cp -r ./public/* .
      
      - name: Deploy to pages branch
        run: |
          git config --global user.email "action@github.com"
          git config --global user.name "GitHub Action"
          git add .
          git commit -m "Deploy from ${{ github.sha }}" || echo "No changes to commit"
          git push origin pages --force

经测试是正常的,我也看不懂Github的脚本,有懂的大佬可以自行更改,并留言。

莫忘

君子喻以义,小人喻以利

本文是原创文章,采用 CC BY-NC-SA 4.0 协议,完整转载请注明来自 新锐博客