-
Notifications
You must be signed in to change notification settings - Fork 64
143 lines (126 loc) · 4.6 KB
/
deploy-docs.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
name: Deploy Docs
on:
workflow_dispatch:
inputs:
tag:
required: true
type: string
release:
types:
- published
jobs:
prepare:
outputs:
tags: ${{ steps.tags.outputs.tags}}
runs-on: ubuntu-20.04
if: ${{ !github.event.release.prerelease }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: get_tags
id: tags
run: |
ref=$(git describe --tags --abbrev=0)
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
ref="${{ inputs.tag }}"
fi
if [ "${{ github.event_name }}" = "release" ]; then
ref="${{ github.event.release.tag_name }}"
fi
latest_tag="$(curl --silent --show-error \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ github.token }}" \
https://api.github.com/repos/emqx/emqx-operator/releases/latest \
| jq '.tag_name' | tr -d '"')"
if [ "$latest_tag" = "$ref" ];then
tag=("$ref" "latest")
else
tag=("$ref")
fi
tags=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${tag[@]}")
echo "tags=$tags" >> $GITHUB_OUTPUT
deploy:
needs: prepare
strategy:
fail-fast: false
matrix:
tags: ${{ fromJSON(needs.prepare.outputs.tags) }}
runs-on: ubuntu-20.04
if: github.repository_owner == 'emqx'
steps:
- name: clone docs
uses: actions/checkout@v3
with:
fetch-depth: 0
path: docs-files
- name: clone frontend
uses: actions/checkout@v3
with:
repository: 'emqx/docs-emqx-com-frontend'
ref: next
token: ${{ secrets.CI_GIT_TOKEN }}
path: frontend
- name: use node.js
uses: actions/setup-node@v1
with:
node-version: 16
- name: use pnpm
uses: pnpm/action-setup@v2
with:
version: 8.5.1
- name: use python
uses: actions/setup-python@v2
with:
python-version: '3.8'
architecture: 'x64'
- name: set env
run: |
echo "VERSION=${{ matrix.tags }}" >> $GITHUB_ENV
echo "DOCS_TYPE=emqx-operator" >> $GITHUB_ENV
- name: remove unused files
run: |
cd docs-files
python3 .github/scripts/remove_unused.py $(pwd)/docs
- name: move files
run: |
rm frontend/docs/en/index.md || true
rm frontend/docs/zh/index.md || true
rm frontend/docs/*.md || true
rm frontend/index.md || true
mkdir -p frontend/docs/en/${DOCS_TYPE}/${VERSION}/
mkdir -p frontend/docs/zh/${DOCS_TYPE}/${VERSION}/
mkdir -p frontend/docs/public/api/
cp -r docs-files/docs/en_US/* frontend/docs/en/${DOCS_TYPE}/${VERSION}/
cp -r docs-files/docs/zh_CN/* frontend/docs/zh/${DOCS_TYPE}/${VERSION}/
cp docs-files/docs/directory.json frontend/docs/.vitepress/config/directory.json
cd docs-files && git tag -l | egrep "^[1-9]+\.[0-9]+\.[0-9]+$" | jq -R -s -c 'split("\n")[:-1] | . += ["latest"] | reverse' > ../frontend/docs/public/api/${DOCS_TYPE}_versions.json
- name: build docs
run: |
cd frontend
pnpm install
pnpm build
- name: upload dist
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: flush cdn
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
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 search index
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 }}