vscodium/update_version.sh

164 lines
5.3 KiB
Bash
Raw Normal View History

#!/bin/bash
2021-10-01 12:47:10 -04:00
set -e
if [[ "${SHOULD_BUILD}" != "yes" ]]; then
echo "Will not update version JSON because we did not build"
exit
fi
2021-10-01 12:47:10 -04:00
if [[ -z "${GITHUB_TOKEN}" ]]; then
echo "Will not update version JSON because no GITHUB_TOKEN defined"
exit
fi
# {
# "url": "https://az764295.vo.msecnd.net/stable/51b0b28134d51361cf996d2f0a1c698247aeabd8/VSCode-darwin-stable.zip",
# "name": "1.33.1",
# "version": "51b0b28134d51361cf996d2f0a1c698247aeabd8",
# "productVersion": "1.33.1",
# "hash": "cb4109f196d23b9d1e8646ce43145c5bb62f55a8",
# "timestamp": 1554971059007,
# "sha256hash": "ac2a1c8772501732cd5ff539a04bb4dc566b58b8528609d2b34bbf970d08cf01"
# }
# `url` is URL_BASE + filename of asset e.g.
2022-08-16 07:51:45 -04:00
# darwin: https://github.com/VSCodium/vscodium/releases/download/${RELEASE_VERSION}/VSCodium-darwin-${RELEASE_VERSION}.zip
# `name` is $RELEASE_VERSION
# `version` is $BUILD_SOURCEVERSION
# `productVersion` is $RELEASE_VERSION
# `hash` in <filename>.sha1
# `timestamp` is $(node -e 'console.log(Date.now())')
# `sha256hash` in <filename>.sha256
2022-08-29 09:13:25 -04:00
if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
URL_BASE="https://github.com/VSCodium/vscodium-insiders/releases/download/${RELEASE_VERSION}"
else
URL_BASE="https://github.com/VSCodium/vscodium/releases/download/${RELEASE_VERSION}"
fi
# to make testing on forks easier
VERSIONS_REPO="${GITHUB_USERNAME}/versions"
2021-10-01 12:47:10 -04:00
echo "Versions repo: ${VERSIONS_REPO}"
generateJson() {
2021-10-01 12:47:10 -04:00
JSON_DATA="{}"
# generate parts
2021-10-01 12:47:10 -04:00
local url="${URL_BASE}/${ASSET_NAME}"
2022-08-16 07:51:45 -04:00
local name="${RELEASE_VERSION}"
local version="${BUILD_SOURCEVERSION}"
local productVersion="${RELEASE_VERSION}"
local timestamp=$(node -e 'console.log(Date.now())')
2021-10-01 12:47:10 -04:00
if [[ ! -f "artifacts/${ASSET_NAME}" ]]; then
echo "Downloading artifact '${ASSET_NAME}'"
2022-08-16 07:51:45 -04:00
gh release download "${RELEASE_VERSION}" --dir "artifacts" --pattern "${ASSET_NAME}*"
2021-10-01 12:47:10 -04:00
fi
local sha1hash=$(cat "artifacts/${ASSET_NAME}.sha1" | awk '{ print $1 }')
local sha256hash=$(cat "artifacts/${ASSET_NAME}.sha256" | awk '{ print $1 }')
# check that nothing is blank (blank indicates something awry with build)
for key in url name version productVersion sha1hash timestamp sha256hash; do
2021-10-01 12:47:10 -04:00
if [[ -z "${key}" ]]; then
echo "Variable '${key}' is empty; exiting..."
exit 1
fi
done
# generate json
2021-10-01 12:47:10 -04:00
JSON_DATA=$(jq \
--arg url "${url}" \
--arg name "${name}" \
--arg version "${version}" \
--arg productVersion "${productVersion}" \
--arg hash "${sha1hash}" \
--arg timestamp "${timestamp}" \
--arg sha256hash "${sha256hash}" \
'. | .url=$url | .name=$name | .version=$version | .productVersion=$productVersion | .hash=$hash | .timestamp=$timestamp | .sha256hash=$sha256hash' \
<<<'{}')
}
updateLatestVersion() {
2021-10-01 12:47:10 -04:00
echo "Generating ${VERSION_PATH}/latest.json"
2021-10-01 12:47:10 -04:00
generateJson
cd versions
# create/update the latest.json file in the correct location
2021-10-01 12:47:10 -04:00
mkdir -p "${VERSION_PATH}"
echo "${JSON_DATA}" > "${VERSION_PATH}/latest.json"
cd ..
}
# init versions repo for later commiting + pushing the json file to it
# thank you https://www.vinaygopinath.me/blog/tech/commit-to-master-branch-on-github-using-travis-ci/
2021-10-01 12:47:10 -04:00
git clone "https://github.com/${VERSIONS_REPO}.git"
cd versions
git config user.email "vscodium-ci@not-real.com"
git config user.name "VSCodium CI"
git remote rm origin
2021-10-01 12:47:10 -04:00
git remote add origin "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${VERSIONS_REPO}.git" > /dev/null 2>&1
cd ..
2021-10-01 12:47:10 -04:00
if [[ "${OS_NAME}" == "osx" ]]; then
2022-08-16 07:51:45 -04:00
ASSET_NAME=VSCodium-darwin-${VSCODE_ARCH}-${RELEASE_VERSION}.zip
2022-08-29 09:13:25 -04:00
VERSION_PATH="${VSCODE_QUALITY}/darwin/${VSCODE_ARCH}"
2021-10-01 12:47:10 -04:00
updateLatestVersion
elif [[ "${OS_NAME}" == "windows" ]]; then
# system installer
2022-08-16 07:51:45 -04:00
ASSET_NAME=VSCodiumSetup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe
2022-08-29 09:13:25 -04:00
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/system"
2021-10-01 12:47:10 -04:00
updateLatestVersion
# user installer
2022-08-16 07:51:45 -04:00
ASSET_NAME=VSCodiumUserSetup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe
2022-08-29 09:13:25 -04:00
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/user"
2021-10-01 12:47:10 -04:00
updateLatestVersion
# windows archive
2022-08-16 07:51:45 -04:00
ASSET_NAME=VSCodium-win32-${VSCODE_ARCH}-${RELEASE_VERSION}.zip
2022-08-29 09:13:25 -04:00
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/archive"
2021-10-01 12:47:10 -04:00
updateLatestVersion
if [[ "${VSCODE_ARCH}" == "ia32" || "${VSCODE_ARCH}" == "x64" ]]; then
# msi
2022-08-16 07:51:45 -04:00
ASSET_NAME=VSCodium-${VSCODE_ARCH}-${RELEASE_VERSION}.msi
2022-08-29 09:13:25 -04:00
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi"
2021-10-01 12:47:10 -04:00
updateLatestVersion
# updates-disabled msi
2022-08-16 07:51:45 -04:00
ASSET_NAME=VSCodium-${VSCODE_ARCH}-updates-disabled-${RELEASE_VERSION}.msi
2022-08-29 09:13:25 -04:00
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi-updates-disabled"
2021-10-01 12:47:10 -04:00
updateLatestVersion
fi
else # linux
# update service links to tar.gz file
# see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION
# as examples
2022-08-16 07:51:45 -04:00
ASSET_NAME=VSCodium-linux-${VSCODE_ARCH}-${RELEASE_VERSION}.tar.gz
2022-08-29 09:13:25 -04:00
VERSION_PATH="${VSCODE_QUALITY}/linux/${VSCODE_ARCH}"
2021-10-01 12:47:10 -04:00
updateLatestVersion
fi
cd versions
2019-05-20 12:27:22 -04:00
git pull origin master # in case another build just pushed
git add .
2021-10-01 12:47:10 -04:00
CHANGES=$( git status --porcelain )
if [[ ! -z "${CHANGES}" ]]; then
dateAndMonth=$( date "+%D %T" )
git commit -m "CI update: ${dateAndMonth} (Build ${GITHUB_RUN_NUMBER})"
if ! git push origin master --quiet; then
git pull origin master
git push origin master --quiet
fi
2019-06-11 00:35:15 -04:00
fi
cd ..