-
Notifications
You must be signed in to change notification settings - Fork 264
/
deploy_docs_legacy.yaml
305 lines (274 loc) · 11.8 KB
/
deploy_docs_legacy.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: Deploy Docs Legacy
on:
push:
tags:
- v*
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.set_environment.outputs.versions }}
docs_types: ${{ steps.set_environment.outputs.docs_types }}
steps:
- uses: actions/checkout@main
with:
fetch-depth: 0
- name: set_environment
id: set_environment
run: |
current_branch=$(echo ${{ github.ref_name }})
current_version=$(echo ${{ github.ref_name }} | sed -r "s/^(.*)-.*$/\1/")
current_version=${current_version/e/v}
if [[ $current_branch == v* ]];
then
tag_list=$(git tag | egrep "^v.*$" | xargs echo -n)
docs_types='["broker"]'
else
tag_list=$(git tag | egrep "^e.*$" | xargs echo -n)
docs_types='["enterprise"]'
fi
latest_version=$(python3 .github/scripts/generate_version.py $tag_list | jq -r '.[0]')
if [[ $current_version == $latest_version ]];
then
build_version_list='["'latest'","'$current_version'"]'
else
build_version_list='["'$current_version'"]'
fi
echo "versions=$build_version_list" >> $GITHUB_OUTPUT
echo "docs_types=$docs_types" >> $GITHUB_OUTPUT
deploy:
needs: prepare
strategy:
matrix:
version: ${{ fromJSON(needs.prepare.outputs.versions) }}
docs_type: ${{ fromJSON(needs.prepare.outputs.docs_types) }}
runs-on: ubuntu-latest
steps:
- name: clone docs
uses: actions/checkout@main
with:
fetch-depth: 0
path: docs-files
- name: set env
run: |
echo "DOCS_TYPE=${{ matrix.docs_type }}" >> $GITHUB_ENV
echo "DOCS_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
echo "VERSION=${{ matrix.version }}" >> $GITHUB_ENV
- name: clone ce frontend
if: matrix.docs_type == 'broker'
uses: actions/checkout@main
with:
repository: 'emqx/emqx-io-docs-frontend'
ref: next
token: ${{ secrets.CI_GIT_TOKEN }}
path: frontend
- name: clone ee frontend
if: matrix.docs_type == 'enterprise'
uses: actions/checkout@main
with:
repository: 'emqx/docs-emqx-com-frontend'
ref: next
token: ${{ secrets.CI_GIT_TOKEN }}
path: frontend
- name: use python
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: use node.js
uses: actions/setup-node@v3
with:
node-version-file: 'frontend/.nvmrc'
- name: use pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: generate directory.json
run: |
cd docs-files
pip3 install pyyaml
if [[ $DOCS_TYPE == "broker" ]];
then
./gen.py ce | tee directory.json
else
./gen.py ee | tee directory_ee.json
fi
- name: remove unused files
run: |
cd docs-files
if [[ $DOCS_TYPE == "broker" ]];
then
python3 .github/scripts/remove_unused.py directory.json $(pwd)
else
python3 .github/scripts/remove_unused.py directory_ee.json $(pwd)
fi
- name: set current emqx version
run: |
cd docs-files
source current-version.env
find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@CE_VERSION@/'"$CE_VERSION"'/g' {} +
find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@EE_VERSION@/'"$EE_VERSION"'/g' {} +
find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@CE_MINOR_VERSION@/'"$CE_MINOR_VERSION"'/g' {} +
find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@EE_MINOR_VERSION@/'"$EE_MINOR_VERSION"'/g' {} +
- name: move ce files
if: matrix.docs_type == 'broker'
run: |
rm frontend/docs/*.md || true
rm frontend/README.md || true
mkdir -p frontend/docs/en/${VERSION}/
mkdir -p frontend/docs/zh/${VERSION}/
mkdir -p frontend/docs/public/api/
mkdir -p frontend/redoc/
cp -r docs-files/en_US/* frontend/docs/en/${VERSION}/
cp -r docs-files/zh_CN/* frontend/docs/zh/${VERSION}/
cp -r docs-files/redocly/*.json frontend/redoc/
cp docs-files/directory.json frontend/docs/.vitepress/config/directory.json
- name: move ee files
if: matrix.docs_type == 'enterprise'
run: |
rm frontend/docs/en/index.md || true
rm frontend/docs/zh/index.md || true
rm frontend/docs/*.md || true
rm frontend/README.md || true
mkdir -p frontend/docs/en/${DOCS_TYPE}/${VERSION}/
mkdir -p frontend/docs/zh/${DOCS_TYPE}/${VERSION}/
mkdir -p frontend/docs/public/api/
mkdir -p frontend/redoc/
cp -r docs-files/en_US/* frontend/docs/en/${DOCS_TYPE}/${VERSION}/
cp -r docs-files/zh_CN/* frontend/docs/zh/${DOCS_TYPE}/${VERSION}/
cp -r docs-files/redocly/*.json frontend/redoc/
cp docs-files/directory_ee.json frontend/docs/.vitepress/config/directory.json
- name: generate version config
run: |
cd docs-files
if [[ $DOCS_TYPE == "broker" ]];
then
version_list=$(git tag | egrep "^v.*$" | xargs echo -n)
else
version_list=$(git tag | egrep "^e.*$" | xargs echo -n)
fi
python3 .github/scripts/generate_version.py $version_list > ../frontend/docs/public/api/${DOCS_TYPE}_versions.json
- name: setup hocon
run: |
echo "HOCON=true" >> $GITHUB_ENV
if [[ $DOCS_TYPE == "broker" ]];
then
cp -r docs-files/hocon/ce/*.json frontend/docs/public/api/
online_versions=$(curl -s https://www.emqx.io/docs/api/broker_hocon_versions.json)
else
cp -r docs-files/hocon/ee/*.json frontend/docs/public/api/
online_versions=$(curl -s https://docs.emqx.com/api/${DOCS_TYPE}_hocon_versions.json)
fi
if [ $? -eq 0 ]; then
online_versions=$(echo $online_versions | jq -r '.'[])
else
online_versions=""
fi
local_versions=$(ls frontend/docs/public/api/hocon-*-*on | sed -E 's_.*/hocon-(.*)-(en|zh).json_\1_g' | uniq)
all_versions=$(echo -e "$online_versions\n$local_versions" | sort -u | awk NF | uniq)
all_versions=$(echo "$all_versions" | sort -rV)
jq -nR '[inputs]' <<< "$all_versions" > frontend/docs/public/api/${DOCS_TYPE}_hocon_versions.json
cat frontend/docs/public/api/${DOCS_TYPE}_hocon_versions.json
- name: build docs
run: |
cd frontend
export NODE_OPTIONS=--max_old_space_size=4096
pnpm install
pnpm build
- name: build ce redoc
if: matrix.docs_type == 'broker'
run: |
cd frontend
yarn global add redoc-cli
LANGS=(zh en)
for lang in "${LANGS[@]}"; do
redoc-cli bundle redoc/ce-${lang}.json -t redoc/template.hbs \
--output docs/.vitepress/dist/${lang}/${VERSION}/admin/api-docs.html \
--options.theme.colors.primary.main=#00b173 \
--options.theme.typography.headings.fontFamily='Roboto, sans-serif' \
--options.hide-hostname --templateOptions.title "EMQX ${VERSION} API Documentation" \
--templateOptions.description "EMQX ${VERSION} API Documentation" \
--templateOptions.version "${VERSION}" \
$(if [ "${lang}" == "zh" ]; then echo "--templateOptions.langZH \"zh\""; fi)
done
- name: build ee redoc
if: matrix.docs_type == 'enterprise'
run: |
cd frontend
yarn global add redoc-cli
LANGS=(zh en)
for lang in "${LANGS[@]}"; do
redoc-cli bundle redoc/ee-${lang}.json -t redoc/template.hbs \
--output docs/.vitepress/dist/${lang}/enterprise/${VERSION}/admin/api-docs.html \
--options.theme.colors.primary.main=#5e4eff \
--options.theme.typography.headings.fontFamily='Roboto, sans-serif' \
--options.hide-hostname --templateOptions.title "EMQX Enterprise ${VERSION} API Documentation" \
--templateOptions.description "EMQX Enterprise ${VERSION} API Documentation" \
--templateOptions.version "${VERSION}" \
$(if [ "${lang}" == "zh" ]; then echo "--templateOptions.langZH \"zh\""; fi)
done
- name: upload ce files
if: matrix.docs_type == 'broker'
run: |
cd frontend/docs/.vitepress/
wget https://gosspublic.alicdn.com/ossutil/1.7.8/ossutil64
chmod 755 ./ossutil64
./ossutil64 config -e https://oss-accelerate.aliyuncs.com -i ${{ secrets.ALI_OSS_ACCESSKEY_ID }} -k ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }} -L CH
./ossutil64 rm -r -f oss://emqx-io-docs/docs/zh/${VERSION}/ || true
./ossutil64 rm -r -f oss://emqx-io-docs/docs/en/${VERSION}/ || true
./ossutil64 cp -r -f dist/ oss://emqx-io-docs/docs/
- name: set aws credentials
uses: aws-actions/configure-aws-credentials@v4
if: matrix.docs_type == 'enterprise'
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: upload ee file to aws s3
if: matrix.docs_type == 'enterprise'
run: |
aws s3 rm --recursive s3://docs-emqx-com/zh/${DOCS_TYPE}/${VERSION} || true
aws s3 rm --recursive s3://docs-emqx-com/en/${DOCS_TYPE}/${VERSION} || true
aws s3 cp --recursive frontend/docs/.vitepress/dist/ s3://docs-emqx-com/
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_DOCS_CLOUDFRONT_ID }} --paths "/zh/${DOCS_TYPE}/${VERSION}/*" "/en/${DOCS_TYPE}/${VERSION}/*" "/api/${DOCS_TYPE}_versions.json" "/sitemap_${DOCS_TYPE}_${VERSION}.xml"
- name: upload ee file to tencent cos
if: matrix.docs_type == 'enterprise'
run: |
pip3 install coscmd
coscmd config -a ${{ secrets.TENCENT_COS_ID }} -s ${{ secrets.TENCENT_COS_KEY }} -b docs-1302406139 -r ap-shanghai
coscmd delete -r -f en/${DOCS_TYPE}/${VERSION} || true
coscmd delete -r -f zh/${DOCS_TYPE}/${VERSION} || true
coscmd config -a ${{ secrets.TENCENT_COS_ID }} -s ${{ secrets.TENCENT_COS_KEY }} -b docs-1302406139 -e cos.accelerate.myqcloud.com
coscmd upload -r frontend/docs/.vitepress/dist/ /
- name: set tccli
run: |
pip3 install tccli
tccli configure set secretId ${{ secrets.TENCENT_COS_ID }}
tccli configure set secretKey ${{ secrets.TENCENT_COS_KEY }}
tccli configure set region ap-shanghai
- name: flush ce cdn
if: matrix.docs_type == 'broker'
run: |
tccli cdn PurgePathCache --cli-unfold-argument --Paths https://emqxio-docs.emqx.net/ --FlushType delete
- name: flush ee cdn
if: matrix.docs_type == 'enterprise'
run: |
tccli cdn PurgePathCache --cli-unfold-argument --Paths https://docs.emqx.com/zh/${DOCS_TYPE}/${VERSION}/ https://docs.emqx.com/en/${DOCS_TYPE}/${VERSION}/ --FlushType delete
tccli cdn PurgeUrlsCache --cli-unfold-argument --Urls https://docs.emqx.com/api/${DOCS_TYPE}_versions.json https://docs.emqx.com/sitemap_${DOCS_TYPE}_${VERSION}.xml
- name: update ce search index
if: matrix.docs_type == 'broker'
uses: Swilder-M/docsearch-scraper-simple@next
env:
APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID_CE }}
API_KEY: ${{ secrets.ALGOLIA_API_KEY_CE }}
with:
docs_type: ${{ env.DOCS_TYPE }}
docs_version: ${{ env.VERSION }}
- name: update ee search index
if: matrix.docs_type == 'enterprise'
uses: Swilder-M/docsearch-scraper-simple@next
env:
APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID_NEXT }}
API_KEY: ${{ secrets.ALGOLIA_API_KEY_NEXT }}
with:
docs_type: ${{ env.DOCS_TYPE }}
docs_version: ${{ env.VERSION }}