-
Notifications
You must be signed in to change notification settings - Fork 3
203 lines (178 loc) · 5.89 KB
/
CD.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
## CD交付流水线
## - 部署到Github Pages
## - 部署到Vercel托管平台
## - 发布新的Github Release
## 参考资料:https://v2.vuepress.vuejs.org/zh/guide/deployment.html#github-pages
name: CD
on:
push:
branches:
- master
- next
workflow_dispatch:
## vercel 环境变量
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
# 阿里云仓库信息
REGISTRY: registry.cn-hangzhou.aliyuncs.com
UserName: mmdapl
jobs:
install-init:
name: "流水线初始化"
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16.20.2
cache: 'pnpm'
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
## 部署到Github-Pages
deploy-github:
name: "部署到Github-Pages"
needs: install-init
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Restore Dependencies From cache
uses: actions/cache@v3
with:
path: |
node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
# 运行构建脚本
- name: Build VuePress Site
run: ./scripts/bundle build_proxy
- name: Deploy To GitHub Page
uses: crazy-max/ghaction-github-pages@v3
with:
target_branch: pages/github
build_dir: docs/.vuepress/dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
## 部署到vercel平台
# deploy-vercel:
# name: "部署到Vercel平台"
# needs: install-init
# runs-on: ubuntu-latest
# if: github.repository == '142vip/JavaScriptCollection'
# steps:
# - name: Checkout Code
# uses: actions/checkout@v3
# with:
# fetch-depth: 0
#
# - name: Restore Dependencies From Cache
# uses: actions/cache@v3
# with:
# path: |
# node_modules
# key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
#
# - name: Pull Vercel Environment Information
# run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
#
# ## 注意:安装pnpm
# - name: Build Project Artifacts
# run: npm i pnpm@7 -g && vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
#
# - name: Deploy Project Artifacts to Vercel
# run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
## 版本发布
release:
name: "创建Github发布"
runs-on: ubuntu-latest
needs: install-init
## 主库master、next且执行release更新时执行
if: github.repository == '142vip/JavaScriptCollection' && startsWith(github.event.head_commit.message, 'chore(release):')
steps:
- name: Restore Dependencies From cache
uses: actions/cache@v3
with:
path: |
node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
### 打成压缩包
- name: Create Zip Package
run: |
zip -r JavaScriptCollection.zip . \
-x "node_modules/*" \
-x ".git/*"
# 提取版本号
- name: Get New Version Number
id: extract_version
run: echo "::set-output name=version::$(node -p "require('./package.json').version")"
# 创建发布版本
- name: Create New Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.extract_version.outputs.version }}
release_name: v${{ steps.extract_version.outputs.version }}
body: |
Release ${{ steps.extract_version.outputs.version }}
### Features
### Bug Fixes
## 更新资源
- name: Upload Resource Assets
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./JavaScriptCollection.zip
asset_name: JavaScriptCollection.zip
asset_content_type: application/zip
# Deploy-ESC:
# name: "部署到ESC服务器"
# needs: install-init
# runs-on: ubuntu-latest
# ## 主库master、next且执行release更新时执行
# if: github.repository == '142vip/JavaScriptCollection' && startsWith(github.event.head_commit.message, 'chore(release):')
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
#
# - name: Get Current Version
# id: version
# uses: ashley-taylor/[email protected]
# with:
# path: ./package.json
# property: version
#
# # 拉取镜像,更新服务
# - name: Pull Image And Update ESC
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.SERVER_HOST }}
# port: ${{ secrets.SERVER_PORT }}
# username: ${{ secrets.SERVER_USERNAME }}
# password: ${{ secrets.SERVER_PASSWORD }}
# script: |
# docker images
# echo "-----------正在运行的服务--------"
# docker ps
# cd /service_env/ && git reset --hard && git pull origin main
# bash ./scripts/book_doc.deploy.sh jsc ${{steps.version.outputs.value}}