-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (105 loc) · 5.34 KB
/
use-vercel-cli-build-try-4.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 参考资料
# https://vercel.com/guides/how-can-i-use-github-actions-with-vercel
# https://vercel.com/guides/how-to-alias-a-preview-deployment-using-the-cli
name: 基于vercel命令的部署
env:
# vercel的token
vct: ${{ secrets.vercel_token }}
# 从教程内得知 环境变量名称必须大写
VERCEL_ORG_ID: ${{ secrets.vercel_orgId }}
VERCEL_PROJECT_ID: ${{ secrets.vercel_projectId }}
# vercel项目名称
pjn: vercel-monorepo-test-1-zn20
# 项目路径
p1: ./packages/monorepo-1
p2: ./packages/proj-2-vp2-custom-components
p3: ./packages/monorepo-3
p4: ./packages/monorepo-4
p5: ./packages/monorepo-5
docs01Star: ./packages/docs-01-star
eci: ./.eslint-config-inspector
# 项目url
p1-url: monorepo-1.ruancat6312.top
p2-url-1: monorepo-2.ruancat6312.top
p2-url-2: m2.ruan-cat.com
p2-url-3: m2.ruancat6312.top
p3-url: monorepo-3.ruancat6312.top
p4-url: monorepo-4.ruancat6312.top
p5-url-1: monorepo-5.ruancat6312.top
p5-url-2: monorepo5.ruan-cat.com
docs-01-star-url: docs-01-star.ruancat6312.top
eci-url-longest: eslint-config-inspector.ruan-cat-vercel-monorepo-test.ruancat6312.top
eci-url-medium: eci.ruancat-vc-monorepo.ruancat6312.top
eci-url-mini: eci.rc-vc.ruancat6312.top
on:
push:
branches:
# 避免高频率占用vercel资源,改成仅在main分支执行部署行为
# - dev
- main
jobs:
Deploy-Production:
runs-on: ubuntu-latest
steps:
- name: 检出分支
uses: actions/checkout@main
- name: 开启 corepack
run: corepack enable && corepack install
- name: 检查pnpm版本
run: pnpm -v
- name: 安装整个项目的依赖
run: pnpm i
- name: 用npm安装vercel cli工具
run: npm i -g vercel@latest
- name: 检查vercel cli版本
run: vc -v
- name: eci:在连接vercel项目之前,预构建项目目录
run: pnpm run -w eci:b
- name: 各子项目连接现有的vercel项目
# 本地window使用
# run: vc link --yes --cwd=./packages/monorepo-3 --project=vercel-monorepo-test-1-zn20
run: |
vc link --yes --cwd=${{env.p1}} --project=${{env.pjn}} -t ${{env.vct}}
vc link --yes --cwd=${{env.p2}} --project=${{env.pjn}} -t ${{env.vct}}
vc link --yes --cwd=${{env.p3}} --project=${{env.pjn}} -t ${{env.vct}}
vc link --yes --cwd=${{env.p4}} --project=${{env.pjn}} -t ${{env.vct}}
vc link --yes --cwd=${{env.p5}} --project=${{env.pjn}} -t ${{env.vct}}
vc link --yes --cwd=${{env.docs01Star}} --project=${{env.pjn}} -t ${{env.vct}}
vc link --yes --cwd=${{env.eci}} --project=${{env.pjn}} -t ${{env.vct}}
- name: vercel生成特定.vercel/output/static目录
# build命令仍然需要用token来运行。
# run: vc build --yes --prod --cwd=./packages/monorepo-3 -A ./vercel.null.json
run: |
vc build --yes --prod --cwd=${{env.p1}} -A ./vercel.null.json -t ${{env.vct}}
vc build --yes --prod --cwd=${{env.p2}} -A ./vercel.null.json -t ${{env.vct}}
vc build --yes --prod --cwd=${{env.p3}} -A ./vercel.null.json -t ${{env.vct}}
vc build --yes --prod --cwd=${{env.p4}} -A ./vercel.null.json -t ${{env.vct}}
vc build --yes --prod --cwd=${{env.p5}} -A ./vercel.null.json -t ${{env.vct}}
vc build --yes --prod --cwd=${{env.docs01Star}} -A ./vercel.null.json -t ${{env.vct}}
# eci项目的目录不是固定的目录,是动态生成的目录,所以构建vercel目录的命令应该在其构建之后
# vc build --yes --prod --cwd=${{env.eci}} -A ./vercel.null.json -t ${{env.vct}}
- name: turbo并发打包全部子项目
run: pnpm run on-github-action-flow
- name: eci:生成vercel静态站点目录结构
run: vc build --yes --prod --cwd=${{env.eci}} -A ./vercel.null.json -t ${{env.vct}}
- name: 各子项目上传文件并部署到vercel内
run: |
url1="$(vc deploy --yes --prebuilt --prod --cwd=${{env.p1}} -t ${{env.vct}})"
vc alias -t ${{env.vct}} set "$url1" ${{env.p1-url}}
url2="$(vc deploy --yes --prebuilt --prod --cwd=${{env.p2}} -t ${{env.vct}})"
vc alias -t ${{env.vct}} set "$url2" ${{env.p2-url-1}}
vc alias -t ${{env.vct}} set "$url2" ${{env.p2-url-2}}
vc alias -t ${{env.vct}} set "$url2" ${{env.p2-url-3}}
url3="$(vc deploy --yes --prebuilt --prod --cwd=${{env.p3}} -t ${{env.vct}})"
vc alias -t ${{env.vct}} set "$url3" ${{env.p3-url}}
url4="$(vc deploy --yes --prebuilt --prod --cwd=${{env.p4}} -t ${{env.vct}})"
vc alias -t ${{env.vct}} set "$url4" ${{env.p4-url}}
url5="$(vc deploy --yes --prebuilt --prod --cwd=${{env.p5}} -t ${{env.vct}})"
vc alias -t ${{env.vct}} set "$url5" ${{env.p5-url-1}}
vc alias -t ${{env.vct}} set "$url5" ${{env.p5-url-2}}
url01Star="$(vc deploy --yes --prebuilt --prod --cwd=${{env.docs01Star}} -t ${{env.vct}})"
vc alias -t ${{env.vct}} set "$url01Star" ${{env.docs-01-star-url}}
urlEci="$(vc deploy --yes --prebuilt --prod --cwd=${{env.eci}} -t ${{env.vct}})"
vc alias -t ${{env.vct}} set "$urlEci" ${{env.eci-url-longest}}
vc alias -t ${{env.vct}} set "$urlEci" ${{env.eci-url-medium}}
vc alias -t ${{env.vct}} set "$urlEci" ${{env.eci-url-mini}}