magiatranslate-client/ci_build.sh
segfault-bilibili 2e4f815732
Automatic build with GitHub Actions (#5)
* extract armv7 lib; make build.bat immune to spaced path

* update submodules

1.update dobby to latest:
original commit hash: b0176de574104726bb68dff3b77ee666300fc338
plus compilation error fix

2.update untp to include plistlib fix

* fix build errors

1. define RS_SUCCESS in MagiaClient.cpp,
which was deleted in Dobby f4643b8d14d7cc94516b446ca77d952d0b986d50

2. fix dobby not being statically linked

* terminate build script on error

let build.sh exit on error
let build.bat fail if signing fails

* sign_example.bat: use zipalign and apksigner

* upgrade to apktool 2.7.0; check hash of apktool

* handle fake python3

* control whether to include audiofix

* build.bat: go back to base dir on exit

* update readme

* update suggested ndk path

* build and release with GitHub Actions

* avoid unnecessary rebuild

* remove nodejs dependency

fix Dobby so that we can implement audiofix in MagiaHook again

* automatic build

* update apktool to 2.8.1

* fix max method number exceeded
2023-08-10 20:11:14 +01:00

60 lines
2.4 KiB
Bash

#!/bin/bash
set -e
BASEDIR="$(realpath "$(dirname "${0}")")"
# prepare signing key
[[ "${KEYSTORE_BASE64}" == "" ]] && echo "KEYSTORE_BASE64 is not set" >&2 && exit 1
[[ "${KS_PASS}" == "" ]] && echo "KS_PASS is not set" >&2 && exit 1
echo "${KEYSTORE_BASE64}" | base64 -d > "${BASEDIR}/builder.jks" 2> /dev/null
KEYSTORE_ARGS="--ks \"${BASEDIR}/builder.jks\" --ks-pass \"pass:${KS_PASS}\""
[[ "${KEY_PASS}" != "" ]] && echo "KEY_PASS is set!" >&2 && KEYSTORE_ARGS="${KEYSTORE_ARGS} --key-pass \"pass:${KEY_PASS}\""
[[ "${KS_KEY_ALIAS}" != "" ]] && echo "KS_KEY_ALIAS is set!" >&2 && KEYSTORE_ARGS="${KEYSTORE_ARGS} --ks-key-alias \"${KS_KEY_ALIAS}\""
unset KEYSTORE_BASE64
unset KS_PASS
unset KEY_PASS
unset KS_KEY_ALIAS
cp sign_example.sh sign.sh
sed -E -i "s@^(\"\\\$\{APKSIGNER\}\" sign ).+( \"\\\$\{APK\}\")\$@\\1${KEYSTORE_ARGS}\\2@" sign.sh 2>&1 > /dev/null
sed -i "s@^KEYSTORE=.*@KEYSTORE=\"${BASEDIR}/builder.jks\"@" sign.sh 2>&1 > /dev/null
chmod +x sign.sh
# prepare source APKs
MT_VER=$(grep -P -o "(?<=^#define MT_VERSION )\d+$" src/Config.h)
. ci_versions/src_apk.sh
SRCAPK="${BASEDIR}/apk/src_${SRCAPK_VER}.apk"
export ARMV7SRCAPK="${BASEDIR}/armv7apk/armv7src_${SRCAPK_VER}.apk"
VERSION="v${SRCAPK_VER}_v${MT_VER}"
# load deps versions
. ci_versions/deps.sh
DEPS_DIR="${BASEDIR}/deps"
# prepare apktool
export MT_APKTOOL="apktool_${APKTOOL_VER}.jar"
mkdir -p "${BASEDIR}/build"
cp "${DEPS_DIR}/${MT_APKTOOL}" "${BASEDIR}/build/${MT_APKTOOL}"
# prepare Android SDK
SDK_ROOT="${DEPS_DIR}/Android/Sdk"
NDK="${SDK_ROOT}/ndk/${NDK_VER}"
CMAKE_BIN_DIR="${SDK_ROOT}/cmake/${CMAKE_VER}/bin"
BUILD_TOOLS_DIR="${SDK_ROOT}/build-tools/${BUILD_TOOLS_VER}"
export MT_CMAKE="${CMAKE_BIN_DIR}/cmake"
export MT_NINJA="${CMAKE_BIN_DIR}/ninja"
export MT_ZIPALIGN="${BUILD_TOOLS_DIR}/zipalign"
export MT_APKSIGNER="${BUILD_TOOLS_DIR}/apksigner"
RESULT="${BASEDIR}/build/io.kamihama.magiatranslate.${VERSION}.apk"
# build main APK which contains audiofix
MT_AUDIOFIX_3_0_1=Y "${BASEDIR}/build_release.sh" "${SRCAPK}" "${VERSION}" "${NDK}"
MAIN_APK="MagiaTranslate_${VERSION}.apk"
mv "${RESULT}" "${BASEDIR}/${MAIN_APK}"
echo "MAIN_APK=${MAIN_APK}" >> "$GITHUB_ENV"
# build failsafe APK which does not contain audiofix
MT_AUDIOFIX_3_0_1=N "${BASEDIR}/build_release.sh" "${SRCAPK}" "${VERSION}" "${NDK}"
FAILSAFE_APK="MagiaTranslate_${VERSION}_failsafe.apk"
mv "${RESULT}" "${BASEDIR}/${FAILSAFE_APK}"
echo "FAILSAFE_APK=${FAILSAFE_APK}" >> "$GITHUB_ENV"
rm "${BASEDIR}/builder.jks"