123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- name: Deploy Docs
- concurrency:
- group: ${{ github.ref }}
- cancel-in-progress: true
- on:
- push:
- branches:
- - master
- jobs:
- deploy:
- runs-on: ubuntu-20.04
- if: github.repository_owner == 'lf-edge'
- steps:
- - name: clone docs
- uses: actions/checkout@v2
- with:
- fetch-depth: 0
- path: docs-files
- - name: clone frontend
- uses: actions/checkout@v2
- with:
- repository: 'emqx/docs-emqx-com-frontend'
- token: ${{ secrets.CI_GIT_TOKEN }}
- path: frontend
- - name: use node.js
- uses: actions/setup-node@v1
- with:
- node-version: 14.15
- - name: use python
- uses: actions/setup-python@v2
- with:
- python-version: '3.8'
- architecture: 'x64'
- - name: set env
- run: |
- BRANCH=$(echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g")
- if [ "$BRANCH" = "master" ];then
- VERSION="latest"
- else
- VERSION=v$BRANCH
- fi
- echo "DOCS_BRANCH=$BRANCH" >> $GITHUB_ENV
- echo "VERSION=$VERSION" >> $GITHUB_ENV
- echo "DOCS_TYPE=kuiper" >> $GITHUB_ENV
- - name: get last version
- run: |
- cd docs-files
- last_sha_url=https://docs.emqx.com/sha/${DOCS_TYPE}
- if [[ "$VERSION" != "latest" ]];
- then
- is_changed=1
- elif curl -fs $last_sha_url > /dev/null;
- then
- last_sha=$(curl $last_sha_url)
- echo $last_sha;
- if [[ -n $(git diff --name-only "$last_sha"...HEAD -- "docs") ]]
- then
- is_changed=1
- else
- is_changed=0
- fi
- else
- is_changed=1
- fi
- echo "CHANGED=$is_changed" >> $GITHUB_ENV
- - name: remove unused files
- if: ${{ env.CHANGED == '1' }}
- run: |
- cd docs-files
- python3 .ci/remove_unused.py $(pwd)/docs
- - name: move files
- if: ${{ env.CHANGED == '1' }}
- run: |
- rm frontend/docs/en/README.md || true
- rm frontend/docs/zh/README.md || true
- rm frontend/docs/*.md || true
- rm frontend/README.md
- mkdir -p frontend/docs/en/${DOCS_TYPE}/${VERSION}/
- mkdir -p frontend/docs/zh/${DOCS_TYPE}/${VERSION}/
- mkdir -p frontend/docs/.vuepress/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/.vuepress/config/directory.json
- echo "[\"latest\"]" > frontend/docs/.vuepress/public/api/${DOCS_TYPE}_versions.json
- - name: build docs
- if: ${{ env.CHANGED == '1' }}
- run: |
- cd frontend
- yarn && yarn build
- if [[ "$VERSION" == "latest" ]];
- then
- mkdir -p docs/.vuepress/dist/sha/
- touch docs/.vuepress/dist/sha/${DOCS_TYPE}
- echo $GITHUB_SHA >> docs/.vuepress/dist/sha/${DOCS_TYPE}
- fi
- - name: upload dist
- if: ${{ env.CHANGED == '1' }}
- run: |
- pip3 install coscmd
- coscmd config -a ${{ secrets.COS_ID }} -s ${{ secrets.COS_KEY }} -b ${{ secrets.COS_NAME }} -r ${{ secrets.COS_REGION }}
- coscmd delete -r -f en/${DOCS_TYPE}/${VERSION} || true
- coscmd delete -r -f zh/${DOCS_TYPE}/${VERSION} || true
- coscmd config -a ${{ secrets.COS_ID }} -s ${{ secrets.COS_KEY }} -b ${{ secrets.COS_NAME }} -e cos.accelerate.myqcloud.com
- cd frontend/docs/.vuepress/dist/
- zip -rq docs-dist-${DOCS_TYPE}-${VERSION}.zip ./
- coscmd upload docs-dist-${DOCS_TYPE}-${VERSION}.zip docs-zip/
- sleep 90
- - name: flush CDN
- if: ${{ env.CHANGED == '1' }}
- run: |
- pip3 install tccli
- tccli configure set secretId ${{ secrets.COS_ID }}
- tccli configure set secretKey ${{ secrets.COS_KEY }}
- tccli configure set region ${{ secrets.COS_REGION }}
- tccli cdn PurgePathCache --cli-unfold-argument --Paths https://docs.emqx.com/zh/${DOCS_TYPE}/${VERSION}/ https://docs.emqx.com/en/${DOCS_TYPE}/${VERSION}/ https://docs.emqx.com/sha/ --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: clone docsearch
- uses: actions/checkout@v2
- with:
- repository: 'Swilder-M/docsearch-scraper-simple'
- path: docsearch
- - name: Install pipenv
- run: |
- python -m pip install --upgrade pipenv wheel
- - id: cache-pipenv
- uses: actions/cache@v1
- with:
- path: ~/.local/share/virtualenvs
- key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
- - name: install dependencies
- if: steps.cache-pipenv.outputs.cache-hit != 'true'
- run: |
- cd docsearch
- pipenv install --keep-outdated
- - name: update current version
- if: ${{ env.VERSION == 'latest' && env.CHANGED == '1' }}
- env:
- APPLICATION_ID: ${{ secrets.DOCS_APPLICATION_ID }}
- API_KEY: ${{ secrets.DOCS_API_KEY }}
- run: |
- cd docsearch
- pipenv run python -m src.index config ${DOCS_TYPE} ${VERSION}
|