|
1 |
| -name: Build and Deploy |
2 |
| - |
| 1 | +name: Deploy to GitHub Pages |
| 2 | + |
3 | 3 | on:
|
4 | 4 | push:
|
5 | 5 | branches:
|
6 |
| - - master # 或者你想要触发构建的分支 |
7 |
| - |
| 6 | + - master # 触发部署的分支 |
| 7 | + |
8 | 8 | jobs:
|
9 |
| - build-and-deploy: |
10 |
| - runs-on: ubuntu-latest # 使用 Ubuntu 最新版本 |
11 |
| - |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
12 | 12 | steps:
|
13 |
| - - name: Checkout code |
14 |
| - uses: actions/checkout@v2 # 获取代码 |
15 |
| - |
16 |
| - - name: Setup Node.js |
17 |
| - uses: actions/setup-node@v2 # 设置 Node.js 环境 |
18 |
| - with: |
19 |
| - node-version: '20' # 使用 Node.js 的特定版本,例如 14.x |
20 |
| - |
21 |
| - - name: Install pnpm |
22 |
| - uses: pnpm/[email protected] # 设置 pnpm |
23 |
| - with: |
24 |
| - version: 9 # 使用特定版本的 pnpm,例如 6.x |
25 |
| - run_install: false # 先不运行安装,因为我们稍后会自定义步骤 |
26 |
| - |
27 |
| - - name: Get pnpm store directory |
28 |
| - id: pnpm-cache |
29 |
| - shell: bash |
30 |
| - run: | |
31 |
| - echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT |
32 |
| - - name: Setup pnpm cache |
33 |
| - uses: actions/cache@v2 |
34 |
| - with: |
35 |
| - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} |
36 |
| - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
37 |
| - restore-keys: | |
38 |
| - ${{ runner.os }}-pnpm-store- |
39 |
| - - name: Install dependencies |
40 |
| - run: pnpm install --frozen-lockfile # 使用 pnpm 安装依赖,并使用锁文件确保一致性 |
41 |
| - |
42 |
| - - name: Build project |
43 |
| - run: pnpm run build # 构建你的项目,确保在 package.json 中有相应的 script |
44 |
| - |
45 |
| - # 下面的步骤可以根据你的部署需求进行配置,例如部署到 GitHub Pages 或其他静态站点托管服务。 |
46 |
| - # 这里以部署到 GitHub Pages 为例: |
47 |
| - - name: Deploy to GitHub Pages |
48 |
| - uses: peaceiris/actions-gh-pages@v3 # 使用 GitHub Pages 部署动作 |
49 |
| - with: |
50 |
| - # github_token: ${{ secrets.GITHUB_TOKEN }} # 使用 GitHub token 进行身份验证 |
51 |
| - publish_dir: ./dist # 指定构建产物的目录,例如 Vite 的默认输出目录是 dist |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v2 |
| 15 | + |
| 16 | + - name: Set up Node.js |
| 17 | + uses: actions/setup-node@v2 |
| 18 | + with: |
| 19 | + node-version: '20' # 使用的 Node.js 版本 |
| 20 | + cache: 'pnpm' # 启用 pnpm 缓存 |
| 21 | + |
| 22 | + - name: Install pnpm |
| 23 | + run: npm install -g pnpm |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: pnpm install |
| 27 | + |
| 28 | + - name: Build |
| 29 | + run: pnpm run build |
| 30 | + |
| 31 | + - name: Deploy to GitHub Pages |
| 32 | + uses: peaceiris/actions-gh-pages@v3 |
| 33 | + with: |
| 34 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + publish_dir: ./dist # Vite 默认构建输出目录 |
0 commit comments