1+ # .github/workflows/deploy.yml
2+
3+ name : Deploy to GitHub Pages
4+
5+ on :
6+ push :
7+ branches :
8+ - main
9+
10+ env :
11+ NODE_VERSION : ' 16.x' # 您已更改为 Node.js 16.x
12+
13+ permissions : # <--- 添加这个 permissions 块
14+ contents : write # 允许 GITHUB_TOKEN 对仓库内容进行写操作(例如推送分支)
15+
16+ jobs :
17+ build-and-deploy :
18+ name : Build and Deploy
19+ runs-on : ubuntu-latest
20+ # 或者在这里为特定作业设置权限:
21+ # permissions:
22+ # contents: write
23+
24+ steps :
25+ - name : Checkout 🛎️
26+ uses : actions/checkout@v4
27+
28+ - name : Set up Node.js ${{ env.NODE_VERSION }} ⚙️
29+ uses : actions/setup-node@v4
30+ with :
31+ node-version : ${{ env.NODE_VERSION }}
32+ cache : ' yarn'
33+
34+ - name : Install dependencies 📦
35+ run : yarn install --frozen-lockfile
36+
37+ - name : Update Browserslist database (optional but recommended)
38+ run : npx browserslist@latest --update-db
39+
40+ - name : Build project 🛠️
41+ run : yarn build
42+ # 如果您在使用 Node 16 时仍然遇到 OpenSSL 错误 (不太可能,但以防万一)
43+ # 您可能仍然需要 NODE_OPTIONS。但通常 Node 16 是可以的。
44+ # env:
45+ # NODE_OPTIONS: --openssl-legacy-provider
46+
47+ # 可选步骤:列出 dist 目录内容,以验证构建输出
48+ - name : List build directory contents
49+ run : ls -R ./dist
50+
51+ - name : Deploy to GitHub Pages 🚀
52+ uses : peaceiris/actions-gh-pages@v4
53+ with :
54+ github_token : ${{ secrets.GITHUB_TOKEN }}
55+ publish_dir : ./dist
56+ # publish_branch: gh-pages # 默认是 gh-pages,可以省略
57+ # user_name: 'github-actions[bot]' # 自定义提交者名称 (可选)
58+ # user_email: 'github-actions[bot]@users.noreply.github.com' # 自定义提交者邮箱 (可选)
59+ # commit_message: ${{ github.event.head_commit.message }} # 使用最后一次提交的消息作为部署提交消息 (可选)
60+ # cname: your-custom-domain.com # 如果您使用自定义域名,请取消注释并替换
0 commit comments