Skip to content

Commit d580d4c

Browse files
committed
Read sensible data from the env and do not rely to an external script anymore.
1 parent da5db0e commit d580d4c

File tree

1 file changed

+133
-21
lines changed

1 file changed

+133
-21
lines changed

tools/release/releaseScript.sh

Lines changed: 133 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,81 @@
1919
# Ignore any error to not stop the script
2020
set +e
2121

22-
printf "\n"
23-
printf "================================================================================\n"
22+
printf "\n================================================================================\n"
2423
printf "| Welcome to the release script! |\n"
2524
printf "================================================================================\n"
2625

27-
releaseScriptLocation="${RELEASE_SCRIPT_PATH}"
26+
printf "Checking environment...\n"
27+
envError=0
2828

29-
if [[ -z "${releaseScriptLocation}" ]]; then
30-
printf "Fatal: RELEASE_SCRIPT_PATH is not defined in the environment. Please set to the path of your local file 'releaseElement2.sh'.\n"
31-
exit 1
29+
# Path of the key store (it's a file)
30+
keyStorePath="${ELEMENT_KEYSTORE_PATH}"
31+
if [[ -z "${keyStorePath}" ]]; then
32+
printf "Fatal: ELEMENT_KEYSTORE_PATH is not defined in the environment.\n"
33+
envError=1
34+
fi
35+
# Keystore password
36+
keyStorePassword="${ELEMENT_KEYSTORE_PASSWORD}"
37+
if [[ -z "${keyStorePassword}" ]]; then
38+
printf "Fatal: ELEMENT_KEYSTORE_PASSWORD is not defined in the environment.\n"
39+
envError=1
40+
fi
41+
# Key password
42+
keyPassword="${ELEMENT_KEY_PASSWORD}"
43+
if [[ -z "${keyPassword}" ]]; then
44+
printf "Fatal: ELEMENT_KEY_PASSWORD is not defined in the environment.\n"
45+
envError=1
46+
fi
47+
# GitHub token
48+
gitHubToken="${ELEMENT_GITHUB_TOKEN}"
49+
if [[ -z "${gitHubToken}" ]]; then
50+
printf "Fatal: ELEMENT_GITHUB_TOKEN is not defined in the environment.\n"
51+
envError=1
52+
fi
53+
# Android home
54+
androidHome="${ANDROID_HOME}"
55+
if [[ -z "${androidHome}" ]]; then
56+
printf "Fatal: ANDROID_HOME is not defined in the environment.\n"
57+
envError=1
58+
fi
59+
# @elementbot:matrix.org matrix token / Not mandatory
60+
elementBotToken="${ELEMENT_BOT_MATRIX_TOKEN}"
61+
if [[ -z "${elementBotToken}" ]]; then
62+
printf "Warning: ELEMENT_BOT_MATRIX_TOKEN is not defined in the environment.\n"
3263
fi
3364

34-
releaseScriptFullPath="${releaseScriptLocation}/releaseElement2.sh"
35-
36-
if [[ ! -f ${releaseScriptFullPath} ]]; then
37-
printf "Fatal: release script not found at ${releaseScriptFullPath}.\n"
65+
if [ ${envError} == 1 ]; then
3866
exit 1
3967
fi
4068

69+
buildToolsVersion="30.0.2"
70+
buildToolsPath="${androidHome}/build-tools/${buildToolsVersion}"
71+
72+
if [[ ! -d ${buildToolsPath} ]]; then
73+
printf "Fatal: ${buildToolsPath} folder not found, ensure that you have installed the SDK version ${buildToolsVersion}.\n"
74+
exit 1
75+
fi
76+
4177
# Check if git flow is enabled
4278
git flow config >/dev/null 2>&1
4379
if [[ $? == 0 ]]
4480
then
45-
printf "Git flow is initialized"
81+
printf "Git flow is initialized\n"
4682
else
4783
printf "Git flow is not initialized. Initializing...\n"
4884
# All default value, just set 'v' for tag prefix
4985
git flow init -d -t 'v'
5086
fi
5187

88+
printf "OK\n"
89+
90+
printf "\n================================================================================\n"
5291
# Guessing version to propose a default version
5392
versionMajorCandidate=`grep "ext.versionMajor" ./vector-app/build.gradle | cut -d " " -f3`
5493
versionMinorCandidate=`grep "ext.versionMinor" ./vector-app/build.gradle | cut -d " " -f3`
5594
versionPatchCandidate=`grep "ext.versionPatch" ./vector-app/build.gradle | cut -d " " -f3`
5695
versionCandidate="${versionMajorCandidate}.${versionMinorCandidate}.${versionPatchCandidate}"
5796

58-
printf "\n"
5997
read -p "Please enter the release version (example: ${versionCandidate}). Just press enter if ${versionCandidate} is correct. " version
6098
version=${version:-${versionCandidate}}
6199

@@ -229,14 +267,89 @@ printf "Wait for the GitHub action https://github.com/vector-im/element-android/
229267
read -p "After GHA is finished, please enter the artifact URL (for 'vector-gplay-release-unsigned'): " artifactUrl
230268

231269
printf "\n================================================================================\n"
232-
printf "Running the release script...\n"
233-
cd ${releaseScriptLocation}
234-
${releaseScriptFullPath} "v${version}" ${artifactUrl}
235-
cd -
270+
printf "Downloading the artifact...\n"
271+
272+
# Download files
273+
targetPath="./tmp/Element/${version}"
274+
275+
# Ignore error
276+
set +e
277+
278+
python3 ./tools/release/download_github_artifacts.py \
279+
--token ${gitHubToken} \
280+
--artifactUrl ${artifactUrl} \
281+
--directory ${targetPath} \
282+
--ignoreErrors
283+
284+
# Do not ignore error
285+
set -e
286+
287+
printf "\n================================================================================\n"
288+
printf "Unzipping the artifact...\n"
289+
290+
unzip ${targetPath}/vector-gplay-release-unsigned.zip -d ${targetPath}
291+
292+
# Flatten folder hierarchy
293+
mv ${targetPath}/gplay/release/* ${targetPath}
294+
rm -rf ${targetPath}/gplay
295+
296+
printf "\n================================================================================\n"
297+
printf "Signing the APKs...\n"
298+
299+
cp ${targetPath}/vector-gplay-arm64-v8a-release-unsigned.apk \
300+
${targetPath}/vector-gplay-arm64-v8a-release-signed.apk
301+
./tools/release/sign_apk_unsafe.sh \
302+
${keyStorePath} \
303+
${targetPath}/vector-gplay-arm64-v8a-release-signed.apk \
304+
${keyStorePassword} \
305+
${keyPassword}
306+
307+
cp ${targetPath}/vector-gplay-armeabi-v7a-release-unsigned.apk \
308+
${targetPath}/vector-gplay-armeabi-v7a-release-signed.apk
309+
./tools/release/sign_apk_unsafe.sh \
310+
${keyStorePath} \
311+
${targetPath}/vector-gplay-armeabi-v7a-release-signed.apk \
312+
${keyStorePassword} \
313+
${keyPassword}
314+
315+
cp ${targetPath}/vector-gplay-x86-release-unsigned.apk \
316+
${targetPath}/vector-gplay-x86-release-signed.apk
317+
./tools/release/sign_apk_unsafe.sh \
318+
${keyStorePath} \
319+
${targetPath}/vector-gplay-x86-release-signed.apk \
320+
${keyStorePassword} \
321+
${keyPassword}
322+
323+
cp ${targetPath}/vector-gplay-x86_64-release-unsigned.apk \
324+
${targetPath}/vector-gplay-x86_64-release-signed.apk
325+
./tools/release/sign_apk_unsafe.sh \
326+
${keyStorePath} \
327+
${targetPath}/vector-gplay-x86_64-release-signed.apk \
328+
${keyStorePassword} \
329+
${keyPassword}
330+
331+
# Ref: https://docs.fastlane.tools/getting-started/android/beta-deployment/#uploading-your-app
332+
# set SUPPLY_APK_PATHS="${targetPath}/vector-gplay-arm64-v8a-release-unsigned.apk,${targetPath}/vector-gplay-armeabi-v7a-release-unsigned.apk,${targetPath}/vector-gplay-x86-release-unsigned.apk,${targetPath}/vector-gplay-x86_64-release-unsigned.apk"
333+
#
334+
# ./fastlane beta
335+
336+
printf "\n================================================================================\n"
337+
printf "Please check the information below:\n"
338+
339+
printf "File vector-gplay-arm64-v8a-release-signed.apk:\n"
340+
${buildToolsPath}/aapt dump badging ${targetPath}/vector-gplay-arm64-v8a-release-signed.apk | grep package
341+
printf "File vector-gplay-armeabi-v7a-release-signed.apk:\n"
342+
${buildToolsPath}/aapt dump badging ${targetPath}/vector-gplay-armeabi-v7a-release-signed.apk | grep package
343+
printf "File vector-gplay-x86-release-signed.apk:\n"
344+
${buildToolsPath}/aapt dump badging ${targetPath}/vector-gplay-x86-release-signed.apk | grep package
345+
printf "File vector-gplay-x86_64-release-signed.apk:\n"
346+
${buildToolsPath}/aapt dump badging ${targetPath}/vector-gplay-x86_64-release-signed.apk | grep package
347+
348+
read -p "\nDoes it look correct? Press enter when it's done."
236349

237350
printf "\n================================================================================\n"
238351
read -p "Installing apk on a real device, press enter when a real device is connected. "
239-
apkPath="${releaseScriptLocation}/Element/v${version}/vector-gplay-arm64-v8a-release-signed.apk"
352+
apkPath="${targetPath}/vector-gplay-arm64-v8a-release-signed.apk"
240353
adb -d install ${apkPath}
241354

242355
read -p "Please run the APK on your phone to check that the upgrade went well (no init sync, etc.). Press enter when it's done."
@@ -250,9 +363,8 @@ printf "Message for the Android internal room:\n\n"
250363
message="@room Element Android ${version} is ready to be tested. You can get if from https://github.com/vector-im/element-android/releases/tag/v${version}. Please report any feedback here. Thanks!"
251364
printf "${message}\n\n"
252365

253-
matrixOrgToken="${MATRIX_ORG_TOKEN}"
254-
if [[ -z "${matrixOrgToken}" ]]; then
255-
read -p "MATRIX_ORG_TOKEN is not defined in the environment. Cannot send the message for you. Please send it manually, and press enter when it's done "
366+
if [[ -z "${elementBotToken}" ]]; then
367+
read -p "ELEMENT_BOT_MATRIX_TOKEN is not defined in the environment. Cannot send the message for you. Please send it manually, and press enter when it's done "
256368
else
257369
read -p "Send this message to the room (yes/no) default to yes? " doSend
258370
doSend=${doSend:-yes}
@@ -261,7 +373,7 @@ else
261373
transactionId=`openssl rand -hex 16`
262374
# Element Android internal
263375
matrixRoomId="!LiSLXinTDCsepePiYW:matrix.org"
264-
curl -X PUT --data $"{\"msgtype\":\"m.text\",\"body\":\"${message}\"}" -H "Authorization: Bearer ${matrixOrgToken}" https://matrix-client.matrix.org/_matrix/client/r0/rooms/${matrixRoomId}/send/m.room.message/\$local.${transactionId}
376+
curl -X PUT --data $"{\"msgtype\":\"m.text\",\"body\":\"${message}\"}" -H "Authorization: Bearer ${elementBotToken}" https://matrix-client.matrix.org/_matrix/client/r0/rooms/${matrixRoomId}/send/m.room.message/\$local.${transactionId}
265377
else
266378
printf "Message not sent, please send it manually!\n"
267379
fi

0 commit comments

Comments
 (0)