forked from VSCodium/vscodium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_version.sh
executable file
·188 lines (151 loc) · 6.17 KB
/
update_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bash
# shellcheck disable=SC1091
set -e
if [[ "${SHOULD_BUILD}" != "yes" && "${FORCE_UPDATE}" != "true" ]]; then
echo "Will not update version JSON because we did not build"
exit 0
fi
if [[ -z "${GITHUB_TOKEN}" ]]; then
echo "Will not update version JSON because no GITHUB_TOKEN defined"
exit 0
fi
if [[ "${FORCE_UPDATE}" == "true" ]]; then
. version.sh
fi
if [[ -z "${BUILD_SOURCEVERSION}" ]]; then
echo "Will not update version JSON because no BUILD_SOURCEVERSION defined"
exit 0
fi
if [[ "${VSCODE_ARCH}" == "ppc64le" ]]; then
echo "Skip ppc64le since only reh is published"
exit 0
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/${ASSETS_REPOSITORY}/releases/download/${RELEASE_VERSION}/${APP_NAME}-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
REPOSITORY_NAME="${VERSIONS_REPOSITORY/*\//}"
URL_BASE="https://github.com/${ASSETS_REPOSITORY}/releases/download/${RELEASE_VERSION}"
generateJson() {
local url name version productVersion sha1hash sha256hash timestamp
JSON_DATA="{}"
# generate parts
url="${URL_BASE}/${ASSET_NAME}"
name="${RELEASE_VERSION}"
version="${BUILD_SOURCEVERSION}"
productVersion="${RELEASE_VERSION}"
timestamp=$( node -e 'console.log(Date.now())' )
if [[ ! -f "assets/${ASSET_NAME}" ]]; then
echo "Downloading asset '${ASSET_NAME}'"
gh release download --repo "${ASSETS_REPOSITORY}" "${RELEASE_VERSION}" --dir "assets" --pattern "${ASSET_NAME}*"
fi
sha1hash=$( awk '{ print $1 }' "assets/${ASSET_NAME}.sha1" )
sha256hash=$( awk '{ print $1 }' "assets/${ASSET_NAME}.sha256" )
# check that nothing is blank (blank indicates something awry with build)
for key in url name version productVersion sha1hash timestamp sha256hash; do
if [[ -z "${key}" ]]; then
echo "Variable '${key}' is empty; exiting..."
exit 1
fi
done
# generate json
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() {
echo "Updating ${VERSION_PATH}/latest.json"
# do not update the same version
if [[ -f "${REPOSITORY_NAME}/${VERSION_PATH}/latest.json" ]]; then
CURRENT_VERSION=$( jq -r '.name' "${REPOSITORY_NAME}/${VERSION_PATH}/latest.json" )
echo "CURRENT_VERSION: ${CURRENT_VERSION}"
if [[ "${CURRENT_VERSION}" == "${RELEASE_VERSION}" && "${FORCE_UPDATE}" != "true" ]]; then
return 0
fi
fi
echo "Generating ${VERSION_PATH}/latest.json"
mkdir -p "${REPOSITORY_NAME}/${VERSION_PATH}"
generateJson
echo "${JSON_DATA}" > "${REPOSITORY_NAME}/${VERSION_PATH}/latest.json"
echo "${JSON_DATA}"
}
# 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/
git clone "https://github.com/${VERSIONS_REPOSITORY}.git"
cd "${REPOSITORY_NAME}" || { echo "'${REPOSITORY_NAME}' dir not found"; exit 1; }
git config user.email "$( echo "${GITHUB_USERNAME}" | awk '{print tolower($0)}' )[email protected]"
git config user.name "${GITHUB_USERNAME} CI"
git remote rm origin
git remote add origin "https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${VERSIONS_REPOSITORY}.git" &> /dev/null
cd ..
if [[ "${OS_NAME}" == "osx" ]]; then
ASSET_NAME="${APP_NAME}-darwin-${VSCODE_ARCH}-${RELEASE_VERSION}.zip"
VERSION_PATH="${VSCODE_QUALITY}/darwin/${VSCODE_ARCH}"
updateLatestVersion
elif [[ "${OS_NAME}" == "windows" ]]; then
# system installer
ASSET_NAME="${APP_NAME}Setup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe"
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/system"
updateLatestVersion
# user installer
ASSET_NAME="${APP_NAME}UserSetup-${VSCODE_ARCH}-${RELEASE_VERSION}.exe"
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/user"
updateLatestVersion
# windows archive
ASSET_NAME="${APP_NAME}-win32-${VSCODE_ARCH}-${RELEASE_VERSION}.zip"
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/archive"
updateLatestVersion
if [[ "${VSCODE_ARCH}" == "ia32" || "${VSCODE_ARCH}" == "x64" ]]; then
# msi
ASSET_NAME="${APP_NAME}-${VSCODE_ARCH}-${RELEASE_VERSION}.msi"
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi"
updateLatestVersion
# updates-disabled msi
ASSET_NAME="${APP_NAME}-${VSCODE_ARCH}-updates-disabled-${RELEASE_VERSION}.msi"
VERSION_PATH="${VSCODE_QUALITY}/win32/${VSCODE_ARCH}/msi-updates-disabled"
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
ASSET_NAME="${APP_NAME}-linux-${VSCODE_ARCH}-${RELEASE_VERSION}.tar.gz"
VERSION_PATH="${VSCODE_QUALITY}/linux/${VSCODE_ARCH}"
updateLatestVersion
fi
cd "${REPOSITORY_NAME}" || { echo "'${REPOSITORY_NAME}' dir not found"; exit 1; }
git pull origin master # in case another build just pushed
git add .
CHANGES=$( git status --porcelain )
if [[ -n "${CHANGES}" ]]; then
echo "Some changes have been found, pushing them"
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
else
echo "No changes"
fi
cd ..