-
Notifications
You must be signed in to change notification settings - Fork 9
160 lines (140 loc) · 5.15 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Deploy Docs
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true
on:
push:
tags:
- v*
workflow_dispatch:
jobs:
check-docs:
uses: ./.github/workflows/check_docs.yaml
secrets: inherit
deploy:
runs-on: ubuntu-20.04
if: github.repository_owner == 'datalayers-io'
needs: check-docs
strategy:
matrix:
docs_language: [zh, en]
steps:
- name: clone docs
uses: actions/checkout@main
with:
fetch-depth: 0
path: docs-files
- name: clone frontend
uses: actions/checkout@main
with:
repository: "datalayers-io/docs-datalayers-frontend"
token: ${{ secrets.DATALAYERS_GIT_CI_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: set env
run: |
BRANCH=$(echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g")
if [ "$BRANCH" = "main" ];then
VERSION="latest"
else
VERSION=$BRANCH
# make short version as directory name
VERSION=$(echo $BRANCH | awk -F. '{print $1"."$2}')
fi
echo "DOCS_BRANCH=$BRANCH" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "DOCS_TYPE=datalayers" >> $GITHUB_ENV
echo "LANGUAGES=${{ matrix.docs_language }}" >> $GITHUB_ENV
- name: remove unused files
run: |
cd docs-files
pip3 install pyyaml
python3 ./gen.py | tee directory.json
python3 .github/scripts/remove_unused.py directory.json $(pwd)
- name: move files
run: |
mkdir -p frontend/docs/${DOCS_TYPE}/${VERSION}/
mkdir -p frontend/docs/public/api/
cp frontend/docs/${LANGUAGES}/index.md frontend/docs/
if [ "${LANGUAGES}" = "en" ]; then
cp -r docs-files/en_US/* frontend/docs/${DOCS_TYPE}/${VERSION}/
else
cp -r docs-files/zh_CN/* frontend/docs/${DOCS_TYPE}/${VERSION}/
fi
cp docs-files/directory.json frontend/docs/.vitepress/config/directory.json
rm -r frontend/docs/en || true
rm -r frontend/docs/zh || true
- name: generate version config
run: |
cd docs-files
# make short tag list
tags=$(git tag)
unique_tags=()
for tag in $tags; do
major_minor=$(echo $tag | awk -F. '{print $1"."$2}')
found=0
for utag in "${unique_tags[@]}"; do
if [ "$utag" == "$major_minor" ]; then
found=1
break
fi
done
if [ $found -eq 0 ]; then
unique_tags+=("$major_minor")
fi
done
# Remove duplicates by converting the array to a set and then back to an array
unique_tags=( $(printf "%s\n" "${unique_tags[@]}" | sort -u) )
echo "${unique_tags[@]}"
python3 .github/scripts/generate_version.py "${unique_tags[@]}" > ../frontend/docs/public/api/${DOCS_TYPE}_versions.json
cat ../frontend/docs/public/api/${DOCS_TYPE}_versions.json
- name: build docs
run: |
cd frontend
pnpm install
pnpm build
- name: upload dist to oss
run: |
cd frontend/docs/.vitepress/
wget -q https://gosspublic.alicdn.com/ossutil/1.7.8/ossutil64
chmod 755 ./ossutil64
if [ "${LANGUAGES}" = "en" ]; then
./ossutil64 config -e https://oss-us-east-1.aliyuncs.com -i ${{ secrets.ALI_OSS_ACCESSKEY_ID }} -k ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }} -L CH
else
./ossutil64 config -e https://oss-cn-shanghai.aliyuncs.com -i ${{ secrets.ALI_OSS_ACCESSKEY_ID }} -k ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }} -L CH
fi
oss_bucket=datalayers-docs-${LANGUAGES}
./ossutil64 cp -r -f dist/ oss://${oss_bucket}/
- name: refresh zh cdn
if: matrix.docs_language == 'zh'
uses: Swilder-M/refresh-huawei-cdn@master
with:
access_key_id: ${{ secrets.HUAWEI_ACCESS_KEY_ID }}
access_key_secret: ${{ secrets.HUAWEI_ACCESS_KEY_SECRET }}
file_paths: https://docs.datalayers.cn/
- name: refresh en cdn
if: matrix.docs_language == 'en'
uses: Swilder-M/refresh-ali-cdn@master
with:
access_key_id: ${{ secrets.ALI_OSS_ACCESSKEY_ID }}
access_key_secret: ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }}
file_paths: https://docs.datalayers.io/
- name: update search index
uses: Swilder-M/docsearch-scraper-simple@next
env:
APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
with:
docs_type: datalayers-docs-${{ matrix.docs_language }}
docs_version: ${{ env.VERSION }}