forked from caydey/ffshare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_build_release.sh
executable file
·75 lines (56 loc) · 2.32 KB
/
github_build_release.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
#!/bin/bash
GRADLE_LOCATION=./app/build.gradle
APP_NAME="FFShare"
APP_VERSION=$(grep -Po '(?<=versionName \").*(?=\")' "$GRADLE_LOCATION")
APP_VERSION_CODE=$(grep -Po '(?<=versionCode ).*' "$GRADLE_LOCATION")
# no pre-release version argument
if [ -z "$1" ]; then
./gradlew assembleRelease
else
PRE_VERSION_NAME="$1"
# create backup of gradle to revert back to after bumping version and assembling release
cp "$GRADLE_LOCATION" "$GRADLE_LOCATION.original"
# change app version to pre version and bumb version code
APP_VERSION="$PRE_VERSION_NAME"
APP_VERSION_CODE="$((APP_VERSION_CODE + 1))"
sed -i -e "s/versionName \".*\"/versionName \"${APP_VERSION}\"/g" "$GRADLE_LOCATION"
sed -i -e "s/versionCode .*/versionCode ${APP_VERSION_CODE}/g" "$GRADLE_LOCATION"
./gradlew assembleRelease
# revert to original gradle version after build finished
mv "$GRADLE_LOCATION.original" "$GRADLE_LOCATION"
fi
OUTPUT_FOLDER="./github_releases/$APP_VERSION"
mkdir -p "$OUTPUT_FOLDER" 2>/dev/null
rm -rf ./"${OUTPUT_FOLDER:?}"/* # clean if rebuild
APK_ROOT=./app/build/outputs/apk
for VARIANT_DIR in "$APK_ROOT"/*; do
variant=$(basename "$VARIANT_DIR")
for APK_FILE in "$VARIANT_DIR"/release/*.apk; do
abi=$(basename "$APK_FILE" | cut -d'-' -f3)
abi_bit="_$abi"
[[ "$abi" == 'universal' ]] && abi_bit=""
newApk="${APP_NAME}_${APP_VERSION}_${variant}${abi_bit}.apk"
cp "$APK_FILE" "$OUTPUT_FOLDER/$newApk"
done
done
changelog=$(cat "./fastlane/metadata/android/en-US/changelogs/$APP_VERSION_CODE.txt")
# title
echo "$APP_NAME $APP_VERSION" > "$OUTPUT_FOLDER/release"
# changelog
echo "=== Changelog ===" >> "$OUTPUT_FOLDER/release"
echo "$changelog" >> "$OUTPUT_FOLDER/release"
# apk info
echo """
=== APK Info ===
arm64 & armeabi - your phones CPU architecture, the only benefit of downloading these over the default one is a download size reduction
full - FFShare will compress videos, images and audio files (mp3/ogg/etc...)
video - FFShare will only compress videos and images
""" >> "$OUTPUT_FOLDER/release"
# sha256
echo "=== SHA256 ===" >> "$OUTPUT_FOLDER/release"
for apk in "$OUTPUT_FOLDER"/*.apk; do
sha=$(sha256sum "$apk" | awk '{ print $1 }')
size=$(du -hk "$apk" | awk '{ printf "%.1fM", $1/1024 }')
base=$(basename "$apk")
echo "$sha $base ($size)" >> "$OUTPUT_FOLDER/release"
done