1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-08 20:12:39 +01:00
Frost-for-Facebook/generate-apk-release.sh

58 lines
2.4 KiB
Bash
Raw Normal View History

2017-06-02 03:09:43 +02:00
#!/usr/bin/env bash
# config
# make sure the GITHUB_API_KEY is encrypted and inside the travis file
# travis encrypt GITHUB_API_KEY=super_secret --add env.global
# Note - gradle 3.0.0 generates outputs in their own folders - ctrl + f > releaseTest
2017-06-02 03:09:43 +02:00
RELEASE_REPO=AllanWang/Frost-for-Facebook-APK-Builder
2017-11-10 07:06:27 +01:00
USER_AUTH=PitchedApps
EMAIL=pitchedapps@gmail.com
2017-06-02 03:09:43 +02:00
MODULE_NAME=app
VERSION_KEY=Frost
# Make version key different from module name
# create a new directory that will contain our generated apk
2019-07-03 23:25:48 +02:00
mkdir ${HOME}/${VERSION_KEY}/
2017-06-02 03:09:43 +02:00
# copy generated apk from build folder to the folder just created
2019-07-03 23:25:48 +02:00
cp -a ${MODULE_NAME}/build/outputs/apk/releaseTest/. ${HOME}/${VERSION_KEY}/
2019-07-03 23:22:34 +02:00
printf "Moved apks\n"
2019-07-03 23:25:48 +02:00
ls -a ${HOME}/${VERSION_KEY}
if [[ -z "$(find ${HOME}/${VERSION_KEY} -name '*.apk')" ]]; then
echo "No apks found"
exit 1
fi
2017-06-02 03:09:43 +02:00
# go to home and setup git
echo "Clone Git"
cd $HOME
git config --global user.email "$EMAIL"
git config --global user.name "$USER_AUTH CI"
# clone the repository in the buildApk folder
2019-07-03 23:25:48 +02:00
git clone --quiet --branch=master https://${USER_AUTH}:${GITHUB_API_KEY}@github.com/${RELEASE_REPO}.git master > /dev/null
2017-06-02 03:09:43 +02:00
# create version file
echo "Create Version File"
cd master
2019-07-03 23:25:48 +02:00
echo "${VERSION_KEY} v${TRAVIS_BUILD_NUMBER}" > "${VERSION_KEY}.txt"
2017-06-02 03:09:43 +02:00
echo "Push Version File"
git remote rm origin
2019-07-03 23:25:48 +02:00
git remote add origin https://${USER_AUTH}:${GITHUB_API_KEY}@github.com/${RELEASE_REPO}.git
2017-06-02 03:09:43 +02:00
git add -f .
2019-07-03 23:25:48 +02:00
git commit -m "Travis build ${TRAVIS_BUILD_NUMBER} pushed [skip ci]"
2017-06-02 03:09:43 +02:00
git push -fq origin master > /dev/null
echo "Create New Release"
2019-07-03 23:25:48 +02:00
API_JSON="$(printf '{"tag_name": "v%s","target_commitish": "master","name": "v%s","body": "Automatic Release v%s for branch %s %s","draft": false,"prerelease": false}' ${TRAVIS_BUILD_NUMBER} ${TRAVIS_BUILD_NUMBER} ${TRAVIS_BUILD_NUMBER} "\`${TRAVIS_BRANCH}\`" "\nhttps://github.com/${TRAVIS_REPO_SLUG}/commit/${TRAVIS_COMMIT}")"
newRelease="$(curl --data "${API_JSON}" https://api.github.com/repos/${RELEASE_REPO}/releases?access_token=${GITHUB_API_KEY})"
2017-06-02 03:09:43 +02:00
rID="$(echo "$newRelease" | jq ".id")"
2019-07-03 23:25:48 +02:00
cd ${HOME}/${VERSION_KEY}
2017-06-02 03:09:43 +02:00
echo "Push apk to $rID"
for apk in $(find *.apk -type f); do
apkName="${apk::-4}"
printf "Apk $apkName\n"
2019-07-03 23:25:48 +02:00
curl "https://uploads.github.com/repos/${RELEASE_REPO}/releases/${rID}/assets?access_token=${GITHUB_API_KEY}&name=${apkName}-v${TRAVIS_BUILD_NUMBER}.apk" --header 'Content-Type: application/zip' --upload-file ${apkName}.apk -X POST
done
2017-06-02 03:09:43 +02:00
echo -e "Done\n"