get_repo.sh 3.5 KB

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