update_version.sh 4.9 KB

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