check_docs.yml 5.4 KB

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