Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update apk generation and naming convention #2293

Merged
merged 10 commits into from
Jul 12, 2019
54 changes: 30 additions & 24 deletions exec/apk-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,55 @@ set -e
if [[ $CIRCLE_BRANCH != pull* ]]
then
export PUBLISH_BRANCH=${PUBLISH_BRANCH:-master}
export DEPLOY_BRANCH=${DEPLOY_BRANCH:-development}

git config --global user.name "Travis CI"
git config --global user.email "[email protected]"

./gradlew bundlePlayStoreRelease

git clone --quiet --branch=apk https://fossasia:[email protected]/fossasia/susi_android apk > /dev/null
ls
cd apk

if [ "$CIRCLE_BRANCH" == "$PUBLISH_BRANCH" ]; then
/bin/rm -f *
else
/bin/rm -f app-fdroid-debug.apk app-playStore-debug.apk app-playStore-release.apk app-fdroid-release.apk
fi
\cp -r ../app/build/outputs/apk/fdroid/*/**.apk .
\cp -r ../app/build/outputs/apk/playStore/*/**.apk .
\cp -r ../app/build/outputs/apk/fdroid/debug/output.json fdroidDebug-output.json
\cp -r ../app/build/outputs/apk/fdroid/release/output.json fdroidRelease-output.json
\cp -r ../app/build/outputs/apk/playStore/debug/output.json playStoreDebug-output.json
\cp -r ../app/build/outputs/apk/playStore/release/output.json playStoreRelease-output.json

# Signing App
if [ "$CIRCLE_BRANCH" == "$PUBLISH_BRANCH" ]; then
echo "Push to master branch detected, signing the app..."
\cp app-playStore-release-unsigned.apk app-playStore-release-unaligned.apk
jarsigner -verbose -tsa http://timestamp.comodoca.com/rfc3161 -sigalg SHA1withRSA -digestalg SHA1 -keystore ../exec/key.jks -storepass $STORE_PASS -keypass $KEY_PASS app-playStore-release-unaligned.apk $ALIAS
${ANDROID_HOME}/build-tools/27.0.3/zipalign -vfp 4 app-playStore-release-unaligned.apk app-playStore-release.apk
/bin/rm -f susiai-dev-*
fi

if [ "$CIRCLE_BRANCH" == "$PUBLISH_BRANCH" ]; then
for file in app*; do
cp $file susi-ai-master-${file%%}
done
fi
# Create a new branch that will contain only latest apk
find ../app/build/outputs -type f -name '*.apk' -exec cp -v {} . \;
find ../app/build/outputs -type f -name '*.aab' -exec cp -v {} . \;

for file in app*; do
if [ "$CIRCLE_BRANCH" == "$PUBLISH_BRANCH" ]; then
if [[ ${file} =~ ".aab" ]]; then
mv $file susiai-master-${file}
else
mv $file susiai-master-${file:4}
fi

elif [ "$CIRCLE_BRANCH" == "$DEPLOY_BRANCH" ]; then
if [[ ${file} =~ ".aab" ]]; then
mv $file susiai-dev-${file}
else
mv $file susiai-dev-${file:4}
fi

fi
done

# Create a new branch that will contain only latest apk
git checkout --orphan workaround

# Add generated APK
git add -A
git commit -am "[Circle CI] Update Susi Apk"
git commit -am "[Circle CI] Update Susi Apk ($(date +%Y-%m-%d.%H:%M:%S))"

# Delete current apk branch
git branch -D apk
# Rename current branch to apk
git branch -m apk
git branch -m apk

# Force push to origin since histories are unrelated
git push origin apk --force --quiet > /dev/null
Expand All @@ -57,6 +63,6 @@ then
if [ "$CIRCLE_BRANCH" == "$PUBLISH_BRANCH" ]; then
echo "Publishing app to Play Store"
gem install fastlane
fastlane supply --apk app-playStore-release.apk --track alpha --json_key ../exec/fastlane.json --package_name $PACKAGE_NAME
fastlane supply --aab susiai-master-app.aab --skip_upload_apk true --track alpha --json_key ../exec/fastlane.json --package_name $PACKAGE_NAME
fi
fi