get_repo.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. else
  38. if [[ "${RELEASE_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$ ]];
  39. then
  40. MS_TAG="${BASH_REMATCH[1]}"
  41. else
  42. echo "Bad RELEASE_VERSION: ${RELEASE_VERSION}"
  43. exit 1
  44. fi
  45. fi
  46. fi
  47. echo "RELEASE_VERSION=\"${RELEASE_VERSION}\""
  48. mkdir -p vscode
  49. cd vscode || { echo "'vscode' dir not found"; exit 1; }
  50. git init -q
  51. git remote add origin https://github.com/Microsoft/vscode.git
  52. # figure out latest tag by calling MS update API
  53. if [[ -z "${MS_TAG}" ]]; then
  54. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  55. UPDATE_INFO=$( curl https://update.code.visualstudio.com/api/update/darwin/insider/lol )
  56. else
  57. UPDATE_INFO=$( curl https://update.code.visualstudio.com/api/update/darwin/stable/lol )
  58. fi
  59. export MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
  60. export MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
  61. elif [[ -z "${MS_COMMIT}" ]]; then
  62. reference=$( git ls-remote --tags | grep -x ".*refs\/tags\/${MS_TAG}" | head -1 )
  63. if [[ -z "${reference}" ]]; then
  64. echo "The following tag can't be found: ${MS_TAG}"
  65. exit 1
  66. elif [[ "${reference}" =~ ^([[:alnum:]]+)[[:space:]]+refs\/tags\/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
  67. export MS_COMMIT="${BASH_REMATCH[1]}"
  68. export MS_TAG="${BASH_REMATCH[2]}"
  69. else
  70. echo "The following reference can't be parsed: ${reference}"
  71. exit 1
  72. fi
  73. fi
  74. echo "MS_TAG=\"${MS_TAG}\""
  75. echo "MS_COMMIT=\"${MS_COMMIT}\""
  76. git fetch --depth 1 origin "${MS_COMMIT}"
  77. git checkout FETCH_HEAD
  78. cd ..
  79. # for GH actions
  80. if [[ ${GITHUB_ENV} ]]; then
  81. echo "MS_TAG=${MS_TAG}" >> "${GITHUB_ENV}"
  82. echo "MS_COMMIT=${MS_COMMIT}" >> "${GITHUB_ENV}"
  83. echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
  84. fi
  85. . version.sh