Skip to content

Commit ae76083

Browse files
committed
fix(deploy): fix pnpm run build
1 parent 21dd6b0 commit ae76083

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

.github/workflows/build.yml

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
name: Build and Check
1+
name: Build and Deploy to GitHub Pages
22

33
on:
44
push:
5-
branches: [ main ] # Adjust branches as needed
5+
branches: [ main, master ] # 只在 main 分支 push 时触发
66
pull_request:
7-
branches: [ main ] # Adjust branches as needed
7+
branches: [ main, master ] # PR 时只做检查,不部署
88

99
concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212

1313
permissions:
14-
contents: read
14+
contents: write # 需要写入权限来部署到 GitHub Pages
15+
pages: write # 专门的 Pages 部署权限
16+
id-token: write # OIDC 认证所需的权限
17+
administration: write
1518

1619
jobs:
1720
check:
1821
strategy:
1922
matrix:
20-
node: [ 22, 23 ]
23+
node: [ 20 ] # GitHub Pages 推荐 LTS 版本
2124
runs-on: ubuntu-latest
2225
name: Astro Check for Node.js ${{ matrix.node }}
2326
steps:
2427
- name: Setup Node.js
2528
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
2629
with:
27-
node-version: ${{ matrix.node }} # Use LTS
30+
node-version: ${{ matrix.node }} # 使用 LTS
2831

2932
- name: Checkout
30-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
uses: actions/checkout@v4
3134

3235
- name: Setup pnpm
3336
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
@@ -40,20 +43,19 @@ jobs:
4043
- name: Run Astro Check
4144
run: pnpm astro check
4245

43-
build:
44-
strategy:
45-
matrix:
46-
node: [ 22, 23 ]
46+
deploy:
47+
if: ${{ github.event_name == 'push' && contains(' refs/heads/main refs/heads/master ', github.ref) }}
48+
needs: check # 确保检查通过后再部署
4749
runs-on: ubuntu-latest
48-
name: Astro Build for Node.js ${{ matrix.node }} # Corrected job name
50+
name: Deploy Astro Site to GitHub Pages
4951
steps:
5052
- name: Setup Node.js
5153
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
5254
with:
53-
node-version: ${{ matrix.node }}
55+
node-version: 20
5456

5557
- name: Checkout
56-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
58+
uses: actions/checkout@v4
5759

5860
- name: Setup pnpm
5961
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
@@ -63,5 +65,22 @@ jobs:
6365
- name: Install dependencies
6466
run: pnpm install --frozen-lockfile
6567

66-
- name: Run Astro Build
67-
run: pnpm astro build
68+
# 构建生产版本
69+
- name: Build Astro site
70+
run: pnpm run build # Astro 的默认构建命令是 'astro build'
71+
72+
# 部署到 GitHub Pages
73+
- name: Setup Pages
74+
uses: actions/configure-pages@v4
75+
with:
76+
enablement: true
77+
# token: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Upload artifact
80+
uses: actions/upload-pages-artifact@v3
81+
with:
82+
path: './dist' # 匹配 Astro 默认输出目录
83+
84+
- name: Deploy to GitHub Pages
85+
id: deployment
86+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)