locales-coverage.yml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: Build locales coverage
  2. on:
  3. push:
  4. branches:
  5. - "l10n_master"
  6. jobs:
  7. locales:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - uses: actions/checkout@v2
  11. with:
  12. token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
  13. - name: Setup Node.js 12.x
  14. uses: actions/setup-node@v1
  15. with:
  16. node-version: 12.x
  17. - name: Create report file
  18. run: |
  19. npm run locales-coverage
  20. FILE_CHANGED=$(git diff src/locales/percentages.json)
  21. if [ ! -z "${FILE_CHANGED}" ]; then
  22. git config --global user.name 'Kostas Bariotis'
  23. git config --global user.email 'konmpar@gmail.com'
  24. git add src/locales/percentages.json
  25. git commit -am "Auto commit: Calculate translation coverage"
  26. git push
  27. fi
  28. - name: Find pull request number
  29. uses: jwalton/gh-find-current-pr@v1
  30. id: findPullRequestNumber
  31. with:
  32. github-token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
  33. - name: Find Comment
  34. uses: peter-evans/find-comment@v1
  35. id: findComment
  36. with:
  37. token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
  38. issue-number: ${{ steps.findPullRequestNumber.outputs.pr }}
  39. comment-author: "kbariotis"
  40. body-includes: "Languages check"
  41. - name: Construct comment body
  42. id: getCommentBody
  43. run: |
  44. locales_above_threshold=$(cat src/locales/percentages.json | jq -r 'to_entries[] | select(.value > 85) | "|\(.key)|\(.value)|"')
  45. locales_below_threshold=$(cat src/locales/percentages.json | jq -r 'to_entries[] | select(.value <= 85) | "|\(.key)|\(.value)|"')
  46. header=$(echo "
  47. ## Languages check
  48. Our translations for every languages should be at least **85%** to appear on Excalidraw. Help us translate them in [Crowdin](https://crowdin.com/project/excalidraw).
  49. ")
  50. comment_body=$(echo "$header
  51. ### Languages over the threshold
  52. |Locale|%|
  53. |----|----|
  54. $locales_above_threshold
  55. ### Languages below the threshold
  56. |Locale|%|
  57. |----|----|
  58. $locales_below_threshold
  59. ")
  60. comment_body="${comment_body//'%'/'%25'}"
  61. comment_body="${comment_body//$'\n'/'%0A'}"
  62. comment_body="${comment_body//$'\r'/'%0D'}"
  63. echo ::set-output name=body::$comment_body
  64. - name: Create comment
  65. if: ${{ steps.findComment.outputs.comment-id == 0 }}
  66. uses: peter-evans/create-or-update-comment@v1
  67. with:
  68. token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
  69. issue-number: ${{ steps.findPullRequestNumber.outputs.pr }}
  70. body: ${{ steps.getCommentBody.outputs.body }}
  71. - name: Update comment
  72. if: ${{ steps.findComment.outputs.comment-id != 0 }}
  73. uses: peter-evans/create-or-update-comment@v1
  74. with:
  75. edit-mode: "replace"
  76. token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
  77. comment-id: ${{ steps.findComment.outputs.comment-id }}
  78. body: ${{ steps.getCommentBody.outputs.body }}