sync_repo.sh 677 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. set -ex
  3. GITHUB_DEST=$1
  4. # This can be called for branches or tags. Filter out private branches first.
  5. if [[ $CI_COMMIT_REF_NAME =~ ^(private|cherry-pick-|renovate|dependabot) ]]
  6. then
  7. echo "Do not sync internal branch ${CI_COMMIT_REF_NAME}."
  8. exit 0
  9. fi
  10. # Keep things tidy.
  11. git remote prune origin
  12. # Make sure github remote is up-to-date.
  13. if git remote | grep github > /dev/null
  14. then
  15. git remote rm github
  16. fi
  17. git remote add github "$GITHUB_DEST"
  18. if [ "$CI_COMMIT_TAG" ]
  19. then
  20. # Tag
  21. git push github --tags -f
  22. else
  23. # Commit
  24. git checkout "$CI_COMMIT_REF_NAME"
  25. git reset --hard origin/"$CI_COMMIT_REF_NAME"
  26. git push -f github "$CI_COMMIT_REF_NAME"
  27. fi