52 lines
1.2 KiB
YAML
52 lines
1.2 KiB
YAML
name: Deploy GitHub Pages
|
|
|
|
# 触发条件
|
|
on:
|
|
# 手动触发
|
|
workflow_dispatch:
|
|
# 当代码推送到主分支时触发
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
# 拉取代码
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# 缓存 node_modules
|
|
- name: Cache node_modules
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.npm
|
|
node_modules
|
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-node-
|
|
|
|
# 设置 Node.js 环境
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
|
|
# 安装依赖
|
|
- name: Install dependencies
|
|
run: npm install
|
|
|
|
# 构建项目
|
|
- name: Build
|
|
run: npm run build
|
|
|
|
# 部署到 GitHub Pages
|
|
- name: Deploy to GitHub Pages
|
|
uses: peaceiris/actions-gh-pages@v3
|
|
with:
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
publish_dir: ./dist # 这里的 dist 是构建后的文件目录,根据实际情况修改 |