get_repo.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 [ "${INSIDER}" == "yes" ]; then
  9. UPDATE_INFO=$(curl https://update.code.visualstudio.com/api/update/darwin/insider/lol)
  10. else
  11. UPDATE_INFO=$(curl https://update.code.visualstudio.com/api/update/darwin/stable/lol)
  12. fi
  13. export MS_COMMIT=$(echo "${UPDATE_INFO}" | jq -r '.version')
  14. export MS_TAG=$(echo "${UPDATE_INFO}" | jq -r '.name')
  15. date=$( date +%Y%j )
  16. if [ "${INSIDER}" == "yes" ]; then
  17. export RELEASE_VERSION="${MS_TAG/-insider/}.${date: -5}-insider"
  18. else
  19. export RELEASE_VERSION="${MS_TAG}.${date: -5}"
  20. fi
  21. else
  22. if [[ "${RELEASE_VERSION}" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$ ]];
  23. then
  24. MS_TAG="${BASH_REMATCH[1]}"
  25. else
  26. echo "Bad RELEASE_VERSION: ${RELEASE_VERSION}"
  27. exit 1
  28. fi
  29. fi
  30. echo "Release version: ${RELEASE_VERSION}"
  31. mkdir -p vscode
  32. cd vscode || { echo "'vscode' dir not found"; exit 1; }
  33. git init -q
  34. git remote add origin https://github.com/Microsoft/vscode.git
  35. # figure out latest tag by calling MS update API
  36. if [[ -z "${MS_TAG}" ]]; then
  37. if [ "${INSIDER}" == "yes" ]; then
  38. UPDATE_INFO=$(curl https://update.code.visualstudio.com/api/update/darwin/insider/lol)
  39. else
  40. UPDATE_INFO=$(curl https://update.code.visualstudio.com/api/update/darwin/stable/lol)
  41. fi
  42. export MS_COMMIT=$(echo "${UPDATE_INFO}" | jq -r '.version')
  43. export MS_TAG=$(echo "${UPDATE_INFO}" | jq -r '.name')
  44. elif [[ -z "${MS_COMMIT}" ]]; then
  45. reference=$( git ls-remote --tags | grep -x ".*refs\/tags\/${MS_TAG}" | head -1 )
  46. if [[ -z "${reference}" ]]; then
  47. echo "The following tag can't be found: ${MS_TAG}"
  48. exit 1
  49. elif [[ "${reference}" =~ ^([[:alnum:]]+)[[:space:]]+refs\/tags\/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
  50. export MS_COMMIT="${BASH_REMATCH[1]}"
  51. export MS_TAG="${BASH_REMATCH[2]}"
  52. else
  53. echo "The following reference can't be parsed: ${reference}"
  54. exit 1
  55. fi
  56. fi
  57. echo "Got the MS tag: ${MS_TAG} version: ${MS_COMMIT}"
  58. git fetch --depth 1 origin "${MS_COMMIT}"
  59. git checkout FETCH_HEAD
  60. cd ..
  61. # for GH actions
  62. if [[ ${GITHUB_ENV} ]]; then
  63. echo "MS_TAG=${MS_TAG}" >> "${GITHUB_ENV}"
  64. echo "MS_COMMIT=${MS_COMMIT}" >> "${GITHUB_ENV}"
  65. echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
  66. fi
  67. . version.sh