check_docs.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. name: 📖 Check docs
  2. run-name: 📖 Check docs ${{ github.sha }}
  3. on:
  4. workflow_call:
  5. workflow_run:
  6. workflows:
  7. - 📖 Trigger doc check
  8. types:
  9. - completed
  10. jobs:
  11. translate_docs:
  12. runs-on: ubuntu-24.04
  13. outputs:
  14. repo: ${{ steps.repo-check.outputs.repo }}
  15. ref: ${{ steps.repo-check.outputs.ref }}
  16. permissions:
  17. contents: write
  18. pull-requests: read
  19. defaults:
  20. run:
  21. shell: bash
  22. steps:
  23. - name: Download an artifact with PR repo name
  24. if: github.event_name == 'workflow_run'
  25. uses: actions/download-artifact@v4
  26. with:
  27. github-token: ${{ secrets.GITHUB_TOKEN }}
  28. run-id: ${{ github.event.workflow_run.id }}
  29. name: pr_repo
  30. path: .
  31. - name: Check origin repository
  32. id: repo-check
  33. run: |
  34. if [ "${{ github.event_name }}" == "workflow_run" ]; then
  35. PR_REPO=$(cat ./pr_repo.txt)
  36. repo=$(head -n 1 <<< "$PR_REPO")
  37. ref=$(tail -n 1 <<< "$PR_REPO")
  38. else
  39. repo="${{ github.repository }}"
  40. ref="${{ github.head_ref }}"
  41. fi
  42. echo "repo=$repo" >> $GITHUB_OUTPUT
  43. echo "ref=$ref" >> $GITHUB_OUTPUT
  44. - name: Checkout
  45. uses: actions/checkout@v3
  46. with:
  47. fetch-depth: 0
  48. repository: ${{ steps.repo-check.outputs.repo }}
  49. token: ${{ secrets.GITHUB_TOKEN }}
  50. submodules: true
  51. ref: ${{ steps.repo-check.outputs.ref }}
  52. - name: Setup PHP
  53. uses: shivammathur/setup-php@v2
  54. with:
  55. php-version: '8.2'
  56. tools: composer
  57. extensions: curl
  58. - name: Run auto-translate
  59. env:
  60. OPENROUTER_TRANSLATOR_API_KEY: ${{ secrets.OPENROUTER_TRANSLATOR_API_KEY }}
  61. run: |
  62. set -e
  63. # Install PHP dependencies for translator
  64. cd translator
  65. composer install --no-dev --no-interaction --prefer-dist
  66. cd ..
  67. # Configure git for commits
  68. git config --global user.name "github-actions[bot]"
  69. git config --global user.email "github-actions[bot]@users.noreply.github.com"
  70. # Run auto-translate
  71. ./translator/bin/auto-translate
  72. # Check if there are any changes to commit (including untracked files)
  73. if [ -n "$(git status --porcelain)" ]; then
  74. echo "Auto-translate made changes, committing them..."
  75. git add -A
  76. git commit -m "docs: Auto-translate documentation changes by ${{ github.actor }}"
  77. git push
  78. echo "Changes committed and pushed successfully"
  79. else
  80. echo "No changes made by auto-translate"
  81. fi
  82. docs_check:
  83. needs: translate_docs
  84. runs-on: ubuntu-22.04
  85. permissions:
  86. contents: write
  87. pull-requests: read
  88. defaults:
  89. run:
  90. shell: bash
  91. container:
  92. image: manticoresearch/docs_autodeploy_multi:latest
  93. env:
  94. CACHEB: "../cache"
  95. DOCKER_HOST: tcp://docker:2375/
  96. DOCKER_DRIVER: overlay2
  97. COMMIT_DIR: manual
  98. DOCS_ERRORS_DIR: build/docs/
  99. GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
  100. steps:
  101. - name: Check origin repository
  102. id: repo-check
  103. run: |
  104. if [ "${{ github.event_name }}" == "workflow_run" ]; then
  105. repo="${{ needs.translate_docs.outputs.repo }}"
  106. ref="${{ needs.translate_docs.outputs.ref }}"
  107. elif [ "${{ github.event_name }}" == "pull_request" ]; then
  108. repo="${{ github.event.pull_request.head.repo.full_name }}"
  109. ref="${{ github.head_ref }}"
  110. else
  111. repo="${{ github.repository }}"
  112. ref="${{ github.head_ref || github.ref_name }}"
  113. fi
  114. echo "repo=$repo" >> $GITHUB_OUTPUT
  115. echo "ref=$ref" >> $GITHUB_OUTPUT
  116. - name: Checkout
  117. uses: actions/checkout@v3
  118. with:
  119. fetch-depth: 0
  120. repository: ${{ steps.repo-check.outputs.repo }}
  121. token: ${{ secrets.GITHUB_TOKEN }}
  122. submodules: true
  123. ref: ${{ steps.repo-check.outputs.ref }}
  124. - name: Fetch master and get changed files
  125. id: changed-files
  126. run: |
  127. git config --global --add safe.directory /__w/manticoresearch/manticoresearch
  128. # Update local master only if we're not currently on it
  129. if [ "${{ github.ref_name }}" != "master" -a "${{ github.event_name }}" != "pull_request" ]; then
  130. git fetch origin master:master
  131. fi
  132. git diff-tree --no-commit-id --name-only -r HEAD^1 HEAD | xargs
  133. echo "changed_files=$(git diff-tree --no-commit-id --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
  134. - name: Get changed doc filepathes
  135. id: doc-filepathes
  136. run: |
  137. filepathes=""
  138. for file in ${{ steps.changed-files.outputs.changed_files }}; do
  139. case "$file" in
  140. "$COMMIT_DIR/"*)
  141. filepathes="$file $filepathes"
  142. ;;
  143. esac
  144. done
  145. echo "$filepathes"
  146. echo "filepathes=$filepathes" >> $GITHUB_OUTPUT
  147. - name: Check docs
  148. id: check
  149. run: |
  150. docs_errors=$(php "/Deploy/check_docs_validity.php" "${{ steps.doc-filepathes.outputs.filepathes }}" "$COMMIT_DIR/" "$DOCS_ERRORS_DIR" | xargs)
  151. echo $docs_errors
  152. echo "errors=$docs_errors" >> $GITHUB_OUTPUT
  153. - name: Check docs translations
  154. run: |
  155. set -e
  156. ./misc/compare_manuals.sh
  157. - name: Upload artifact
  158. uses: manticoresoftware/upload_artifact_with_retries@v4
  159. with:
  160. name: Docs error artifact
  161. path: $DOCS_ERRORS_DIR
  162. - name: Display result
  163. run: |
  164. if [ "${{ steps.check.outputs.errors }}" != "" ]; then
  165. exit 1
  166. fi
  167. echo "Doc check passed successfully "