update_version.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. VERSIONS_REPO="${GITHUB_USERNAME}/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 "vscodium-ci@not-real.com"
  78. git config user.name "VSCodium 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 [[ "$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. # system installer
  90. ASSET_NAME=VSCodiumSetup-${BUILDARCH}-${LATEST_MS_TAG}.exe
  91. VERSION_PATH="win32/${BUILDARCH}/system"
  92. JSON="$(generateJson ${ASSET_NAME})"
  93. updateLatestVersion "$VERSION_PATH" "$JSON"
  94. # user installer
  95. ASSET_NAME=VSCodiumUserSetup-${BUILDARCH}-${LATEST_MS_TAG}.exe
  96. VERSION_PATH="win32/${BUILDARCH}/user"
  97. JSON="$(generateJson ${ASSET_NAME})"
  98. updateLatestVersion "$VERSION_PATH" "$JSON"
  99. # windows archive
  100. ASSET_NAME=VSCodium-win32-${BUILDARCH}-${LATEST_MS_TAG}.zip
  101. VERSION_PATH="win32/${BUILDARCH}/archive"
  102. JSON="$(generateJson ${ASSET_NAME})"
  103. updateLatestVersion "$VERSION_PATH" "$JSON"
  104. else # linux
  105. # update service links to tar.gz file
  106. # see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION
  107. # as examples
  108. ASSET_NAME=VSCodium-linux-${VSCODE_ARCH}-${LATEST_MS_TAG}.tar.gz
  109. VERSION_PATH="linux/${VSCODE_ARCH}"
  110. JSON="$(generateJson ${ASSET_NAME})"
  111. updateLatestVersion "$VERSION_PATH" "$JSON"
  112. fi
  113. cd versions
  114. git pull origin master # in case another build just pushed
  115. git add .
  116. dateAndMonth=`date "+%D %T"`
  117. git commit -m "CI update: $dateAndMonth (Build $GITHUB_RUN_NUMBER)"
  118. if ! git push origin master --quiet; then
  119. git pull origin master
  120. git push origin master --quiet
  121. fi
  122. cd ..