Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
10bits committed Feb 16, 2021
1 parent fbe8efc commit fe7b9f6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 55 deletions.
40 changes: 17 additions & 23 deletions action_app_custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source $GITHUB_WORKSPACE/action_util.sh
#去除河蟹,默认启用
function app_clear_18plus()
{
if [[ "$APP_NAME" = "legado" ]]; then
if [[ "$APP_NAME" == "legado" ]]; then
debug "清空18PlusList.txt"
echo "">$APP_WORKSPACE/app/src/main/assets/18PlusList.txt
fi
Expand All @@ -13,7 +13,7 @@ function app_clear_18plus()
#修改桌面阅读名为阅读.A,安装多个阅读时候方便识别,默认启用
function app_rename()
{
if [[ "$APP_NAME" = "legado" ]] && [[ "$SECRETS_RENAME" = "true" ]]; then
if [[ "$APP_NAME" == "legado" ]] && [[ "$SECRETS_RENAME" == "true" ]]; then
debug "更改桌面启动名称"
sed 's/"app_name">阅读/"app_name">'"$APP_LAUNCH_NAME"'/' \
$APP_WORKSPACE/app/src/main/res/values-zh/strings.xml -i
Expand All @@ -26,17 +26,16 @@ function app_rename()
#删除一些用不到的资源
function app_resources_unuse()
{
if [[ "$APP_NAME" = "legado" ]]; then
if [[ "$APP_NAME" == "legado" ]]; then
debug "删除一些用不到的资源"
rm $APP_WORKSPACE/app/src/main/assets/bg -rf
#rm $APP_WORKSPACE/app/src/main/assets/web/new -rf
rm $APP_WORKSPACE/app/src/main/assets/bg -rf
fi
}

#最小化生成apk体积
function app_minify()
{
if [[ "$APP_NAME" = "legado" ]]; then
if [[ "$APP_NAME" == "legado" ]]; then
debug "缩小apk体积"
sed -e '/minifyEnabled/i\ shrinkResources true' \
-e 's/minifyEnabled false/minifyEnabled true/' \
Expand All @@ -47,7 +46,7 @@ function app_minify()
#和已有阅读共存,默认启用
function app_live_together()
{
if [[ "$APP_NAME" = "legado" ]]; then
if [[ "$APP_NAME" == "legado" ]]; then
debug "解决安装程序共存问题"
sed "s/'.release'/'.release$APP_SUFFIX'/" \
$APP_WORKSPACE/app/build.gradle -i
Expand All @@ -69,7 +68,7 @@ function app_sign()
#禁用一些库
function app_not_apply_plugin()
{
if [[ "$APP_NAME" = "MyBookshelf" ]]; then
if [[ "$APP_NAME" == "MyBookshelf" ]]; then
debug "删除google services相关"
sed -e '/io.fabric/d' \
-e '/com.google.firebase/d' \
Expand All @@ -78,25 +77,20 @@ function app_not_apply_plugin()
fi
}

#进入收尾工作
function app_other()
{
if [[ "$APP_NAME" = "MyBookshelf" ]]; then
debug "$APP_NAME 解压MyBookshelf_Keys.zip"
unzip -o $APP_WORKSPACE/app/MyBookshelf_Keys.zip -d $APP_WORKSPACE/app
rm $APP_WORKSPACE/app/gradle.properties
#sed 's/com.gedoor.monkeybook/com.kunfei.bookshelf/' $APP_WORKSPACE/app/build.gradle -i
fi
}
#签名
app_sign;

#通用
app_sign
[[ "$SECRETS_MINIFY" = "true" ]] && app_minify
#是否启用资源压缩,默认不压缩
[[ "$SECRETS_MINIFY" == "true" ]] && app_minify;

#阅读3.0
app_clear_18plus;app_rename;app_live_together;app_resources_unuse
app_clear_18plus;
app_rename;
app_live_together;
app_resources_unuse;

#自用定制脚本
source $GITHUB_WORKSPACE/action_legado_myself.sh

#阅读2.0
app_not_apply_plugin
app_not_apply_plugin;
60 changes: 42 additions & 18 deletions action_legado_myself.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/bin/sh
source $GITHUB_WORKSPACE/action_util.sh
#阅读3.0自用定制脚本
if [[ "$APP_NAME" = "legado" ]] && [[ "$REPO_ACTOR" = "10bits" ]]; then

function build_gradle_setting()
{
debug "maven中央仓库回归"
sed "/google()/i\ mavenCentral()" $APP_WORKSPACE/build.gradle -i

debug "Speed Up Gradle"
sed -e '/android {/r '"$GITHUB_WORKSPACE/.github/legado/speedup.gradle"'' \
-e '/kapt {/a\ useBuildCache = true' \
$APP_WORKSPACE/app/build.gradle -i
}

function bookshelfAdd_no_alert()
{
debug "关闭加入书架提示"
find $APP_WORKSPACE/app/src -regex '.*/ReadBookActivity.kt' -exec \
sed -e '/fun finish()/,/fun onDestroy()/{s/alert/\/*&/;s/show()/&*\//}' \
-e '/!ReadBook.inBookshelf/a\viewModel.removeFromBookshelf{ super.finish() }' \
{} -i \;
}

function exploreShow_be_better()
{
debug "发现书籍界面优化"
find $APP_WORKSPACE/app/src -regex '.*/ExploreShowActivity.kt' -exec \
sed -e "/loadMoreView.error(it)/i\isLoading = false" \
Expand All @@ -15,21 +32,21 @@ if [[ "$APP_NAME" = "legado" ]] && [[ "$REPO_ACTOR" = "10bits" ]]; then
{} -i \;
find $APP_WORKSPACE/app/src -regex '.*/ExploreShowViewModel.kt' -exec \
sed "s/30000L/8000L/" {} -i \;

debug "关闭加入书架提示"
find $APP_WORKSPACE/app/src -regex '.*/ReadBookActivity.kt' -exec \
sed -e '/fun finish()/,/fun onDestroy()/{s/alert/\/*&/;s/show()/&*\//}' \
-e '/!ReadBook.inBookshelf/a\viewModel.removeFromBookshelf{ super.finish() }' \
{} -i \;

}

function explore_can_search()
{
debug "发现界面支持搜索书籍"
find $APP_WORKSPACE/app/src -regex '.*/ExploreFragment.kt' -exec \
sed -e 's/getString(R.string.screen_find)/"搜索书籍、书源"/' \
-e '/fun initSearchView()/i\override fun onResume(){super.onResume();searchView.clearFocus()}' \
-e '/ExploreFragment/i\import io.legado.app.ui.book.search.SearchActivity' \
-e '/onQueryTextSubmit/a\if(!query?.contains("group:")!!){startActivity<SearchActivity> { putExtra("key", query) }}' \
{} -i \;
}

function rhino_safe_js()
{
debug "safe JsExtensions.kt"
if version_ge "$APP_TAG" "3.21.021012"; then
sed -e '/^import io.legado.app.App$/c\import splitties.init.appCtx' \
Expand All @@ -38,19 +55,26 @@ if [[ "$APP_NAME" = "legado" ]] && [[ "$REPO_ACTOR" = "10bits" ]]; then
fi
find $APP_WORKSPACE/app/src -type d -regex '.*/app/help' -exec \
cp $GITHUB_WORKSPACE/.github/fake/safe_JsExtensions.kt {}/JsExtensions.kt \;

debug "开启Rhino安全沙箱,移步https://github.com/10bits/rhino-android"
sed "/gedoor:rhino-android/c\ implementation 'com.github.10bits:rhino-android:1.6'" $APP_WORKSPACE/app/build.gradle -i

sed "/gedoor:rhino-android/c\ implementation 'com.github.10bits:rhino-android:1.6'" \
$APP_WORKSPACE/app/build.gradle -i
}

function no_google_services()
{
debug "删除google services相关"
sed -e "/com.google.firebase/d" \
-e "/com.google.gms/d" \
-e "/androidx.appcompat/a\ implementation 'androidx.documentfile:documentfile:1.0.1'" \
$APP_WORKSPACE/app/build.gradle -i
}

debug "Speed Up Gradle"
sed -e '/android {/r '"$GITHUB_WORKSPACE/.github/legado/speedup.gradle"'' \
-e '/kapt {/a\ useBuildCache = true' \
$APP_WORKSPACE/app/build.gradle -i

fi
if [[ "$APP_NAME" == "legado" ]] && [[ "$REPO_ACTOR" == "10bits" ]]; then
exploreShow_be_better;
bookshelfAdd_no_alert;
build_gradle_setting;
explore_can_search;
no_google_services;
rhino_safe_js;
fi
28 changes: 14 additions & 14 deletions action_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)"

function update_info()
{
cd $GITHUB_WORKSPACE
if version_gt $APP_LATEST_TAG $APP_LAST_TAG; then
sed "5c > 最新构建下载:[$APP_RELEASE_NAME]($APP_DOWNLOAD) 上次构建时间:$APP_LATEST_CHECK" README.md -i
sed "1i $APP_LATEST_TAG" .lastcheck -i
git config user.name github-actions
git config user.email github-actions@github.com
git commit -a -m "$APP_NAME-$APP_LATEST_TAG release"
git push
fi
cd $GITHUB_WORKSPACE
if version_gt $APP_LATEST_TAG $APP_LAST_TAG; then
sed "5c > 最新构建下载:[$APP_RELEASE_NAME]($APP_DOWNLOAD) 上次构建时间:$APP_LATEST_CHECK" README.md -i
sed "1i $APP_LATEST_TAG" .lastcheck -i
git config user.name github-actions
git config user.email github-actions@github.com
git commit -a -m "$APP_NAME-$APP_LATEST_TAG release"
git push
fi
}

function webdav_upload()
{
if [[ "$WEBDAV_UPLOAD" = "true" ]] && [[ -n "$WEBDAV_AUTH" ]] && [[ -n "$WEBDAV_URL" ]] && [[ "$REPO_OWNER" = "$REPO_ACTOR" ]]; then
debug "已开启webdav上传"
curl -X MKCOL -u $WEBDAV_AUTH $WEBDAV_URL
curl -u $WEBDAV_AUTH -T $1 $WEBDAV_URL
fi
if [[ "$WEBDAV_UPLOAD" == "true" ]] && [[ -n "$WEBDAV_AUTH" ]] && [[ -n "$WEBDAV_URL" ]] && [[ "$REPO_OWNER" == "$REPO_ACTOR" ]]; then
debug "已开启webdav上传"
curl -X MKCOL -u $WEBDAV_AUTH $WEBDAV_URL
curl -u $WEBDAV_AUTH -T $1 $WEBDAV_URL
fi
}

0 comments on commit fe7b9f6

Please sign in to comment.