update_version.sh 4.5 KB

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