commit-bot.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. name: Commit Bot
  2. # To avoid infinite loops, don't trigger on "push"
  3. on:
  4. schedule:
  5. - cron: "0,30 * * * *"
  6. concurrency:
  7. group: ${{format('commit-bot-{0}:{1}', github.repository, github.ref)}}
  8. cancel-in-progress: true
  9. jobs:
  10. update-modules:
  11. runs-on: ubuntu-latest
  12. name: Commit Bot
  13. if: github.repository == 'boostorg/boost'
  14. steps:
  15. - name: Check for module updates
  16. id: branches
  17. run: |
  18. if [[ "${{ github.event_name }}" == "push" ]]; then
  19. branches="${{ github.ref_name }}"
  20. else
  21. branches="master develop"
  22. fi
  23. echo "branches=$branches" >> $GITHUB_OUTPUT
  24. - name: Checkout master repository
  25. uses: actions/checkout@v4
  26. if: contains(steps.branches.outputs.branches, 'master')
  27. with:
  28. ref: master
  29. path: master
  30. persist-credentials: false
  31. - name: Checkout develop repository
  32. uses: actions/checkout@v4
  33. if: contains(steps.branches.outputs.branches, 'develop')
  34. with:
  35. ref: develop
  36. path: develop
  37. persist-credentials: false
  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. if [[ ! "$url" =~ ^https:// ]]; then
  53. basicreponame=$(basename $url)
  54. url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY_OWNER}/${basicreponame}
  55. fi
  56. hash=$(git ls-remote "$url" "refs/heads/$branch" | cut -f 1)
  57. hash="${hash#"${hash%%[![:space:]]*}"}"
  58. hash="${hash%"${hash##*[![:space:]]}"}"
  59. commit_id="${hash:0:8}"
  60. previous_hash=$(git ls-tree HEAD "$submodule_path" | awk '{print $3}')
  61. previous_hash="${previous_hash#"${previous_hash%%[![:space:]]*}"}"
  62. previous_hash="${previous_hash%"${previous_hash##*[![:space:]]}"}"
  63. previous_commit_id="${previous_hash:0:8}"
  64. if [ "$hash" == "$previous_hash" ]; then
  65. echo "$submodule_name ($commit_id): OK"
  66. else
  67. echo "$submodule_name: $previous_commit_id -> $commit_id"
  68. set -x
  69. set +e
  70. git submodule update --init "$submodule_path"
  71. git submodule update --remote "$submodule_path"
  72. git add "$submodule_path"
  73. git commit -m "Update $submodule_name from $branch"
  74. set -e
  75. set +x
  76. fi
  77. done <<< "$module_paths"
  78. cd ..
  79. done
  80. - name: Push changes from master
  81. uses: ad-m/github-push-action@v0.8.0
  82. if: contains(steps.branches.outputs.branches, 'master')
  83. with:
  84. # github_token: ${{ secrets.GITHUB_TOKEN }}
  85. github_token: ${{ secrets.CI_PAT }}
  86. branch: master
  87. directory: master
  88. - name: Push changes from develop
  89. uses: ad-m/github-push-action@v0.8.0
  90. if: contains(steps.branches.outputs.branches, 'develop')
  91. with:
  92. # github_token: ${{ secrets.GITHUB_TOKEN }}
  93. github_token: ${{ secrets.CI_PAT }}
  94. branch: develop
  95. directory: develop
粤ICP备19079148号