Skip to content

Commit 7afb312

Browse files
authored
feat: 更换github pages部署方式,支持actions部署 (#144)
* feat: 更换github pages部署方式,支持actions部署 * chore: update * chore: update
1 parent fd469f1 commit 7afb312

File tree

1 file changed

+21
-42
lines changed

1 file changed

+21
-42
lines changed

.github/workflows/CD.yaml

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
push:
1010
branches:
1111
- next
12+
- refactor/deploy
1213
workflow_dispatch:
1314

1415
# 环境变量
@@ -17,12 +18,21 @@ env:
1718
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
1819
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
1920

21+
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
22+
permissions:
23+
contents: read
24+
pages: write
25+
id-token: write
26+
2027
jobs:
2128
# 部署到Github-Pages
2229
deploy-github:
2330
name: 部署到Github-Pages
24-
if: github.repository == '142vip/JavaScriptCollection'
2531
runs-on: ubuntu-latest
32+
environment:
33+
name: github-pages
34+
url: ${{ steps.deployment.outputs.page_url }}
35+
if: github.repository == '142vip/JavaScriptCollection'
2636

2737
steps:
2838
- name: Checkout Code
@@ -52,43 +62,19 @@ jobs:
5262
run: |
5363
./scripts/ci
5464
55-
# 运行构建脚本
56-
- name: Build VuePress Site
57-
run: |
58-
./scripts/bundle build_proxy
59-
60-
# 将README.md同步,利于github pages分支展示
61-
- name: Add Readme.md To Dist
62-
run: |
63-
cp -f README.md docs/.vuepress/dist
65+
# 编译 打包成dist
66+
- name: Build with VitePress
67+
run: pnpm build:proxy
6468

65-
- name: Check GitHub Pages status
66-
uses: crazy-max/ghaction-github-status@v3
69+
- name: Upload artifact
70+
uses: actions/upload-pages-artifact@v3
6771
with:
68-
pages_threshold: major_outage
72+
path: docs/.vuepress/dist
6973

70-
# 获取Git提交信息
71-
- name: Get Commit Info
72-
id: gitInfo
73-
run: |
74-
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
75-
echo "author=$(git log -1 --pretty=%an)" >> $GITHUB_OUTPUT
76-
echo "email=$(git log -1 --pretty=%ae)" >> $GITHUB_OUTPUT
77-
78-
# 参考:https://github.com/marketplace/actions/github-pages
79-
- name: Deploy To GitHub Page
80-
uses: crazy-max/ghaction-github-pages@v3
81-
with:
82-
target_branch: pages/github
83-
build_dir: docs/.vuepress/dist
84-
commit_message: |
85-
chore(sync): v${{steps.gitInfo.outputs.version}}
86-
87-
部署地址: https://142vip.github.io/JavaScriptCollection
88-
committer: ${{steps.gitInfo.outputs.author}}<${{steps.gitInfo.outputs.email}}>
89-
author: Mr·Sync
90-
env:
91-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
# 部署
75+
- name: Deploy to GitHub Pages
76+
id: deployment
77+
uses: actions/deploy-pages@v4
9278

9379
# 部署到vercel平台
9480
# deploy-vercel:
@@ -134,13 +120,6 @@ jobs:
134120
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
135121
fetch-depth: 0
136122

137-
# ## 打成压缩包
138-
- name: Create Zip Package
139-
run: |
140-
zip -r JavaScriptCollection.zip . \
141-
-x "node_modules/*" \
142-
-x "*.git*"
143-
144123
# 安装PNPM
145124
- name: PNPM Install
146125
uses: pnpm/action-setup@v4

0 commit comments

Comments
 (0)