update_version.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash
  2. set -e
  3. if [[ "${SHOULD_BUILD}" != "yes" ]]; then
  4. echo "Will not update version JSON because we did not build"
  5. exit
  6. fi
  7. if [[ -z "${GITHUB_TOKEN}" ]]; then
  8. echo "Will not update version JSON because no GITHUB_TOKEN defined"
  9. exit
  10. fi
  11. # {
  12. # "url": "https://az764295.vo.msecnd.net/stable/51b0b28134d51361cf996d2f0a1c698247aeabd8/VSCode-darwin-stable.zip",
  13. # "name": "1.33.1",
  14. # "version": "51b0b28134d51361cf996d2f0a1c698247aeabd8",
  15. # "productVersion": "1.33.1",
  16. # "hash": "cb4109f196d23b9d1e8646ce43145c5bb62f55a8",
  17. # "timestamp": 1554971059007,
  18. # "sha256hash": "ac2a1c8772501732cd5ff539a04bb4dc566b58b8528609d2b34bbf970d08cf01"
  19. # }
  20. # `url` is URL_BASE + filename of asset e.g.
  21. # darwin: https://github.com/VSCodium/vscodium/releases/download/${RELEASE_VERSION}/VSCodium-darwin-${RELEASE_VERSION}.zip
  22. # `name` is $RELEASE_VERSION
  23. # `version` is $BUILD_SOURCEVERSION
  24. # `productVersion` is $RELEASE_VERSION
  25. # `hash` in <filename>.sha1
  26. # `timestamp` is $(node -e 'console.log(Date.now())')
  27. # `sha256hash` in <filename>.sha256
  28. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  29. URL_BASE="https://github.com/VSCodium/vscodium-insiders/releases/download/${RELEASE_VERSION}"
  30. else
  31. URL_BASE="https://github.com/VSCodium/vscodium/releases/download/${RELEASE_VERSION}"
  32. fi
  33. # to make testing on forks easier
  34. VERSIONS_REPO="${GITHUB_USERNAME}/versions"
  35. echo "Versions repo: ${VERSIONS_REPO}"
  36. generateJson() {
  37. JSON_DATA="{}"
  38. # generate parts
  39. local url="${URL_BASE}/${ASSET_NAME}"
  40. local name="${RELEASE_VERSION}"
  41. local version="${BUILD_SOURCEVERSION}"
  42. local productVersion="${RELEASE_VERSION}"
  43. local timestamp=$(node -e 'console.log(Date.now())')
  44. if [[ ! -f "artifacts/${ASSET_NAME}" ]]; then
  45. echo "Downloading artifact '${ASSET_NAME}'"
  46. gh release download "${RELEASE_VERSION}" --dir "artifacts" --pattern "${ASSET_NAME}*"
  47. fi
  48. local sha1hash=$(cat "artifacts/${ASSET_NAME}.sha1" | awk '{ print $1 }')
  49. local sha256hash=$(cat "artifacts/${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 [[ -z "${key}" ]]; then
  53. echo "Variable '${key}' is empty; exiting..."
  54. exit 1
  55. fi
  56. done
  57. # generate json
  58. JSON_DATA=$(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. }
  69. updateLatestVersion() {
  70. echo "Generating ${VERSION_PATH}/latest.json"
  71. generateJson
  72. cd versions
  73. # create/update the latest.json file in the correct location
  74. mkdir -p "${VERSION_PATH}"
  75. echo "${JSON_DATA}" > "${VERSION_PATH}/latest.json"
  76. cd ..
  77. }
  78. # init versions repo for later commiting + pushing the json file to it
  79. # thank you https://www.vinaygopinath.me/blog/tech/commit-to-master-branch-on-github-using-travis-ci/
  80. git clone "https://github.com/${VERSIONS_REPO}.git"
  81. cd versions
  82. git config user.email "vscodium-ci@not-real.com"
  83. git config user.name "VSCodium CI"
  84. git remote rm origin
  85. git remote add origin "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${VERSIONS_REPO}.git" > /dev/null 2>&1
  86. cd ..
  87. if [[ "${OS_NAME}" == "osx" ]]; then
  88. ASSET_NAME=VSCodium-darwin-${VSCODE_ARCH}-${RELEASE_VERSION}.zip
  89. VERSION_PATH="${VSCODE_QUALITY}/darwin/${VSCODE_ARCH}"
  90. updateLatestVersion
  91. elif [[ "${OS_NAME}" == "windows" ]]; then
  92. # system installer
  93. ASSET_NAME=VSCodiumSetup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe
  94. VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/system"
  95. updateLatestVersion
  96. # user installer
  97. ASSET_NAME=VSCodiumUserSetup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe
  98. VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/user"
  99. updateLatestVersion
  100. # windows archive
  101. ASSET_NAME=VSCodium-win32-${VSCODE_ARCH}-${RELEASE_VERSION}.zip
  102. VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/archive"
  103. updateLatestVersion
  104. if [[ "${VSCODE_ARCH}" == "ia32" || "${VSCODE_ARCH}" == "x64" ]]; then
  105. # msi
  106. ASSET_NAME=VSCodium-${VSCODE_ARCH}-${RELEASE_VERSION}.msi
  107. VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi"
  108. updateLatestVersion
  109. # updates-disabled msi
  110. ASSET_NAME=VSCodium-${VSCODE_ARCH}-updates-disabled-${RELEASE_VERSION}.msi
  111. VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi-updates-disabled"
  112. updateLatestVersion
  113. fi
  114. else # linux
  115. # update service links to tar.gz file
  116. # see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION
  117. # as examples
  118. ASSET_NAME=VSCodium-linux-${VSCODE_ARCH}-${RELEASE_VERSION}.tar.gz
  119. VERSION_PATH="${VSCODE_QUALITY}/linux/${VSCODE_ARCH}"
  120. updateLatestVersion
  121. fi
  122. cd versions
  123. git pull origin master # in case another build just pushed
  124. git add .
  125. CHANGES=$( git status --porcelain )
  126. if [[ ! -z "${CHANGES}" ]]; then
  127. dateAndMonth=$( date "+%D %T" )
  128. git commit -m "CI update: ${dateAndMonth} (Build ${GITHUB_RUN_NUMBER})"
  129. if ! git push origin master --quiet; then
  130. git pull origin master
  131. git push origin master --quiet
  132. fi
  133. fi
  134. cd ..