deploy_docs.yaml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. name: Deploy Docs
  2. concurrency:
  3. group: ${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. push:
  7. branches:
  8. - master
  9. jobs:
  10. deploy:
  11. runs-on: ubuntu-20.04
  12. if: github.repository_owner == 'lf-edge'
  13. steps:
  14. - name: clone docs
  15. uses: actions/checkout@v2
  16. with:
  17. fetch-depth: 0
  18. path: docs-files
  19. - name: clone frontend
  20. uses: actions/checkout@v2
  21. with:
  22. repository: 'emqx/docs-emqx-com-frontend'
  23. token: ${{ secrets.CI_GIT_TOKEN }}
  24. path: frontend
  25. - name: use node.js
  26. uses: actions/setup-node@v1
  27. with:
  28. node-version: 14.15
  29. - name: use python
  30. uses: actions/setup-python@v2
  31. with:
  32. python-version: '3.8'
  33. architecture: 'x64'
  34. - name: set env
  35. run: |
  36. BRANCH=$(echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g")
  37. if [ "$BRANCH" = "master" ];then
  38. VERSION="latest"
  39. else
  40. VERSION=v$BRANCH
  41. fi
  42. echo "DOCS_BRANCH=$BRANCH" >> $GITHUB_ENV
  43. echo "VERSION=$VERSION" >> $GITHUB_ENV
  44. echo "DOCS_TYPE=kuiper" >> $GITHUB_ENV
  45. - name: get last version
  46. run: |
  47. cd docs-files
  48. last_sha_url=https://docs.emqx.com/sha/${DOCS_TYPE}
  49. if [[ "$VERSION" != "latest" ]];
  50. then
  51. is_changed=1
  52. elif curl -fs $last_sha_url > /dev/null;
  53. then
  54. last_sha=$(curl $last_sha_url)
  55. echo $last_sha;
  56. if [[ -n $(git diff --name-only "$last_sha"...HEAD -- "docs") ]]
  57. then
  58. is_changed=1
  59. else
  60. is_changed=0
  61. fi
  62. else
  63. is_changed=1
  64. fi
  65. echo "CHANGED=$is_changed" >> $GITHUB_ENV
  66. - name: remove unused files
  67. if: ${{ env.CHANGED == '1' }}
  68. run: |
  69. cd docs-files
  70. python3 .ci/remove_unused.py $(pwd)/docs
  71. - name: move files
  72. if: ${{ env.CHANGED == '1' }}
  73. run: |
  74. rm frontend/docs/en/README.md || true
  75. rm frontend/docs/zh/README.md || true
  76. rm frontend/docs/*.md || true
  77. rm frontend/README.md
  78. mkdir -p frontend/docs/en/${DOCS_TYPE}/${VERSION}/
  79. mkdir -p frontend/docs/zh/${DOCS_TYPE}/${VERSION}/
  80. mkdir -p frontend/docs/.vuepress/public/api/
  81. cp -r docs-files/docs/en_US/* frontend/docs/en/${DOCS_TYPE}/${VERSION}/
  82. cp -r docs-files/docs/zh_CN/* frontend/docs/zh/${DOCS_TYPE}/${VERSION}/
  83. cp docs-files/docs/directory.json frontend/docs/.vuepress/config/directory.json
  84. echo "[\"latest\"]" > frontend/docs/.vuepress/public/api/${DOCS_TYPE}_versions.json
  85. - name: build docs
  86. if: ${{ env.CHANGED == '1' }}
  87. run: |
  88. cd frontend
  89. yarn && yarn build
  90. if [[ "$VERSION" == "latest" ]];
  91. then
  92. mkdir -p docs/.vuepress/dist/sha/
  93. touch docs/.vuepress/dist/sha/${DOCS_TYPE}
  94. echo $GITHUB_SHA >> docs/.vuepress/dist/sha/${DOCS_TYPE}
  95. fi
  96. - name: upload dist
  97. if: ${{ env.CHANGED == '1' }}
  98. run: |
  99. pip3 install coscmd
  100. coscmd config -a ${{ secrets.COS_ID }} -s ${{ secrets.COS_KEY }} -b ${{ secrets.COS_NAME }} -r ${{ secrets.COS_REGION }}
  101. coscmd delete -r -f en/${DOCS_TYPE}/${VERSION} || true
  102. coscmd delete -r -f zh/${DOCS_TYPE}/${VERSION} || true
  103. coscmd config -a ${{ secrets.COS_ID }} -s ${{ secrets.COS_KEY }} -b ${{ secrets.COS_NAME }} -e cos.accelerate.myqcloud.com
  104. cd frontend/docs/.vuepress/dist/
  105. zip -rq docs-dist-${DOCS_TYPE}-${VERSION}.zip ./
  106. coscmd upload docs-dist-${DOCS_TYPE}-${VERSION}.zip docs-zip/
  107. sleep 90
  108. - name: flush CDN
  109. if: ${{ env.CHANGED == '1' }}
  110. run: |
  111. pip3 install tccli
  112. tccli configure set secretId ${{ secrets.COS_ID }}
  113. tccli configure set secretKey ${{ secrets.COS_KEY }}
  114. tccli configure set region ${{ secrets.COS_REGION }}
  115. 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
  116. 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
  117. - name: clone docsearch
  118. uses: actions/checkout@v2
  119. with:
  120. repository: 'Swilder-M/docsearch-scraper-simple'
  121. path: docsearch
  122. - name: Install pipenv
  123. run: |
  124. python -m pip install --upgrade pipenv wheel
  125. - id: cache-pipenv
  126. uses: actions/cache@v1
  127. with:
  128. path: ~/.local/share/virtualenvs
  129. key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
  130. - name: install dependencies
  131. if: steps.cache-pipenv.outputs.cache-hit != 'true'
  132. run: |
  133. cd docsearch
  134. pipenv install --keep-outdated
  135. - name: update current version
  136. if: ${{ env.VERSION == 'latest' && env.CHANGED == '1' }}
  137. env:
  138. APPLICATION_ID: ${{ secrets.DOCS_APPLICATION_ID }}
  139. API_KEY: ${{ secrets.DOCS_API_KEY }}
  140. run: |
  141. cd docsearch
  142. pipenv run python -m src.index config ${DOCS_TYPE} ${VERSION}