get_repo.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env bash
  2. # shellcheck disable=SC2129
  3. set -e
  4. # git workaround
  5. if [[ "${CI_BUILD}" != "no" ]]; then
  6. git config --global --add safe.directory "/__w/$( echo "${GITHUB_REPOSITORY}" | awk '{print tolower($0)}' )"
  7. fi
  8. if [[ -z "${RELEASE_VERSION}" ]]; then
  9. if [[ "${VSCODE_LATEST}" == "yes" ]] || [[ ! -f "${VSCODE_QUALITY}.json" ]]; then
  10. UPDATE_INFO=$( curl --silent --fail "https://update.code.visualstudio.com/api/update/darwin/${VSCODE_QUALITY}/0000000000000000000000000000000000000000" )
  11. else
  12. MS_COMMIT=$( jq -r '.commit' "${VSCODE_QUALITY}.json" )
  13. MS_TAG=$( jq -r '.tag' "${VSCODE_QUALITY}.json" )
  14. fi
  15. if [[ -z "${MS_COMMIT}" ]]; then
  16. MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
  17. MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
  18. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  19. MS_TAG="${MS_TAG/\-insider/}"
  20. fi
  21. fi
  22. date=$( date +%Y%j )
  23. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  24. RELEASE_VERSION="${MS_TAG}.${date: -5}-insider"
  25. else
  26. 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 "Error: 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 "Error: Bad RELEASE_VERSION: ${RELEASE_VERSION}"
  43. exit 1
  44. fi
  45. fi
  46. if [[ "${MS_TAG}" == "$( jq -r '.tag' "${VSCODE_QUALITY}".json )" ]]; then
  47. MS_COMMIT=$( jq -r '.commit' "${VSCODE_QUALITY}".json )
  48. else
  49. echo "Error: No MS_COMMIT for ${RELEASE_VERSION}"
  50. exit 1
  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. UPDATE_INFO=$( curl --silent --fail "https://update.code.visualstudio.com/api/update/darwin/${VSCODE_QUALITY}/0000000000000000000000000000000000000000" )
  61. MS_COMMIT=$( echo "${UPDATE_INFO}" | jq -r '.version' )
  62. MS_TAG=$( echo "${UPDATE_INFO}" | jq -r '.name' )
  63. elif [[ -z "${MS_COMMIT}" ]]; then
  64. REFERENCE=$( git ls-remote --tags | grep -x ".*refs\/tags\/${MS_TAG}" | head -1 )
  65. if [[ -z "${REFERENCE}" ]]; then
  66. echo "Error: The following tag can't be found: ${MS_TAG}"
  67. exit 1
  68. elif [[ "${REFERENCE}" =~ ^([[:alnum:]]+)[[:space:]]+refs\/tags\/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
  69. MS_COMMIT="${BASH_REMATCH[1]}"
  70. MS_TAG="${BASH_REMATCH[2]}"
  71. else
  72. echo "Error: The following reference can't be parsed: ${REFERENCE}"
  73. exit 1
  74. fi
  75. fi
  76. echo "MS_TAG=\"${MS_TAG}\""
  77. echo "MS_COMMIT=\"${MS_COMMIT}\""
  78. git fetch --depth 1 origin "${MS_COMMIT}"
  79. git checkout FETCH_HEAD
  80. cd ..
  81. # for GH actions
  82. if [[ "${GITHUB_ENV}" ]]; then
  83. echo "MS_TAG=${MS_TAG}" >> "${GITHUB_ENV}"
  84. echo "MS_COMMIT=${MS_COMMIT}" >> "${GITHUB_ENV}"
  85. echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
  86. fi
  87. export MS_TAG
  88. export MS_COMMIT
  89. export RELEASE_VERSION