update_version.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
  25. # zip, sha1, and sha256 files are all at top level dir
  26. ASSET_PATH=.
  27. ASSET_NAME=VSCodium-darwin-${LATEST_MS_TAG}.zip
  28. VERSION_PATH="darwin"
  29. elif [[ "$CI_WINDOWS" == "True" ]]; then
  30. # TODO: make this logic work for Windows builds too
  31. # or re-implement it in PowerShell and call that from the Windows build
  32. exit
  33. else # linux
  34. # update service links to tar.gz file
  35. # see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION
  36. # and https://update.code.visualstudio.com/api/update/linux-ia32/stable/VERSION
  37. # as examples
  38. ASSET_PATH=.
  39. ASSET_NAME=VSCodium-linux-${BUILDARCH}-${LATEST_MS_TAG}.tar.gz
  40. VERSION_PATH="linux/${BUILDARCH}"
  41. fi
  42. # generate parts
  43. url=${URL_BASE}/${ASSET_NAME}
  44. name=$LATEST_MS_TAG
  45. version=$LATEST_MS_COMMIT
  46. productVersion=$LATEST_MS_TAG
  47. sha1hash=$(cat ${ASSET_PATH}/${ASSET_NAME}.sha1 | awk '{ print $ 1 }')
  48. timestamp=$(node -e 'console.log(Date.now())')
  49. sha256hash=$(cat ${ASSET_PATH}/${ASSET_NAME}.sha256 | awk '{ print $ 1 }')
  50. # check that nothing is blank (blank indicates something awry with build)
  51. for key in url name version productVersion sha1hash timestamp sha256hash; do
  52. if [[ "${!key}" == "" ]]; then
  53. echo "Missing data for version update; exiting..."
  54. exit 1
  55. fi
  56. done
  57. # generate json
  58. JSON=$(jq \
  59. --arg url "${url}" \
  60. --arg name "${name}" \
  61. --arg version "${version}" \
  62. --arg productVersion "${productVersion}" \
  63. --arg hash "${sha1hash}" \
  64. --arg timestamp "${timestamp}" \
  65. --arg sha256hash "${sha256hash}" \
  66. '. | .url=$url | .name=$name | .version=$version | .productVersion=$productVersion | .hash=$hash | .timestamp=$timestamp | .sha256hash=$sha256hash' \
  67. <<<'{}')
  68. echo $JSON
  69. # clone down the current versions repo
  70. # create/update the latest.json file in the correct location
  71. # commit and push (thank you https://www.vinaygopinath.me/blog/tech/commit-to-master-branch-on-github-using-travis-ci/)
  72. git clone https://github.com/VSCodium/versions.git
  73. cd versions
  74. git config user.email "travis@travis-ci.org"
  75. git config user.name "Travis CI"
  76. mkdir -p $VERSION_PATH
  77. echo $JSON > $VERSION_PATH/latest.json
  78. git add $VERSION_PATH
  79. dateAndMonth=`date "+%D %T"`
  80. git commit -m "Travis update: $dateAndMonth (Build $TRAVIS_BUILD_NUMBER)"
  81. git remote rm origin
  82. git remote add origin https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/VSCodium/versions.git > /dev/null 2>&1
  83. git push origin master --quiet