Skip to content

Workflow file for this run

# Inspired from https://github.com/actions/starter-workflows/blob/main/pages/nextjs.yml
name: GitHub Pages
on:
push:
branches: main # 当推送到main分支时触发
workflow_dispatch: # 允许手动触发工作流
permissions:
contents: read # 允许读取仓库内容
pages: write # 允许写入GitHub Pages
id-token: write # 允许写入ID令牌
concurrency:
group: 'pages' # 并发组名称
cancel-in-progress: false # 不取消正在进行的工作流
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # 检出代码
- uses: actions/setup-node@v4 # 设置Node.js环境
with:
node-version: '20' # 使用Node.js 20版本
cache: yarn # 缓存yarn依赖
- id: configurepages
uses: actions/configure-pages@v5 # 配置GitHub Pages
with:
enablement: true # 启用GitHub Pages
- name: Restore cache # 恢复缓存
uses: actions/cache@v4
with:
path: .next/cache # 缓存Next.js构建缓存
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
- run: yarn # 安装依赖
- run: yarn build # 构建项目
env:
EXPORT: 1 # 启用静态导出
UNOPTIMIZED: 1 # 禁用图像优化
BASE_PATH: ${{ steps.configurepages.outputs.base_path }} # 设置基础路径
- uses: actions/upload-pages-artifact@v3 # 上传构建产物
with:
path: ./out # 指定构建输出目录
# 部署任务
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }} # 设置部署环境和URL
runs-on: ubuntu-latest
needs: build # 依赖build任务完成
steps:
- id: deployment
uses: actions/deploy-pages@v4 # 部署到GitHub Pages