update_version.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. if [[ "$SHOULD_BUILD" != "yes" ]]; then
  3. echo "Will not update version JSON because we did not build"
  4. exit
  5. fi
  6. # {
  7. # "url": "https://az764295.vo.msecnd.net/stable/51b0b28134d51361cf996d2f0a1c698247aeabd8/VSCode-darwin-stable.zip",
  8. # "name": "1.33.1",
  9. # "version": "51b0b28134d51361cf996d2f0a1c698247aeabd8",
  10. # "productVersion": "1.33.1",
  11. # "hash": "cb4109f196d23b9d1e8646ce43145c5bb62f55a8",
  12. # "timestamp": 1554971059007,
  13. # "sha256hash": "ac2a1c8772501732cd5ff539a04bb4dc566b58b8528609d2b34bbf970d08cf01"
  14. # }
  15. # `url` is URL_BASE + filename of asset e.g.
  16. # darwin: https://github.com/VSCodium/vscodium/releases/download/${LATEST_MS_TAG}/VSCodium-darwin-${LATEST_MS_TAG}.zip
  17. # `name` is $LATEST_MS_TAG
  18. # `version` is $LATEST_MS_COMMIT
  19. # `productVersion` is $LATEST_MS_TAG
  20. # `hash` in <filename>.sha1
  21. # `timestamp` is $(node -e 'console.log(Date.now())')
  22. # `sha256hash` in <filename>.sha256
  23. URL_BASE=https://github.com/VSCodium/vscodium/releases/download/${LATEST_MS_TAG}
  24. # to make testing on forks easier
  25. if [[ "$CI_WINDOWS" == "True" ]]; then
  26. # BUILD_REPOSITORY_URI = e.g. https://github.com/VSCodium/vscodium
  27. VERSIONS_REPO=$(echo ${BUILD_REPOSITORY_URI} | awk -F"/" '{ print $4 }')/versions
  28. git config --global core.autocrlf true
  29. else
  30. # TRAVIS_REPO_SLUG = e.g. VSCodium/vscodium
  31. VERSIONS_REPO=$(echo ${TRAVIS_REPO_SLUG} | awk -F"/" '{ print $1 }')/versions
  32. fi
  33. # generateJson <assetName>
  34. # e.g. generateJson VSCodium-darwin-1.33.0.zip
  35. generateJson() {
  36. local assetName=$1
  37. # generate parts
  38. local url=${URL_BASE}/${assetName}
  39. local name=$LATEST_MS_TAG
  40. local version=$LATEST_MS_COMMIT
  41. local productVersion=$LATEST_MS_TAG
  42. local timestamp=$(node -e 'console.log(Date.now())')
  43. local sha1hash=$(cat ${assetName}.sha1 | awk '{ print $1 }')
  44. local sha256hash=$(cat ${assetName}.sha256 | awk '{ print $1 }')
  45. # check that nothing is blank (blank indicates something awry with build)
  46. for key in url name version productVersion sha1hash timestamp sha256hash; do
  47. if [[ "${!key}" == "" ]]; then
  48. echo "Missing data for version update; exiting..."
  49. exit 1
  50. fi
  51. done
  52. # generate json
  53. local json=$(jq \
  54. --arg url "${url}" \
  55. --arg name "${name}" \
  56. --arg version "${version}" \
  57. --arg productVersion "${productVersion}" \
  58. --arg hash "${sha1hash}" \
  59. --arg timestamp "${timestamp}" \
  60. --arg sha256hash "${sha256hash}" \
  61. '. | .url=$url | .name=$name | .version=$version | .productVersion=$productVersion | .hash=$hash | .timestamp=$timestamp | .sha256hash=$sha256hash' \
  62. <<<'{}')
  63. echo "$json"
  64. }
  65. updateLatestVersion() {
  66. cd versions
  67. local versionPath=$1
  68. local json=$2
  69. # create/update the latest.json file in the correct location
  70. mkdir -p $versionPath
  71. echo $json > $versionPath/latest.json
  72. cd ..
  73. }
  74. # init versions repo for later commiting + pushing the json file to it
  75. # thank you https://www.vinaygopinath.me/blog/tech/commit-to-master-branch-on-github-using-travis-ci/
  76. git clone https://github.com/${VERSIONS_REPO}.git
  77. cd versions
  78. git config user.email "travis@travis-ci.org"
  79. git config user.name "Travis CI"
  80. git remote rm origin
  81. git remote add origin https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${VERSIONS_REPO}.git > /dev/null 2>&1
  82. cd ..
  83. if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
  84. # zip, sha1, and sha256 files are all at top level dir
  85. ASSET_NAME=VSCodium-darwin-${LATEST_MS_TAG}.zip
  86. VERSION_PATH="darwin"
  87. JSON="$(generateJson ${ASSET_NAME})"
  88. updateLatestVersion "$VERSION_PATH" "$JSON"
  89. elif [[ "$CI_WINDOWS" == "True" ]]; then
  90. # windows update service supports user and archive types
  91. # so we will run the commands twice
  92. # user installer
  93. ASSET_NAME=VSCodiumUserSetup-${BUILDARCH}-${LATEST_MS_TAG}.exe
  94. VERSION_PATH="win32/${BUILDARCH}/user"
  95. JSON="$(generateJson ${ASSET_NAME})"
  96. updateLatestVersion "$VERSION_PATH" "$JSON"
  97. # windows archive
  98. ASSET_NAME=VSCodium-win32-${BUILDARCH}-${LATEST_MS_TAG}.zip
  99. VERSION_PATH="win32/${BUILDARCH}/archive"
  100. JSON="$(generateJson ${ASSET_NAME})"
  101. updateLatestVersion "$VERSION_PATH" "$JSON"
  102. else # linux
  103. # update service links to tar.gz file
  104. # see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION
  105. # and https://update.code.visualstudio.com/api/update/linux-ia32/stable/VERSION
  106. # as examples
  107. ASSET_NAME=VSCodium-linux-${BUILDARCH}-${LATEST_MS_TAG}.tar.gz
  108. VERSION_PATH="linux/${BUILDARCH}"
  109. JSON="$(generateJson ${ASSET_NAME})"
  110. updateLatestVersion "$VERSION_PATH" "$JSON"
  111. fi
  112. cd versions
  113. git pull origin master # in case another build just pushed
  114. git add .
  115. dateAndMonth=`date "+%D %T"`
  116. git commit -m "Travis update: $dateAndMonth (Build $TRAVIS_BUILD_NUMBER)"
  117. git push origin master --quiet
  118. cd ..