Skip to content

Commit

Permalink
add build script and secret vars stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
NANI-SORE committed Feb 3, 2024
1 parent 6d0429b commit 826a651
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ windows/flutter/generated_plugin_registrant.h
# FVM files
.fvm/flutter_sdk

# Secret variables
/config/secrets.json


22 changes: 18 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,42 @@
{
"name": "loliSnatcher",
"request": "launch",
"type": "dart"
"type": "dart",
"preLaunchTask": "Create secrets config",
"args": [
"--dart-define-from-file=./config/secrets.json"
]
},
{
"name": "loliSnatcher (play store)",
"request": "launch",
"type": "dart",
"flutterMode": "profile",
"preLaunchTask": "Create secrets config",
"args": [
"--dart-define=LS_IS_STORE=true"
"--dart-define=LS_IS_STORE=true",
"--dart-define-from-file=./config/secrets.json"
]
},
{
"name": "loliSnatcher (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
"flutterMode": "profile",
"preLaunchTask": "Create secrets config",
"args": [
"--dart-define-from-file=./config/secrets.json"
]
},
{
"name": "loliSnatcher (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
"flutterMode": "release",
"preLaunchTask": "Create secrets config",
"args": [
"--dart-define-from-file=./config/secrets.json"
]
}
]
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Create secrets config",
"type": "shell",
"command": "sh ./gen_config.sh",
"presentation": {
"reveal": "never",
"close": true
},
"problemMatcher": []
}
]
}
11 changes: 6 additions & 5 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

def dartEnvironmentVariables = [
LS_IS_STORE: false
def dartEnvVars = [
LS_IS_STORE: false,
LS_IS_TESTING: false
];
if (project.hasProperty('dart-defines')) {
dartEnvironmentVariables = dartEnvironmentVariables + project.property('dart-defines')
dartEnvVars = dartEnvVars + project.property('dart-defines')
.split(',')
.collectEntries { entry ->
def pair = new String(entry.decodeBase64(), 'UTF-8').split('=')
[(pair.first()): pair.last()]
}
}
println("LS_IS_STORE=${dartEnvironmentVariables.LS_IS_STORE}")
def packageName = dartEnvironmentVariables.LS_IS_STORE == "true" ? "com.noaisu.play.loliSnatcher" : "com.noaisu.loliSnatcher"
println("LS_IS_STORE=${dartEnvVars.LS_IS_STORE}")
def packageName = dartEnvVars.LS_IS_STORE == "true" ? "com.noaisu.play.loliSnatcher" : "com.noaisu.loliSnatcher"
println("packageName=${packageName}")
// Build example
// flutter build apk --split-per-abi --dart-define=LS_IS_STORE=true
Expand Down
72 changes: 72 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

source scripts/select.sh

selected_item=0
menu_items=("Testing" "Github" "Store")
title="Select a build type (arrow keys to select, enter to confirm):"
run_menu "$title" "$selected_item" "${menu_items[@]}"
menu_result="$?"

echo

build_arg="LS_IS_STORE=false"
build_desc="Github"
build_mode="apk --split-per-abi"
suffix="github"
case "$menu_result"
in
0)
build_arg="LS_IS_STORE=false"
build_desc="Github"
suffix="github"
;;
1)
build_arg="LS_IS_TESTING=true"
build_desc="Testing"
suffix="test"
;;
2)
build_arg="LS_IS_STORE=true"
build_desc="Store"
build_mode="appbundle"
suffix="store"
;;
esac

echo "Doing a ["$build_desc"] build - [$build_mode --$build_arg]"
sh gen_config.sh
flutter build $build_mode --release --dart-define=$build_arg

get_version_and_build() {
version_and_build=$(grep "version:" pubspec.yaml | awk '{print $2}')
IFS='+' read -ra version_build_array <<< "$version_and_build"
version="${version_build_array[0]}"
build="${version_build_array[1]}"
}
get_version_and_build

if [ "$build_mode" = "appbundle" ]; then
src_aab="build/app/outputs/bundle/release/app-release.aab"
dest_aab="build/app/outputs/bundle/release/ls_${version}(${build})_appbundle_${suffix}.aab"
cp "$src_aab" "$dest_aab"

echo
echo "=> Built AAB: ls_${version}(${build})_appbundle_${suffix}.aab"
else
srcv8_apk="build/app/outputs/flutter-apk/app-arm64-v8a-release.apk"
destv8_apk="build/app/outputs/flutter-apk/ls_${version}(${build})_arm64-v8a_${suffix}.apk"
cp "$srcv8_apk" "$destv8_apk"

srcv7_apk="build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk"
destv7_apk="build/app/outputs/flutter-apk/ls_${version}(${build})_armeabi-v7a_${suffix}.apk"
cp "$srcv7_apk" "$destv7_apk"

src64_apk="build/app/outputs/flutter-apk/app-x86_64-release.apk"
dest64_apk="build/app/outputs/flutter-apk/ls_${version}(${build})_x86_64_${suffix}.apk"
cp "$src64_apk" "$dest64_apk"

echo
echo "=> Built APKs: ls_${version}(${build})_[arch]_${suffix}.apk"
fi

4 changes: 4 additions & 0 deletions gen_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if [ ! -f ./config/secrets.json ]; then
mkdir -p config
echo "{}" > config/secrets.json
fi
78 changes: 78 additions & 0 deletions scripts/select.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

function print_menu()
{
local title_item="$1"
shift
local selected_item="$1"
shift

local function_arguments=($@)
local menu_items=(${function_arguments[@]:0})
local menu_size="${#menu_items[@]}"
local menu_limit=$((menu_size - 1))

echo "$title_item"
for (( i = 0; i < $menu_size; ++i ))
do
if [ "$i" = "$selected_item" ]
then
echo "-> ${menu_items[i]}"
else
echo " ${menu_items[i]}"
fi
done
}

function run_menu()
{
local title_item="$1"
shift
local selected_item="$1"
shift

local function_arguments=($@)
local menu_items=(${function_arguments[@]:0})
local menu_size="${#menu_items[@]}"
local menu_limit=$((menu_size - 1))

clear
print_menu "$title_item" "$selected_item" "${menu_items[@]}"

while read -rsn1 input
do
case "$input"
in
$'\x1B') # ESC ASCII code (https://dirask.com/posts/ASCII-Table-pJ3Y0j)
read -rsn1 -t 0.1 input
if [ "$input" = "[" ] # occurs before arrow code
then
read -rsn1 -t 0.1 input
case "$input"
in
A) # Up Arrow
if [ "$selected_item" -ge 1 ]
then
selected_item=$((selected_item - 1))
clear
print_menu "$title_item" "$selected_item" "${menu_items[@]}"
fi
;;
B) # Down Arrow
if [ "$selected_item" -lt "$menu_limit" ]
then
selected_item=$((selected_item + 1))
clear
print_menu "$title_item" "$selected_item" "${menu_items[@]}"
fi
;;
esac
fi
read -rsn5 -t 0.1 # flushing stdin
;;
"") # Enter key
return "$selected_item"
;;
esac
done
}

0 comments on commit 826a651

Please sign in to comment.