update_version.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. else
  29. # TRAVIS_REPO_SLUG = e.g. VSCodium/vscodium
  30. VERSIONS_REPO=$(echo ${TRAVIS_REPO_SLUG} | awk -F"/" '{ print $1 }')/versions
  31. fi
  32. # generateJson <assetName>
  33. # e.g. generateJson VSCodium-darwin-1.33.0.zip
  34. generateJson() {
  35. local assetName=$1
  36. # generate parts
  37. local url=${URL_BASE}/${assetName}
  38. local name=$LATEST_MS_TAG
  39. local version=$LATEST_MS_COMMIT
  40. local productVersion=$LATEST_MS_TAG
  41. local timestamp=$(node -e 'console.log(Date.now())')
  42. local sha1hash=$(cat ${assetName}.sha1 | awk '{ print $1 }')
  43. local sha256hash=$(cat ${assetName}.sha256 | awk '{ print $1 }')
  44. # check that nothing is blank (blank indicates something awry with build)
  45. for key in url name version productVersion sha1hash timestamp sha256hash; do
  46. if [[ "${!key}" == "" ]]; then
  47. echo "Missing data for version update; exiting..."
  48. exit 1
  49. fi
  50. done
  51. # generate json
  52. local json=$(jq \
  53. --arg url "${url}" \
  54. --arg name "${name}" \
  55. --arg version "${version}" \
  56. --arg productVersion "${productVersion}" \
  57. --arg hash "${sha1hash}" \
  58. --arg timestamp "${timestamp}" \
  59. --arg sha256hash "${sha256hash}" \
  60. '. | .url=$url | .name=$name | .version=$version | .productVersion=$productVersion | .hash=$hash | .timestamp=$timestamp | .sha256hash=$sha256hash' \
  61. <<<'{}')
  62. echo "$json"
  63. }
  64. updateLatestVersion() {
  65. cd versions
  66. local versionPath=$1
  67. local json=$2
  68. # create/update the latest.json file in the correct location
  69. mkdir -p $versionPath
  70. echo $json > $versionPath/latest.json
  71. cd ..
  72. }
  73. # init versions repo for later commiting + pushing the json file to it
  74. # thank you https://www.vinaygopinath.me/blog/tech/commit-to-master-branch-on-github-using-travis-ci/
  75. git clone https://github.com/${VERSIONS_REPO}.git
  76. cd versions
  77. git config user.email "travis@travis-ci.org"
  78. git config user.name "Travis CI"
  79. git remote rm origin
  80. git remote add origin https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${VERSIONS_REPO}.git > /dev/null 2>&1
  81. cd ..
  82. if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
  83. # zip, sha1, and sha256 files are all at top level dir
  84. ASSET_NAME=VSCodium-darwin-${LATEST_MS_TAG}.zip
  85. VERSION_PATH="darwin"
  86. JSON="$(generateJson ${ASSET_NAME})"
  87. updateLatestVersion "$VERSION_PATH" "$JSON"
  88. elif [[ "$CI_WINDOWS" == "True" ]]; then
  89. # windows update service supports user and archive types
  90. # so we will run the commands twice
  91. # user installer
  92. ASSET_NAME=VSCodiumUserSetup-${BUILDARCH}-${LATEST_MS_TAG}.exe
  93. if [[ "$BUILDARCH" == "x64" ]]; then
  94. VERSION_PATH="win32/${BUILDARCH}/user"
  95. else
  96. VERSION_PATH="win32/user"
  97. fi
  98. JSON="$(generateJson ${ASSET_NAME} ${ASSET_PATH})"
  99. updateLatestVersion "$VERSION_PATH" "$JSON"
  100. # windows archive
  101. ASSET_NAME=VSCodium-win32-${BUILDARCH}-${LATEST_MS_TAG}.zip
  102. if [[ "$BUILDARCH" == "x64" ]]; then
  103. VERSION_PATH="win32/${BUILDARCH}/archive"
  104. else
  105. VERSION_PATH="win32/archive"
  106. fi
  107. JSON="$(generateJson ${ASSET_NAME} ${ASSET_PATH})"
  108. updateLatestVersion "$VERSION_PATH" "$JSON"
  109. else # linux
  110. # update service links to tar.gz file
  111. # see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION
  112. # and https://update.code.visualstudio.com/api/update/linux-ia32/stable/VERSION
  113. # as examples
  114. ASSET_NAME=VSCodium-linux-${BUILDARCH}-${LATEST_MS_TAG}.tar.gz
  115. VERSION_PATH="linux/${BUILDARCH}"
  116. JSON="$(generateJson ${ASSET_NAME})"
  117. updateLatestVersion "$VERSION_PATH" "$JSON"
  118. fi
  119. cd versions
  120. git add .
  121. dateAndMonth=`date "+%D %T"`
  122. git commit -m "Travis update: $dateAndMonth (Build $TRAVIS_BUILD_NUMBER)"
  123. git push origin master --quiet
  124. cd ..