chore: 优化 GitHub Actions 打包脚本 refer: https://vitejs.cn/vitepress/guide/deploy.html
Some checks are pending
Deploy GitHub Pages / build (push) Waiting to run
Deploy GitHub Pages / Deploy (push) Blocked by required conditions
Some checks are pending
Deploy GitHub Pages / build (push) Waiting to run
Deploy GitHub Pages / Deploy (push) Blocked by required conditions
This commit is contained in:
65
.github/workflows/deploy-pages.yml
vendored
65
.github/workflows/deploy-pages.yml
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
# 构建 VitePress 站点并将其部署到 GitHub Pages
|
||||||
name: Deploy GitHub Pages
|
name: Deploy GitHub Pages
|
||||||
|
|
||||||
# 触发条件
|
# 触发条件
|
||||||
@@ -9,44 +10,64 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
# 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列
|
||||||
|
# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成
|
||||||
|
concurrency:
|
||||||
|
group: pages
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
# 构建工作
|
||||||
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# 拉取代码
|
# 拉取代码
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0 # 如果未启用 lastUpdated,则不需要
|
||||||
|
|
||||||
# 缓存 node_modules
|
# - uses: pnpm/action-setup@v3 # 如果使用 pnpm,请取消注释
|
||||||
- name: Cache node_modules
|
# - uses: oven-sh/setup-bun@v1 # 如果使用 Bun,请取消注释
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.npm
|
|
||||||
node_modules
|
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-node-
|
|
||||||
|
|
||||||
# 设置 Node.js 环境
|
# 设置 Node.js 环境
|
||||||
- name: Set up Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 22
|
node-version: 22
|
||||||
|
cache: npm # 或 pnpm / yarn
|
||||||
|
|
||||||
|
- name: Setup Pages
|
||||||
|
uses: actions/configure-pages@v4
|
||||||
|
|
||||||
# 安装依赖
|
# 安装依赖
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm install
|
run: npm ci # 或 pnpm install / yarn install / bun install
|
||||||
|
|
||||||
# 构建项目
|
# 构建项目
|
||||||
- name: Build
|
- name: Build with VitePress
|
||||||
run: npm run build
|
run: npm run docs:build # 或 pnpm docs:build / yarn docs:build / bun run docs:build
|
||||||
|
|
||||||
# 部署到 GitHub Pages
|
- name: Upload artifact
|
||||||
- name: Deploy to GitHub Pages
|
uses: actions/upload-pages-artifact@v3
|
||||||
uses: peaceiris/actions-gh-pages@v3
|
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
path: docs/.vitepress/dist
|
||||||
publish_dir: ./dist # 这里的 dist 是构建后的文件目录,根据实际情况修改
|
|
||||||
|
# 部署工作
|
||||||
|
deploy:
|
||||||
|
environment:
|
||||||
|
name: github-pages
|
||||||
|
url: ${{ steps.deployment.outputs.page_url }}
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Deploy
|
||||||
|
steps:
|
||||||
|
- name: Deploy to GitHub Pages
|
||||||
|
id: deployment
|
||||||
|
uses: actions/deploy-pages@v4
|
||||||
|
Reference in New Issue
Block a user