Tachiyomi-Extensions/.github/scripts/sign-apks.sh

59 lines
1.4 KiB
Bash
Raw Normal View History

2020-11-13 00:22:02 +00:00
#!/bin/bash
set -e
shopt -s globstar nullglob extglob
2020-11-13 00:22:02 +00:00
TOOLS="$(ls -d ${ANDROID_HOME}/build-tools/* | tail -1)"
# Get APKs from previous jobs' artifacts
cp -R ~/apk-artifacts/ $PWD
2020-11-13 00:22:02 +00:00
APKS=( **/*".apk" )
# Fail if too little extensions seem to have been built
if [ "${#APKS[@]}" -le "1" ]; then
echo "Insufficient amount of APKs found. Please check the project configuration."
exit 1
else
echo "Signing ${#APKS[@]} APKs"
fi
2020-11-13 00:22:02 +00:00
# Take base64 encoded key input and put it into a file
STORE_PATH=$PWD/signingkey.jks
rm -f $STORE_PATH && touch $STORE_PATH
echo $1 | base64 -d > $STORE_PATH
STORE_ALIAS=$2
export KEY_STORE_PASSWORD=$3
export KEY_PASSWORD=$4
DEST=$PWD/apk
rm -rf $DEST && mkdir -p $DEST
MAX_PARALLEL=5
2021-02-13 00:56:38 +00:00
2020-11-13 00:22:02 +00:00
# Sign all of the APKs
for APK in ${APKS[@]}; do
2021-02-13 00:56:38 +00:00
(
echo "Signing $APK"
2021-02-13 00:56:38 +00:00
BASENAME=$(basename $APK)
APKNAME="${BASENAME%%+(-release*)}.apk"
APKDEST="$DEST/$APKNAME"
# AGP already zipaligns APKs
# ${TOOLS}/zipalign -c -v -p 4 $APK
2020-11-13 00:22:02 +00:00
2021-02-13 00:56:38 +00:00
cp $APK $APKDEST
${TOOLS}/apksigner sign --ks $STORE_PATH --ks-key-alias $STORE_ALIAS --ks-pass env:KEY_STORE_PASSWORD --key-pass env:KEY_PASSWORD $APKDEST
) &
2020-11-13 00:22:02 +00:00
2021-02-13 00:56:38 +00:00
# Allow to execute up to $MAX_PARALLEL jobs in parallel
if [[ $(jobs -r -p | wc -l) -ge $MAX_PARALLEL ]]; then
wait -n
fi
2020-11-13 00:22:02 +00:00
done
2021-02-13 00:56:38 +00:00
wait
2020-11-13 00:22:02 +00:00
rm $STORE_PATH
unset KEY_STORE_PASSWORD
unset KEY_PASSWORD