sync_cmakebuild.yml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. name: Sync cmakebuild with main
  2. on:
  3. schedule:
  4. - cron: "0 * * * *" # At minute 0 every hour
  5. workflow_dispatch:
  6. concurrency:
  7. group: ${{ github.workflow }}
  8. cancel-in-progress: true
  9. env:
  10. REPO: ${{ github.repository }}
  11. TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
  12. jobs:
  13. sync:
  14. runs-on: ubuntu-latest
  15. steps:
  16. - name: Sync
  17. run: |
  18. mainsha=$(curl -s -H "Accept: application/vnd.github.VERSION.sha" https://api.github.com/repos/$REPO/commits/main)
  19. echo "Main sha: ${mainsha}"
  20. lastsha=$(curl -s https://raw.githubusercontent.com/$REPO/cmakebuild/ydb/ci/cmakegen.txt)
  21. echo "Last sha: ${lastsha}"
  22. if [ "${mainsha}" == "${lastsha}" ];then
  23. echo "No new commits on the main branch to merge, exiting"
  24. exit 0
  25. fi
  26. git clone -b main https://$TOKEN@github.com/$REPO.git ydb
  27. git config --global user.email "alex@ydb.tech"
  28. git config --global user.name "Alexander Smirnov"
  29. cd ydb
  30. git fetch --depth `expr $(git rev-list --count HEAD) + 1`
  31. # Depth 10: 1st with cmake generation, 2nd with previous merge, 3rd is common between main and cmakebuild,
  32. # others for possible commits directly on cmakebuild branch
  33. git fetch origin cmakebuild:cmakebuild --depth 10
  34. mainsha=$(git rev-parse HEAD)
  35. git checkout cmakebuild
  36. prevsha=$(git rev-parse HEAD)
  37. conflicts_file=$(mktemp)
  38. for i in $(seq 1 10);do
  39. (git merge main --no-commit --no-ff main > $conflicts_file) | true
  40. git reset HEAD --hard > /dev/null
  41. git clean -fd > /dev/null
  42. if [ -s $conflicts_file ];then
  43. echo "Conflicts detected, trying to remove referenced CMakeLists* files"
  44. grep -E -o '\s\S*CMakeLists\S*\s' $conflicts_file | xargs rm -f
  45. git add .
  46. git commit -m "Remove conflicted CMakeLists"
  47. else
  48. break
  49. fi
  50. done
  51. git merge main --no-edit
  52. currsha=$(git rev-parse HEAD)
  53. if [ ${prevsha} == ${currsha} ];then
  54. echo "Merge did not bring any changes, exiting"
  55. exit
  56. fi
  57. # Generate cmakelists
  58. ./generate_cmake -k
  59. echo ${mainsha} > ydb/ci/cmakegen.txt
  60. git add .
  61. git commit -m "Generate cmake for ${mainsha}"
  62. git push --set-upstream origin cmakebuild