fetch-develop.deps.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env bash
  2. # Fetches the js-sdk and matrix-react-sdk dependencies for development
  3. # or testing purposes
  4. # If there exists a branch of that dependency with the same name as
  5. # the branch the current checkout is on, use that branch. Otherwise,
  6. # use develop.
  7. set -x
  8. GIT_CLONE_ARGS=("$@")
  9. [ -z "$defbranch" ] && defbranch="develop"
  10. # clone a specific branch of a github repo
  11. function clone() {
  12. org=$1
  13. repo=$2
  14. branch=$3
  15. # Chop 'origin' off the start as jenkins ends up using
  16. # branches on the origin, but this doesn't work if we
  17. # specify the branch when cloning.
  18. branch=${branch#origin/}
  19. if [ -n "$branch" ]
  20. then
  21. echo "Trying to use $org/$repo#$branch"
  22. # Disable auth prompts: https://serverfault.com/a/665959
  23. GIT_TERMINAL_PROMPT=0 git clone https://github.com/$org/$repo.git $repo --branch $branch \
  24. "${GIT_CLONE_ARGS[@]}"
  25. return $?
  26. fi
  27. return 1
  28. }
  29. function dodep() {
  30. deforg=$1
  31. defrepo=$2
  32. rm -rf $defrepo
  33. # Try the PR author's branch in case it exists on the deps as well.
  34. # Try the target branch of the push or PR.
  35. # Use the default branch as the last resort.
  36. if [[ "$BUILDKITE" == true ]]; then
  37. # If BUILDKITE_BRANCH is set, it will contain either:
  38. # * "branch" when the author's branch and target branch are in the same repo
  39. # * "author:branch" when the author's branch is in their fork
  40. # We can split on `:` into an array to check.
  41. BUILDKITE_BRANCH_ARRAY=(${BUILDKITE_BRANCH//:/ })
  42. if [[ "${#BUILDKITE_BRANCH_ARRAY[@]}" == "2" ]]; then
  43. prAuthor=${BUILDKITE_BRANCH_ARRAY[0]}
  44. prBranch=${BUILDKITE_BRANCH_ARRAY[1]}
  45. else
  46. prAuthor=$deforg
  47. prBranch=$BUILDKITE_BRANCH
  48. fi
  49. clone $prAuthor $defrepo $prBranch ||
  50. clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH ||
  51. clone $deforg $defrepo $defbranch ||
  52. return $?
  53. else
  54. clone $deforg $defrepo $ghprbSourceBranch ||
  55. clone $deforg $defrepo $GIT_BRANCH ||
  56. clone $deforg $defrepo `git rev-parse --abbrev-ref HEAD` ||
  57. clone $deforg $defrepo $defbranch ||
  58. return $?
  59. fi
  60. echo "$defrepo set to branch "`git -C "$defrepo" rev-parse --abbrev-ref HEAD`
  61. }
  62. ##############################
  63. echo 'Setting up matrix-js-sdk'
  64. dodep matrix-org matrix-js-sdk
  65. pushd matrix-js-sdk
  66. yarn link
  67. yarn install --frozen-lockfile
  68. popd
  69. yarn link matrix-js-sdk
  70. ##############################
  71. echo 'Setting up matrix-react-sdk'
  72. dodep element-hq matrix-react-sdk
  73. pushd matrix-react-sdk
  74. yarn link
  75. yarn link matrix-js-sdk
  76. yarn install --frozen-lockfile
  77. popd
  78. yarn link matrix-react-sdk
  79. ##############################