From a5b2066f76e870ea294bf0b205239da506676213 Mon Sep 17 00:00:00 2001 From: Peter Squicciarini Date: Thu, 16 May 2019 10:41:32 -0700 Subject: [PATCH] Commit version JSON after deploy (#158) --- .travis.yml | 3 ++ get_repo.sh | 3 +- sum.sh | 1 + update_version.sh | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100755 update_version.sh diff --git a/.travis.yml b/.travis.yml index 4c68352df79..42b10668ab8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,3 +51,6 @@ deploy: on: all_branches: true condition: $SHOULD_BUILD = yes + +after_deploy: + - ./update_version.sh diff --git a/get_repo.sh b/get_repo.sh index ee03a0772fd..d859e011286 100755 --- a/get_repo.sh +++ b/get_repo.sh @@ -8,7 +8,8 @@ else cd vscode fi -export LATEST_MS_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) +export LATEST_MS_COMMIT=$(git rev-list --tags --max-count=1) +export LATEST_MS_TAG=$(git describe --tags ${LATEST_MS_COMMIT}) echo "Got the latest MS tag: ${LATEST_MS_TAG}" git checkout $LATEST_MS_TAG cd .. diff --git a/sum.sh b/sum.sh index 427378ec23e..1367666c9d4 100755 --- a/sum.sh +++ b/sum.sh @@ -3,6 +3,7 @@ sum_file () { if [[ -f "$1" ]]; then shasum -a 256 $1 > $1.sha256 + shasum $1 > $1.sha1 fi } diff --git a/update_version.sh b/update_version.sh new file mode 100755 index 00000000000..dd5a34d6d55 --- /dev/null +++ b/update_version.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +if [[ "$SHOULD_BUILD" != "yes" ]]; then + echo "Will not update version JSON because we did not build" + 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. +# darwin: https://github.com/VSCodium/vscodium/releases/download/${LATEST_MS_TAG}/VSCodium-darwin-${LATEST_MS_TAG}.zip +# `name` is $LATEST_MS_TAG +# `version` is $LATEST_MS_COMMIT +# `productVersion` is $LATEST_MS_TAG +# `hash` in .sha1 +# `timestamp` is $(node -e 'console.log(Date.now())') +# `sha256hash` in .sha256 + +URL_BASE=https://github.com/VSCodium/vscodium/releases/download/${LATEST_MS_TAG} + +if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + # zip, sha1, and sha256 files are all at top level dir + ASSET_PATH=. + ASSET_NAME=VSCodium-darwin-${LATEST_MS_TAG}.zip + VERSION_PATH="darwin" +elif [[ "$CI_WINDOWS" == "True" ]]; then + # TODO: make this logic work for Windows builds too + # or re-implement it in PowerShell and call that from the Windows build + exit +else # linux + # update service links to tar.gz file + # see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION + # and https://update.code.visualstudio.com/api/update/linux-ia32/stable/VERSION + # as examples + ASSET_PATH=. + ASSET_NAME=VSCodium-linux-${BUILDARCH}-${LATEST_MS_TAG}.tar.gz + VERSION_PATH="linux/${BUILDARCH}" +fi + +# generate parts +url=${URL_BASE}/${ASSET_NAME} +name=$LATEST_MS_TAG +version=$LATEST_MS_COMMIT +productVersion=$LATEST_MS_TAG +sha1hash=$(cat ${ASSET_PATH}/${ASSET_NAME}.sha1 | awk '{ print $ 1 }') +timestamp=$(node -e 'console.log(Date.now())') +sha256hash=$(cat ${ASSET_PATH}/${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 + if [[ "${!key}" == "" ]]; then + echo "Missing data for version update; exiting..." + exit 1 + fi +done + +# generate json +JSON=$(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' \ + <<<'{}') + +echo $JSON + +# clone down the current versions repo +# create/update the latest.json file in the correct location +# commit and push (thank you https://www.vinaygopinath.me/blog/tech/commit-to-master-branch-on-github-using-travis-ci/) +git clone https://github.com/VSCodium/versions.git +cd versions +git config user.email "travis@travis-ci.org" +git config user.name "Travis CI" +mkdir -p $VERSION_PATH +echo $JSON > $VERSION_PATH/latest.json +git add $VERSION_PATH +dateAndMonth=`date "+%D %T"` +git commit -m "Travis update: $dateAndMonth (Build $TRAVIS_BUILD_NUMBER)" +git remote rm origin +git remote add origin https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/VSCodium/versions.git > /dev/null 2>&1 +git push origin master --quiet