吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1126|回复: 6
收起左侧

[其他转载] [yml] GitHub Action 自动化 Astro 部署博客

  [复制链接]
hoochanlon 发表于 2025-12-18 23:51

起因

每次写Action调试经常出错还麻烦,套用别人的例子呢,除了难找之外(毕竟不少都是私有库,想参考action也有点难),有些博客魔改的太多,配置了CMS的更麻烦,不少action例子基本不太能做到复制粘贴运行不出错,还是要靠自己一步步慢慢调。

另外这方面的文章较少,新手也容易掉坑,调起来也特麻烦,所以还是发表该贴,同时也是方便自己备忘。

该 action yml 解决两个痛点:

  1. 无需配置 ssh key、deploy  key、personal access tokens
  2. 无需创建 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

免费评分

参与人数 1吾爱币 +2 热心值 +1 收起 理由
vethenc + 2 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| hoochanlon 发表于 2025-12-20 17:25
hsctest 发表于 2025-12-20 10:15
action编写我一边都是借助AI,有的语法还是很困难,关键是不好调试,有没有比较好的方式去调试编写过程呢?

我也暂时没找到好的调试过程,只能靠试错才成出完整版的action
YoungBai 发表于 2025-12-19 08:51
chitose0173 发表于 2025-12-19 09:43
vethenc 发表于 2025-12-19 10:53
感谢分享,非常实用
zt185 发表于 2025-12-19 13:21
看起来不错,下载自己研究一下!
hsctest 发表于 2025-12-20 10:15
action编写我一边都是借助AI,有的语法还是很困难,关键是不好调试,有没有比较好的方式去调试编写过程呢?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-12-25 14:19

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表