weblate-sync.yml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. name: Synchronize Weblate Branch
  2. on:
  3. workflow_dispatch:
  4. schedule:
  5. - cron: '15 18 * * *'
  6. env:
  7. DEVELOP_BRANCH: dev
  8. WEBLATE_BRANCH: weblate
  9. jobs:
  10. check:
  11. name: Check Branches
  12. runs-on: ubuntu-latest
  13. outputs:
  14. behind: ${{ steps.check.outputs.behind }}
  15. ahead: ${{ steps.check.outputs.ahead }}
  16. steps:
  17. - name: Checkout
  18. uses: actions/checkout@v4
  19. with:
  20. ref: ${{ env.DEVELOP_BRANCH }}
  21. clean: false
  22. fetch-depth: 0
  23. - name: Check branches
  24. id: check
  25. run: |
  26. git fetch --all
  27. git branch $WEBLATE_BRANCH origin/$WEBLATE_BRANCH
  28. echo "behind=$(git rev-list --count $WEBLATE_BRANCH..$DEVELOP_BRANCH)" >> $GITHUB_OUTPUT
  29. echo "ahead=$(git rev-list --count $DEVELOP_BRANCH..$WEBLATE_BRANCH)" >> $GITHUB_OUTPUT
  30. - name: Echo outputs
  31. run: |
  32. echo "behind: ${{ steps.check.outputs.behind }}"
  33. echo "ahead: ${{ steps.check.outputs.ahead }}"
  34. force-update:
  35. name: Force Update Weblate Status
  36. runs-on: ubuntu-latest
  37. needs: check
  38. if: ${{ needs.check.outputs.behind > 0 }}
  39. env:
  40. WEBLATE_TOKEN: ${{ secrets.WEBLATE_TOKEN }}
  41. steps:
  42. - name: Checkout
  43. uses: actions/checkout@v4
  44. - name: Setup python
  45. uses: actions/setup-python@v5
  46. with:
  47. python-version: '3.13.5'
  48. - name: Install wlc
  49. run: pip install wlc
  50. - name: Update weblate repository
  51. run: wlc --key $WEBLATE_TOKEN pull
  52. - name: Push weblate branch
  53. run: wlc --key $WEBLATE_TOKEN push
  54. sync-branch:
  55. name: Sync Weblate Branch
  56. runs-on: ubuntu-latest
  57. needs: [check, force-update]
  58. if: ${{ needs.check.outputs.ahead > 0 || needs.check.outputs.behind > 0 && always() }}
  59. steps:
  60. - name: Checkout
  61. uses: actions/checkout@v4
  62. with:
  63. ref: ${{ env.DEVELOP_BRANCH }}
  64. fetch-depth: 0
  65. - name: Set up git
  66. run: |
  67. git config --global user.name 'Weblate'
  68. git config --global user.email 'weblate@nginxui.com'
  69. - name: Push changes of weblate branch to develop branch
  70. run: |
  71. git fetch origin
  72. git merge --ff-only -- origin/${{ env.WEBLATE_BRANCH }}
  73. git push origin ${{ env.DEVELOP_BRANCH }}