Skip to content

Update ci.yml

Update ci.yml #3

Workflow file for this run

name: CI & Deploy
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
# 允许在 Actions 面板手动触发此工作流
workflow_dispatch:
# 部署到 GitHub Pages 所需的权限设置
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
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Setup Pages
uses: actions/configure-pages@v5
with:
static_site_generator: next
- name: Restore Next.js cache
uses: actions/cache@v4
with:
path: |
.next/cache
# 使用 pnpm-lock.yaml 生成缓存 hash
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
- name: Install dependencies
run: pnpm install
- name: Lint
run: pnpm run lint
- name: Type check
run: pnpm run types:check
- name: Build
run: pnpm run build
- name: Upload artifact
# 仅在 push 或手动触发时上传构建产物,PR 时跳过
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: actions/upload-pages-artifact@v3
with:
path: ./out
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
# 仅在 push 或手动触发时执行部署操作,PR 时跳过部署
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4