Merge pull request #22 from QQDQ/main #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Docs | |
concurrency: | |
group: ${{ github.ref_name }} | |
cancel-in-progress: true | |
on: | |
push: | |
tags: | |
- v* | |
branches: | |
- main | |
jobs: | |
deploy: | |
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@v3 | |
with: | |
node-version-file: 'frontend/.nvmrc' | |
- name: use pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: use python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.8' | |
architecture: 'x64' | |
- name: install python dependencies | |
run: | | |
cd docs-files | |
pip3 install requests | |
- 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 | |
fi | |
echo "DOCS_BRANCH=$BRANCH" >> $GITHUB_ENV | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "DOCS_TYPE=neuronex" >> $GITHUB_ENV | |
- name: sync neuron docs | |
run: | | |
cd docs-files | |
python3 .github/scripts/sync_neuron.py $(pwd) | |
# - name: remove unused files | |
# run: | | |
# cd docs-files | |
# python3 .github/scripts/remove_unused.py $(pwd) | |
- 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/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.json frontend/docs/.vitepress/config/directory.json | |
- name: generate version config | |
run: | | |
cd docs-files | |
python3 .github/scripts/generate_version.py $(git tag | egrep "v[0-9](\.[0-9])*$" | xargs echo -n) > ../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: build redoc | |
run: | | |
cd frontend | |
yarn global add redoc-cli | |
LANGS=(zh en) | |
for lang in "${LANGS[@]}"; do | |
redoc-cli bundle redoc/api-swagger-${lang}.json -t redoc/template.hbs \ | |
--output docs/.vitepress/dist/${lang}/neuronex/${VERSION}/api/api-docs.html \ | |
--options.theme.colors.primary.main=#00b173 \ | |
--options.theme.typography.headings.fontFamily='Roboto, sans-serif' \ | |
--options.hide-hostname --templateOptions.title "NeuronEX ${VERSION} API Documentation" \ | |
--templateOptions.description "NeuronEX ${VERSION} API Documentation" \ | |
--templateOptions.version "${VERSION}" \ | |
--templateOptions.neuronex \ | |
$(if [ "${lang}" == "zh" ]; then echo "--templateOptions.langZH \"zh\""; fi) | |
done | |
- 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 }} |