|
| 1 | +name: Deploy Docs Legacy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + |
| 8 | +jobs: |
| 9 | + prepare: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + versions: ${{ steps.set_environment.outputs.versions }} |
| 13 | + docs_types: ${{ steps.set_environment.outputs.docs_types }} |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@main |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + - name: set_environment |
| 19 | + id: set_environment |
| 20 | + run: | |
| 21 | + current_branch=$(echo ${{ github.ref_name }}) |
| 22 | + current_version=$(echo ${{ github.ref_name }} | sed -r "s/^(.*)-.*$/\1/") |
| 23 | + current_version=${current_version/e/v} |
| 24 | + if [[ $current_branch == v* ]]; |
| 25 | + then |
| 26 | + tag_list=$(git tag | egrep "^v.*$" | xargs echo -n) |
| 27 | + docs_types='["broker"]' |
| 28 | + else |
| 29 | + tag_list=$(git tag | egrep "^e.*$" | xargs echo -n) |
| 30 | + docs_types='["enterprise"]' |
| 31 | + fi |
| 32 | + latest_version=$(python3 .github/scripts/generate_version.py $tag_list | jq -r '.[0]') |
| 33 | + if [[ $current_version == $latest_version ]]; |
| 34 | + then |
| 35 | + build_version_list='["'latest'","'$current_version'"]' |
| 36 | + else |
| 37 | + build_version_list='["'$current_version'"]' |
| 38 | + fi |
| 39 | + echo "versions=$build_version_list" >> $GITHUB_OUTPUT |
| 40 | + echo "docs_types=$docs_types" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + deploy: |
| 43 | + needs: prepare |
| 44 | + strategy: |
| 45 | + matrix: |
| 46 | + version: ${{ fromJSON(needs.prepare.outputs.versions) }} |
| 47 | + docs_type: ${{ fromJSON(needs.prepare.outputs.docs_types) }} |
| 48 | + runs-on: ubuntu-latest |
| 49 | + steps: |
| 50 | + - name: clone docs |
| 51 | + uses: actions/checkout@main |
| 52 | + with: |
| 53 | + fetch-depth: 0 |
| 54 | + path: docs-files |
| 55 | + |
| 56 | + - name: set env |
| 57 | + run: | |
| 58 | + echo "DOCS_TYPE=${{ matrix.docs_type }}" >> $GITHUB_ENV |
| 59 | + echo "DOCS_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV |
| 60 | + echo "VERSION=${{ matrix.version }}" >> $GITHUB_ENV |
| 61 | +
|
| 62 | + - name: clone ce frontend |
| 63 | + if: matrix.docs_type == 'broker' |
| 64 | + uses: actions/checkout@main |
| 65 | + with: |
| 66 | + repository: 'emqx/emqx-io-docs-frontend' |
| 67 | + ref: next |
| 68 | + token: ${{ secrets.CI_GIT_TOKEN }} |
| 69 | + path: frontend |
| 70 | + |
| 71 | + - name: clone ee frontend |
| 72 | + if: matrix.docs_type == 'enterprise' |
| 73 | + uses: actions/checkout@main |
| 74 | + with: |
| 75 | + repository: 'emqx/docs-emqx-com-frontend' |
| 76 | + ref: next |
| 77 | + token: ${{ secrets.CI_GIT_TOKEN }} |
| 78 | + path: frontend |
| 79 | + |
| 80 | + - name: use python |
| 81 | + uses: actions/setup-python@v4 |
| 82 | + with: |
| 83 | + python-version: 3.8 |
| 84 | + |
| 85 | + - name: use node.js |
| 86 | + uses: actions/setup-node@v3 |
| 87 | + with: |
| 88 | + node-version-file: 'frontend/.nvmrc' |
| 89 | + |
| 90 | + - name: use pnpm |
| 91 | + uses: pnpm/action-setup@v2 |
| 92 | + with: |
| 93 | + version: 8 |
| 94 | + |
| 95 | + - name: generate directory.json |
| 96 | + run: | |
| 97 | + cd docs-files |
| 98 | + pip3 install pyyaml |
| 99 | + if [[ $DOCS_TYPE == "broker" ]]; |
| 100 | + then |
| 101 | + ./gen.py ce | tee directory.json |
| 102 | + else |
| 103 | + ./gen.py ee | tee directory_ee.json |
| 104 | + fi |
| 105 | +
|
| 106 | + - name: remove unused files |
| 107 | + run: | |
| 108 | + cd docs-files |
| 109 | + if [[ $DOCS_TYPE == "broker" ]]; |
| 110 | + then |
| 111 | + python3 .github/scripts/remove_unused.py directory.json $(pwd) |
| 112 | + else |
| 113 | + python3 .github/scripts/remove_unused.py directory_ee.json $(pwd) |
| 114 | + fi |
| 115 | +
|
| 116 | + - name: set current emqx version |
| 117 | + run: | |
| 118 | + cd docs-files |
| 119 | + source current-version.env |
| 120 | + find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@CE_VERSION@/'"$CE_VERSION"'/g' {} + |
| 121 | + find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@EE_VERSION@/'"$EE_VERSION"'/g' {} + |
| 122 | + find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@CE_MINOR_VERSION@/'"$CE_MINOR_VERSION"'/g' {} + |
| 123 | + find ./en_US ./zh_CN -type f -name "*.md" -exec sed -i 's/@EE_MINOR_VERSION@/'"$EE_MINOR_VERSION"'/g' {} + |
| 124 | +
|
| 125 | +
|
| 126 | + - name: move ce files |
| 127 | + if: matrix.docs_type == 'broker' |
| 128 | + run: | |
| 129 | + rm frontend/docs/*.md || true |
| 130 | + rm frontend/README.md || true |
| 131 | + mkdir -p frontend/docs/en/${VERSION}/ |
| 132 | + mkdir -p frontend/docs/zh/${VERSION}/ |
| 133 | + mkdir -p frontend/docs/public/api/ |
| 134 | + mkdir -p frontend/redoc/ |
| 135 | + cp -r docs-files/en_US/* frontend/docs/en/${VERSION}/ |
| 136 | + cp -r docs-files/zh_CN/* frontend/docs/zh/${VERSION}/ |
| 137 | + cp -r docs-files/redocly/*.json frontend/redoc/ |
| 138 | + cp docs-files/directory.json frontend/docs/.vitepress/config/directory.json |
| 139 | +
|
| 140 | + - name: move ee files |
| 141 | + if: matrix.docs_type == 'enterprise' |
| 142 | + run: | |
| 143 | + rm frontend/docs/en/index.md || true |
| 144 | + rm frontend/docs/zh/index.md || true |
| 145 | + rm frontend/docs/*.md || true |
| 146 | + rm frontend/README.md || true |
| 147 | + mkdir -p frontend/docs/en/${DOCS_TYPE}/${VERSION}/ |
| 148 | + mkdir -p frontend/docs/zh/${DOCS_TYPE}/${VERSION}/ |
| 149 | + mkdir -p frontend/docs/public/api/ |
| 150 | + mkdir -p frontend/redoc/ |
| 151 | + cp -r docs-files/en_US/* frontend/docs/en/${DOCS_TYPE}/${VERSION}/ |
| 152 | + cp -r docs-files/zh_CN/* frontend/docs/zh/${DOCS_TYPE}/${VERSION}/ |
| 153 | + cp -r docs-files/redocly/*.json frontend/redoc/ |
| 154 | + cp docs-files/directory_ee.json frontend/docs/.vitepress/config/directory.json |
| 155 | +
|
| 156 | + - name: generate version config |
| 157 | + run: | |
| 158 | + cd docs-files |
| 159 | + if [[ $DOCS_TYPE == "broker" ]]; |
| 160 | + then |
| 161 | + version_list=$(git tag | egrep "^v.*$" | xargs echo -n) |
| 162 | + else |
| 163 | + version_list=$(git tag | egrep "^e.*$" | xargs echo -n) |
| 164 | + fi |
| 165 | + python3 .github/scripts/generate_version.py $version_list > ../frontend/docs/public/api/${DOCS_TYPE}_versions.json |
| 166 | +
|
| 167 | + - name: setup hocon |
| 168 | + run: | |
| 169 | + echo "HOCON=true" >> $GITHUB_ENV |
| 170 | + if [[ $DOCS_TYPE == "broker" ]]; |
| 171 | + then |
| 172 | + cp -r docs-files/hocon/ce/*.json frontend/docs/public/api/ |
| 173 | + online_versions=$(curl -s https://www.emqx.io/docs/api/broker_hocon_versions.json) |
| 174 | + else |
| 175 | + cp -r docs-files/hocon/ee/*.json frontend/docs/public/api/ |
| 176 | + online_versions=$(curl -s https://docs.emqx.com/api/${DOCS_TYPE}_hocon_versions.json) |
| 177 | + fi |
| 178 | +
|
| 179 | + if [ $? -eq 0 ]; then |
| 180 | + online_versions=$(echo $online_versions | jq -r '.'[]) |
| 181 | + else |
| 182 | + online_versions="" |
| 183 | + fi |
| 184 | +
|
| 185 | + local_versions=$(ls frontend/docs/public/api/hocon-*-*on | sed -E 's_.*/hocon-(.*)-(en|zh).json_\1_g' | uniq) |
| 186 | + all_versions=$(echo -e "$online_versions\n$local_versions" | sort -u | awk NF | uniq) |
| 187 | + all_versions=$(echo "$all_versions" | sort -rV) |
| 188 | + jq -nR '[inputs]' <<< "$all_versions" > frontend/docs/public/api/${DOCS_TYPE}_hocon_versions.json |
| 189 | + cat frontend/docs/public/api/${DOCS_TYPE}_hocon_versions.json |
| 190 | +
|
| 191 | + - name: build docs |
| 192 | + run: | |
| 193 | + cd frontend |
| 194 | + export NODE_OPTIONS=--max_old_space_size=4096 |
| 195 | + pnpm install |
| 196 | + pnpm build |
| 197 | +
|
| 198 | + - name: build ce redoc |
| 199 | + if: matrix.docs_type == 'broker' |
| 200 | + run: | |
| 201 | + cd frontend |
| 202 | + yarn global add redoc-cli |
| 203 | + LANGS=(zh en) |
| 204 | + for lang in "${LANGS[@]}"; do |
| 205 | + redoc-cli bundle redoc/ce-${lang}.json -t redoc/template.hbs \ |
| 206 | + --output docs/.vitepress/dist/${lang}/${VERSION}/admin/api-docs.html \ |
| 207 | + --options.theme.colors.primary.main=#00b173 \ |
| 208 | + --options.theme.typography.headings.fontFamily='Roboto, sans-serif' \ |
| 209 | + --options.hide-hostname --templateOptions.title "EMQX ${VERSION} API Documentation" \ |
| 210 | + --templateOptions.description "EMQX ${VERSION} API Documentation" \ |
| 211 | + --templateOptions.version "${VERSION}" \ |
| 212 | + $(if [ "${lang}" == "zh" ]; then echo "--templateOptions.langZH \"zh\""; fi) |
| 213 | + done |
| 214 | +
|
| 215 | + - name: build ee redoc |
| 216 | + if: matrix.docs_type == 'enterprise' |
| 217 | + run: | |
| 218 | + cd frontend |
| 219 | + yarn global add redoc-cli |
| 220 | + LANGS=(zh en) |
| 221 | + for lang in "${LANGS[@]}"; do |
| 222 | + redoc-cli bundle redoc/ee-${lang}.json -t redoc/template.hbs \ |
| 223 | + --output docs/.vitepress/dist/${lang}/enterprise/${VERSION}/admin/api-docs.html \ |
| 224 | + --options.theme.colors.primary.main=#5e4eff \ |
| 225 | + --options.theme.typography.headings.fontFamily='Roboto, sans-serif' \ |
| 226 | + --options.hide-hostname --templateOptions.title "EMQX Enterprise ${VERSION} API Documentation" \ |
| 227 | + --templateOptions.description "EMQX Enterprise ${VERSION} API Documentation" \ |
| 228 | + --templateOptions.version "${VERSION}" \ |
| 229 | + $(if [ "${lang}" == "zh" ]; then echo "--templateOptions.langZH \"zh\""; fi) |
| 230 | + done |
| 231 | +
|
| 232 | + - name: upload ce files |
| 233 | + if: matrix.docs_type == 'broker' |
| 234 | + run: | |
| 235 | + cd frontend/docs/.vitepress/ |
| 236 | + wget https://gosspublic.alicdn.com/ossutil/1.7.8/ossutil64 |
| 237 | + chmod 755 ./ossutil64 |
| 238 | + ./ossutil64 config -e https://oss-accelerate.aliyuncs.com -i ${{ secrets.ALI_OSS_ACCESSKEY_ID }} -k ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }} -L CH |
| 239 | + ./ossutil64 rm -r -f oss://emqx-io-docs/docs/zh/${VERSION}/ || true |
| 240 | + ./ossutil64 rm -r -f oss://emqx-io-docs/docs/en/${VERSION}/ || true |
| 241 | + ./ossutil64 cp -r -f dist/ oss://emqx-io-docs/docs/ |
| 242 | +
|
| 243 | + - name: set aws credentials |
| 244 | + uses: aws-actions/configure-aws-credentials@v4 |
| 245 | + if: matrix.docs_type == 'enterprise' |
| 246 | + with: |
| 247 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 248 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 249 | + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} |
| 250 | + |
| 251 | + - name: upload ee file to aws s3 |
| 252 | + if: matrix.docs_type == 'enterprise' |
| 253 | + run: | |
| 254 | + aws s3 rm --recursive s3://docs-emqx-com/zh/${DOCS_TYPE}/${VERSION} || true |
| 255 | + aws s3 rm --recursive s3://docs-emqx-com/en/${DOCS_TYPE}/${VERSION} || true |
| 256 | + aws s3 cp --recursive frontend/docs/.vitepress/dist/ s3://docs-emqx-com/ |
| 257 | + 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" |
| 258 | +
|
| 259 | + - name: upload ee file to tencent cos |
| 260 | + if: matrix.docs_type == 'enterprise' |
| 261 | + run: | |
| 262 | + pip3 install coscmd |
| 263 | + coscmd config -a ${{ secrets.TENCENT_COS_ID }} -s ${{ secrets.TENCENT_COS_KEY }} -b docs-1302406139 -r ap-shanghai |
| 264 | + coscmd delete -r -f en/${DOCS_TYPE}/${VERSION} || true |
| 265 | + coscmd delete -r -f zh/${DOCS_TYPE}/${VERSION} || true |
| 266 | + coscmd config -a ${{ secrets.TENCENT_COS_ID }} -s ${{ secrets.TENCENT_COS_KEY }} -b docs-1302406139 -e cos.accelerate.myqcloud.com |
| 267 | + coscmd upload -r frontend/docs/.vitepress/dist/ / |
| 268 | +
|
| 269 | + - name: set tccli |
| 270 | + run: | |
| 271 | + pip3 install tccli |
| 272 | + tccli configure set secretId ${{ secrets.TENCENT_COS_ID }} |
| 273 | + tccli configure set secretKey ${{ secrets.TENCENT_COS_KEY }} |
| 274 | + tccli configure set region ap-shanghai |
| 275 | +
|
| 276 | + - name: flush ce cdn |
| 277 | + if: matrix.docs_type == 'broker' |
| 278 | + run: | |
| 279 | + tccli cdn PurgePathCache --cli-unfold-argument --Paths https://emqxio-docs.emqx.net/ --FlushType delete |
| 280 | +
|
| 281 | + - name: flush ee cdn |
| 282 | + if: matrix.docs_type == 'enterprise' |
| 283 | + run: | |
| 284 | + 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 |
| 285 | + 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 |
| 286 | +
|
| 287 | + - name: update ce search index |
| 288 | + if: matrix.docs_type == 'broker' |
| 289 | + uses: Swilder-M/docsearch-scraper-simple@next |
| 290 | + env: |
| 291 | + APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID_CE }} |
| 292 | + API_KEY: ${{ secrets.ALGOLIA_API_KEY_CE }} |
| 293 | + with: |
| 294 | + docs_type: ${{ env.DOCS_TYPE }} |
| 295 | + docs_version: ${{ env.VERSION }} |
| 296 | + |
| 297 | + - name: update ee search index |
| 298 | + if: matrix.docs_type == 'enterprise' |
| 299 | + uses: Swilder-M/docsearch-scraper-simple@next |
| 300 | + env: |
| 301 | + APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID_NEXT }} |
| 302 | + API_KEY: ${{ secrets.ALGOLIA_API_KEY_NEXT }} |
| 303 | + with: |
| 304 | + docs_type: ${{ env.DOCS_TYPE }} |
| 305 | + docs_version: ${{ env.VERSION }} |
0 commit comments