sync_repo.sh 705 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. set -ex
  3. GITHUB_DEST=$1
  4. if echo $CI_BUILD_REF_NAME | grep private; then
  5. echo 'sync no private branches'
  6. exit 0
  7. fi
  8. if echo $CI_BUILD_REF_NAME | grep cherry-pick-; then
  9. echo 'sync no cherry-pick branches'
  10. exit 0
  11. fi
  12. if echo $CI_BUILD_REF_NAME | grep dependabot/; then
  13. echo 'sync no dependabot branches'
  14. exit 0
  15. fi
  16. git checkout $CI_BUILD_REF_NAME
  17. if [ "$CI_BUILD_REF_NAME" != "$CI_BUILD_TAG" ]; then
  18. git pull --rebase origin $CI_BUILD_REF_NAME
  19. fi
  20. if git remote | grep github > /dev/null; then
  21. git remote rm github
  22. fi
  23. git remote add github $GITHUB_DEST
  24. if [ "$CI_BUILD_REF_NAME" != "$CI_BUILD_TAG" ]; then
  25. git push github $CI_BUILD_REF_NAME
  26. else
  27. git push github --tags
  28. fi