commit-bot.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. name: Commit Bot
  2. on:
  3. push:
  4. branches:
  5. - master
  6. - develop
  7. schedule:
  8. - cron: "0,30 * * * *"
  9. concurrency:
  10. group: ${{format('commit-bot-{0}:{1}', github.repository, github.ref)}}
  11. cancel-in-progress: true
  12. jobs:
  13. update-modules:
  14. runs-on: ubuntu-latest
  15. name: Commit Bot
  16. steps:
  17. - name: Check for module updates
  18. id: branches
  19. run: |
  20. if [[ "${{ github.event_name }}" == "push" ]]; then
  21. branches="${{ github.ref_name }}"
  22. else
  23. branches="master develop"
  24. fi
  25. echo "branches=$branches" >> $GITHUB_OUTPUT
  26. - name: Checkout master repository
  27. uses: actions/checkout@v4
  28. if: contains(steps.branches.outputs.branches, 'master')
  29. with:
  30. ref: master
  31. path: master
  32. - name: Checkout develop repository
  33. uses: actions/checkout@v4
  34. if: contains(steps.branches.outputs.branches, 'develop')
  35. with:
  36. ref: develop
  37. path: develop
  38. - name: Check for module updates
  39. run: |
  40. branches="${{ steps.branches.outputs.branches }}"
  41. # Set up Git
  42. git config --global user.name "boost-commitbot"
  43. git config --global user.email "boost-commitbot@example.com"
  44. # Update each branch
  45. for branch in $branches; do
  46. cd $branch
  47. module_paths=$(git config --file .gitmodules --get-regexp '^submodule\..*\.path$')
  48. while IFS=' ' read -r key path; do
  49. submodule_name=$(echo "$key" | awk -F '.' '{print $2}')
  50. submodule_path=$(echo "$path")
  51. url=$(git config --file .gitmodules --get-regexp "^submodule\.$submodule_name\.url$" | awk '{print $2}')
  52. hash=$(git ls-remote "$url" "refs/heads/$branch" | cut -f 1)
  53. hash="${hash#"${hash%%[![:space:]]*}"}"
  54. hash="${hash%"${hash##*[![:space:]]}"}"
  55. commit_id="${hash:0:8}"
  56. previous_hash=$(git ls-tree HEAD "$submodule_path" | awk '{print $3}')
  57. previous_hash="${previous_hash#"${previous_hash%%[![:space:]]*}"}"
  58. previous_hash="${previous_hash%"${previous_hash##*[![:space:]]}"}"
  59. previous_commit_id="${previous_hash:0:8}"
  60. if [ "$hash" == "$previous_hash" ]; then
  61. echo "$submodule_name ($commit_id): OK"
  62. else
  63. echo "$submodule_name: $previous_commit_id -> $commit_id"
  64. set -x
  65. set +e
  66. git submodule update --init "$submodule_path"
  67. git submodule update --remote "$submodule_path"
  68. git add "$submodule_path"
  69. git commit -m "Update $submodule_name from $branch"
  70. set -e
  71. set +x
  72. fi
  73. done <<< "$module_paths"
  74. cd ..
  75. done
  76. - name: Push changes from master
  77. uses: ad-m/github-push-action@v0.8.0
  78. if: contains(steps.branches.outputs.branches, 'master')
  79. with:
  80. github_token: ${{ secrets.GITHUB_TOKEN }}
  81. branch: master
  82. directory: master
  83. - name: Push changes from develop
  84. uses: ad-m/github-push-action@v0.8.0
  85. if: contains(steps.branches.outputs.branches, 'develop')
  86. with:
  87. github_token: ${{ secrets.GITHUB_TOKEN }}
  88. branch: develop
  89. directory: develop
粤ICP备19079148号