2023-07-20 21:25:13 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# shellcheck disable=SC1091
|
2019-05-16 20:41:32 +03:00
|
|
|
|
2021-10-01 19:47:10 +03:00
|
|
|
set -e
|
|
|
|
|
2023-01-08 17:37:11 +03:00
|
|
|
if [[ "${SHOULD_BUILD}" != "yes" && "${FORCE_UPDATE}" != "true" ]]; then
|
2019-05-16 20:41:32 +03:00
|
|
|
echo "Will not update version JSON because we did not build"
|
2023-07-23 19:35:27 +03:00
|
|
|
exit 0
|
2019-05-16 20:41:32 +03:00
|
|
|
fi
|
|
|
|
|
2024-06-11 20:30:12 +03:00
|
|
|
if [[ -z "${GH_TOKEN}" ]] && [[ -z "${GITHUB_TOKEN}" ]] && [[ -z "${GH_ENTERPRISE_TOKEN}" ]] && [[ -z "${GITHUB_ENTERPRISE_TOKEN}" ]]; then
|
2021-10-01 19:47:10 +03:00
|
|
|
echo "Will not update version JSON because no GITHUB_TOKEN defined"
|
2023-07-23 19:35:27 +03:00
|
|
|
exit 0
|
2024-06-11 20:30:12 +03:00
|
|
|
else
|
|
|
|
GITHUB_TOKEN="${GH_TOKEN:-${GITHUB_TOKEN:-${GH_ENTERPRISE_TOKEN:-${GITHUB_ENTERPRISE_TOKEN}}}}"
|
2021-10-01 19:47:10 +03:00
|
|
|
fi
|
|
|
|
|
2024-06-11 20:30:12 +03:00
|
|
|
# Support for GitHub Enterprise
|
|
|
|
GH_HOST="${GH_HOST:-github.com}"
|
|
|
|
|
2023-01-08 18:08:05 +03:00
|
|
|
if [[ "${FORCE_UPDATE}" == "true" ]]; then
|
|
|
|
. version.sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${BUILD_SOURCEVERSION}" ]]; then
|
|
|
|
echo "Will not update version JSON because no BUILD_SOURCEVERSION defined"
|
2023-07-23 19:35:27 +03:00
|
|
|
exit 0
|
2023-01-08 18:08:05 +03:00
|
|
|
fi
|
|
|
|
|
2024-04-12 15:27:37 +03:00
|
|
|
if [[ "${VSCODE_ARCH}" == "ppc64le" ]] || [[ "${VSCODE_ARCH}" == "riscv64" ]] ; then
|
2024-06-11 17:56:15 +03:00
|
|
|
echo "Skip PPC64LE since only reh is published"
|
2023-07-23 19:35:27 +03:00
|
|
|
exit 0
|
2023-06-09 01:16:20 +03:00
|
|
|
fi
|
|
|
|
|
2019-05-16 20:41:32 +03:00
|
|
|
# {
|
|
|
|
# "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-10-06 23:15:41 +03:00
|
|
|
# darwin: https://github.com/${ASSETS_REPOSITORY}/releases/download/${RELEASE_VERSION}/${APP_NAME}-darwin-${RELEASE_VERSION}.zip
|
2022-08-16 14:51:45 +03:00
|
|
|
# `name` is $RELEASE_VERSION
|
|
|
|
# `version` is $BUILD_SOURCEVERSION
|
|
|
|
# `productVersion` is $RELEASE_VERSION
|
2019-05-16 20:41:32 +03:00
|
|
|
# `hash` in <filename>.sha1
|
|
|
|
# `timestamp` is $(node -e 'console.log(Date.now())')
|
|
|
|
# `sha256hash` in <filename>.sha256
|
|
|
|
|
2023-04-02 16:55:31 +03:00
|
|
|
REPOSITORY_NAME="${VERSIONS_REPOSITORY/*\//}"
|
2024-06-11 20:30:12 +03:00
|
|
|
URL_BASE="https://${GH_HOST}/${ASSETS_REPOSITORY}/releases/download/${RELEASE_VERSION}"
|
2019-05-18 05:47:03 +03:00
|
|
|
|
|
|
|
generateJson() {
|
2023-07-20 21:25:13 +03:00
|
|
|
local url name version productVersion sha1hash sha256hash timestamp
|
2021-10-01 19:47:10 +03:00
|
|
|
JSON_DATA="{}"
|
2019-05-18 05:47:03 +03:00
|
|
|
|
|
|
|
# generate parts
|
2023-07-20 21:25:13 +03:00
|
|
|
url="${URL_BASE}/${ASSET_NAME}"
|
|
|
|
name="${RELEASE_VERSION}"
|
|
|
|
version="${BUILD_SOURCEVERSION}"
|
|
|
|
productVersion="${RELEASE_VERSION}"
|
|
|
|
timestamp=$( node -e 'console.log(Date.now())' )
|
2019-05-18 05:47:03 +03:00
|
|
|
|
2022-10-06 23:15:41 +03:00
|
|
|
if [[ ! -f "assets/${ASSET_NAME}" ]]; then
|
|
|
|
echo "Downloading asset '${ASSET_NAME}'"
|
|
|
|
gh release download --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" --dir "assets" --pattern "${ASSET_NAME}*"
|
2021-10-01 19:47:10 +03:00
|
|
|
fi
|
|
|
|
|
2023-07-20 21:25:13 +03:00
|
|
|
sha1hash=$( awk '{ print $1 }' "assets/${ASSET_NAME}.sha1" )
|
|
|
|
sha256hash=$( awk '{ print $1 }' "assets/${ASSET_NAME}.sha256" )
|
2019-05-18 05:47:03 +03:00
|
|
|
|
|
|
|
# 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 19:47:10 +03:00
|
|
|
if [[ -z "${key}" ]]; then
|
|
|
|
echo "Variable '${key}' is empty; exiting..."
|
2019-05-18 05:47:03 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# generate json
|
2023-07-20 21:25:13 +03:00
|
|
|
JSON_DATA=$( jq \
|
2019-05-18 05:47:03 +03:00
|
|
|
--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' \
|
2023-07-20 21:25:13 +03:00
|
|
|
<<<'{}' )
|
2019-05-18 05:47:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
updateLatestVersion() {
|
2023-06-13 15:33:30 +03:00
|
|
|
echo "Updating ${VERSION_PATH}/latest.json"
|
2019-05-18 05:47:03 +03:00
|
|
|
|
2023-01-08 18:08:05 +03:00
|
|
|
# do not update the same version
|
2023-06-13 16:31:03 +03:00
|
|
|
if [[ -f "${REPOSITORY_NAME}/${VERSION_PATH}/latest.json" ]]; then
|
|
|
|
CURRENT_VERSION=$( jq -r '.name' "${REPOSITORY_NAME}/${VERSION_PATH}/latest.json" )
|
2023-06-13 15:33:30 +03:00
|
|
|
echo "CURRENT_VERSION: ${CURRENT_VERSION}"
|
2021-10-01 19:47:10 +03:00
|
|
|
|
2023-01-08 17:33:27 +03:00
|
|
|
if [[ "${CURRENT_VERSION}" == "${RELEASE_VERSION}" && "${FORCE_UPDATE}" != "true" ]]; then
|
2023-07-23 19:35:27 +03:00
|
|
|
return 0
|
2022-10-11 22:58:57 +03:00
|
|
|
fi
|
|
|
|
fi
|
2019-05-18 05:47:03 +03:00
|
|
|
|
2023-06-13 15:33:30 +03:00
|
|
|
echo "Generating ${VERSION_PATH}/latest.json"
|
|
|
|
|
2023-06-13 16:31:03 +03:00
|
|
|
mkdir -p "${REPOSITORY_NAME}/${VERSION_PATH}"
|
2022-10-11 22:58:57 +03:00
|
|
|
|
|
|
|
generateJson
|
2019-05-18 05:47:03 +03:00
|
|
|
|
2023-06-13 16:31:03 +03:00
|
|
|
echo "${JSON_DATA}" > "${REPOSITORY_NAME}/${VERSION_PATH}/latest.json"
|
2023-06-13 15:33:30 +03:00
|
|
|
|
|
|
|
echo "${JSON_DATA}"
|
2019-05-18 05:47:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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/
|
2024-06-11 20:30:12 +03:00
|
|
|
git clone "https://${GH_HOST}/${VERSIONS_REPOSITORY}.git"
|
2023-04-02 16:55:31 +03:00
|
|
|
cd "${REPOSITORY_NAME}" || { echo "'${REPOSITORY_NAME}' dir not found"; exit 1; }
|
2022-10-06 23:15:41 +03:00
|
|
|
git config user.email "$( echo "${GITHUB_USERNAME}" | awk '{print tolower($0)}' )-ci@not-real.com"
|
|
|
|
git config user.name "${GITHUB_USERNAME} CI"
|
2019-05-18 05:47:03 +03:00
|
|
|
git remote rm origin
|
2024-06-11 20:30:12 +03:00
|
|
|
git remote add origin "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@${GH_HOST}/${VERSIONS_REPOSITORY}.git" &> /dev/null
|
2019-05-18 05:47:03 +03:00
|
|
|
cd ..
|
|
|
|
|
2021-10-01 19:47:10 +03:00
|
|
|
if [[ "${OS_NAME}" == "osx" ]]; then
|
2022-10-06 23:15:41 +03:00
|
|
|
ASSET_NAME="${APP_NAME}-darwin-${VSCODE_ARCH}-${RELEASE_VERSION}.zip"
|
2022-08-29 16:13:25 +03:00
|
|
|
VERSION_PATH="${VSCODE_QUALITY}/darwin/${VSCODE_ARCH}"
|
2021-10-01 19:47:10 +03:00
|
|
|
updateLatestVersion
|
|
|
|
elif [[ "${OS_NAME}" == "windows" ]]; then
|
2019-07-10 01:25:17 +03:00
|
|
|
# system installer
|
2022-10-06 23:15:41 +03:00
|
|
|
ASSET_NAME="${APP_NAME}Setup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe"
|
2022-08-29 16:13:25 +03:00
|
|
|
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/system"
|
2021-10-01 19:47:10 +03:00
|
|
|
updateLatestVersion
|
2019-05-18 05:47:03 +03:00
|
|
|
|
|
|
|
# user installer
|
2022-10-06 23:15:41 +03:00
|
|
|
ASSET_NAME="${APP_NAME}UserSetup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe"
|
2022-08-29 16:13:25 +03:00
|
|
|
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/user"
|
2021-10-01 19:47:10 +03:00
|
|
|
updateLatestVersion
|
2019-05-18 05:47:03 +03:00
|
|
|
|
|
|
|
# windows archive
|
2022-10-06 23:15:41 +03:00
|
|
|
ASSET_NAME="${APP_NAME}-win32-${VSCODE_ARCH}-${RELEASE_VERSION}.zip"
|
2022-08-29 16:13:25 +03:00
|
|
|
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/archive"
|
2021-10-01 19:47:10 +03:00
|
|
|
updateLatestVersion
|
|
|
|
|
2021-09-09 02:38:07 +03:00
|
|
|
if [[ "${VSCODE_ARCH}" == "ia32" || "${VSCODE_ARCH}" == "x64" ]]; then
|
|
|
|
# msi
|
2022-10-06 23:15:41 +03:00
|
|
|
ASSET_NAME="${APP_NAME}-${VSCODE_ARCH}-${RELEASE_VERSION}.msi"
|
2022-08-29 16:13:25 +03:00
|
|
|
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi"
|
2021-10-01 19:47:10 +03:00
|
|
|
updateLatestVersion
|
|
|
|
|
2021-09-09 02:38:07 +03:00
|
|
|
# updates-disabled msi
|
2022-10-06 23:15:41 +03:00
|
|
|
ASSET_NAME="${APP_NAME}-${VSCODE_ARCH}-updates-disabled-${RELEASE_VERSION}.msi"
|
2022-08-29 16:13:25 +03:00
|
|
|
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi-updates-disabled"
|
2021-10-01 19:47:10 +03:00
|
|
|
updateLatestVersion
|
2021-09-09 02:38:07 +03:00
|
|
|
fi
|
2019-05-16 20:41:32 +03:00
|
|
|
else # linux
|
|
|
|
# update service links to tar.gz file
|
|
|
|
# see https://update.code.visualstudio.com/api/update/linux-x64/stable/VERSION
|
|
|
|
# as examples
|
2022-10-06 23:15:41 +03:00
|
|
|
ASSET_NAME="${APP_NAME}-linux-${VSCODE_ARCH}-${RELEASE_VERSION}.tar.gz"
|
2022-08-29 16:13:25 +03:00
|
|
|
VERSION_PATH="${VSCODE_QUALITY}/linux/${VSCODE_ARCH}"
|
2021-10-01 19:47:10 +03:00
|
|
|
updateLatestVersion
|
2019-05-16 20:41:32 +03:00
|
|
|
fi
|
|
|
|
|
2023-04-02 16:55:31 +03:00
|
|
|
cd "${REPOSITORY_NAME}" || { echo "'${REPOSITORY_NAME}' dir not found"; exit 1; }
|
2019-05-18 05:47:03 +03:00
|
|
|
|
2019-05-20 19:27:22 +03:00
|
|
|
git pull origin master # in case another build just pushed
|
2019-05-18 05:47:03 +03:00
|
|
|
git add .
|
2021-10-01 19:47:10 +03:00
|
|
|
|
|
|
|
CHANGES=$( git status --porcelain )
|
|
|
|
|
2023-07-20 21:25:13 +03:00
|
|
|
if [[ -n "${CHANGES}" ]]; then
|
2023-06-13 16:31:03 +03:00
|
|
|
echo "Some changes have been found, pushing them"
|
2023-06-13 16:24:24 +03:00
|
|
|
|
2021-10-01 19:47:10 +03:00
|
|
|
dateAndMonth=$( date "+%D %T" )
|
2023-06-13 16:24:24 +03:00
|
|
|
|
2021-10-01 19:47:10 +03:00
|
|
|
git commit -m "CI update: ${dateAndMonth} (Build ${GITHUB_RUN_NUMBER})"
|
2023-06-13 16:24:24 +03:00
|
|
|
|
2021-10-01 19:47:10 +03:00
|
|
|
if ! git push origin master --quiet; then
|
|
|
|
git pull origin master
|
|
|
|
git push origin master --quiet
|
|
|
|
fi
|
2023-06-13 16:24:24 +03:00
|
|
|
else
|
|
|
|
echo "No changes"
|
2019-06-11 07:35:15 +03:00
|
|
|
fi
|
2019-05-18 05:47:03 +03:00
|
|
|
|
|
|
|
cd ..
|