get_repo.sh 2.6 KB

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