2
0

get_repo.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. set -e
  3. # git workaround
  4. if [[ "${CI_BUILD}" != "no" ]]; then
  5. git config --global --add safe.directory /__w/vscodium/vscodium
  6. fi
  7. if [[ -z "${RELEASE_VERSION}" ]]; then
  8. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  9. if [[ "${VSCODE_LATEST}" == "yes" ]] || [[ ! -f "insider.json" ]]; then
  10. UPDATE_INFO=$( curl https://update.code.visualstudio.com/api/update/darwin/insider/lol )
  11. else
  12. export MS_COMMIT=$(jq -r '.commit' insider.json)
  13. export MS_TAG=$(jq -r '.tag' insider.json)
  14. fi
  15. else
  16. UPDATE_INFO=$( curl https://update.code.visualstudio.com/api/update/darwin/stable/lol )
  17. fi
  18. if [[ -z "${MS_COMMIT}" ]]; then
  19. export MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
  20. export MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
  21. fi
  22. date=$( date +%Y%j )
  23. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  24. export RELEASE_VERSION="${MS_TAG/\-insider/}.${date: -5}-insider"
  25. else
  26. export RELEASE_VERSION="${MS_TAG}.${date: -5}"
  27. fi
  28. else
  29. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  30. if [[ "${RELEASE_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+-insider$ ]];
  31. then
  32. MS_TAG="${BASH_REMATCH[1]}"
  33. else
  34. echo "Bad RELEASE_VERSION: ${RELEASE_VERSION}"
  35. exit 1
  36. fi
  37. if [[ "${MS_TAG}" == "$(jq -r '.tag' insider.json)" ]]; then
  38. export MS_COMMIT=$(jq -r '.commit' insider.json)
  39. else
  40. echo "No MS_COMMIT for ${RELEASE_VERSION}"
  41. exit 1
  42. fi
  43. else
  44. if [[ "${RELEASE_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$ ]];
  45. then
  46. MS_TAG="${BASH_REMATCH[1]}"
  47. else
  48. echo "Bad RELEASE_VERSION: ${RELEASE_VERSION}"
  49. exit 1
  50. fi
  51. fi
  52. fi
  53. echo "RELEASE_VERSION=\"${RELEASE_VERSION}\""
  54. mkdir -p vscode
  55. cd vscode || { echo "'vscode' dir not found"; exit 1; }
  56. git init -q
  57. git remote add origin https://github.com/Microsoft/vscode.git
  58. # figure out latest tag by calling MS update API
  59. if [[ -z "${MS_TAG}" ]]; then
  60. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  61. UPDATE_INFO=$( curl https://update.code.visualstudio.com/api/update/darwin/insider/lol )
  62. else
  63. UPDATE_INFO=$( curl https://update.code.visualstudio.com/api/update/darwin/stable/lol )
  64. fi
  65. export MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
  66. export MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
  67. elif [[ -z "${MS_COMMIT}" ]]; then
  68. reference=$( git ls-remote --tags | grep -x ".*refs\/tags\/${MS_TAG}" | head -1 )
  69. if [[ -z "${reference}" ]]; then
  70. echo "The following tag can't be found: ${MS_TAG}"
  71. exit 1
  72. elif [[ "${reference}" =~ ^([[:alnum:]]+)[[:space:]]+refs\/tags\/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
  73. export MS_COMMIT="${BASH_REMATCH[1]}"
  74. export MS_TAG="${BASH_REMATCH[2]}"
  75. else
  76. echo "The following reference can't be parsed: ${reference}"
  77. exit 1
  78. fi
  79. fi
  80. echo "MS_TAG=\"${MS_TAG}\""
  81. echo "MS_COMMIT=\"${MS_COMMIT}\""
  82. git fetch --depth 1 origin "${MS_COMMIT}"
  83. git checkout FETCH_HEAD
  84. cd ..
  85. # for GH actions
  86. if [[ ${GITHUB_ENV} ]]; then
  87. echo "MS_TAG=${MS_TAG}" >> "${GITHUB_ENV}"
  88. echo "MS_COMMIT=${MS_COMMIT}" >> "${GITHUB_ENV}"
  89. echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
  90. fi
  91. . version.sh