diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..6013718bf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build APK + +on: + pull_request: + branches: + - development + push: + branches: + - development + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: app + steps: + - name: Set up Repository + uses: actions/checkout@v4 + + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: "3.27.2" + channel: "stable" + + - name: Get dependencies + run: flutter pub get + + - name: Ensure Build Script is Executable + run: chmod +x build.sh + + - name: Run Build Script + # shell: bash + run: | + ./build.sh --init + ./build.sh --build --production --debug + + - name: Verify APK Exists + run: | + if [ ! -f "build/app/outputs/flutter-apk/app-debug.apk" ]; then + echo "APK not found! Build failed." + exit 1 + fi + + - name: Upload APK Artifact + uses: actions/upload-artifact@v4 + with: + name: app-apk + path: app/build/app/outputs/flutter-apk/app-debug.apk diff --git a/app/android/app/build_production b/app/android/app/build_production index 304d7e0f6..841ab2c08 100644 --- a/app/android/app/build_production +++ b/app/android/app/build_production @@ -59,10 +59,10 @@ android { signingConfigs { release { - keyAlias localProperties.getProperty('keyAlias') - keyPassword localProperties.getProperty('keyPassword') - storeFile file(localProperties.getProperty('storeFile')) - storePassword localProperties.getProperty('storePassword') + // keyAlias localProperties.getProperty('keyAlias') + // keyPassword localProperties.getProperty('keyPassword') + // storeFile file(localProperties.getProperty('storeFile')) + // storePassword localProperties.getProperty('storePassword') } debug { diff --git a/app/android/app/build_testing b/app/android/app/build_testing index 304d7e0f6..841ab2c08 100644 --- a/app/android/app/build_testing +++ b/app/android/app/build_testing @@ -59,10 +59,10 @@ android { signingConfigs { release { - keyAlias localProperties.getProperty('keyAlias') - keyPassword localProperties.getProperty('keyPassword') - storeFile file(localProperties.getProperty('storeFile')) - storePassword localProperties.getProperty('storePassword') + // keyAlias localProperties.getProperty('keyAlias') + // keyPassword localProperties.getProperty('keyPassword') + // storeFile file(localProperties.getProperty('storeFile')) + // storePassword localProperties.getProperty('storePassword') } debug { diff --git a/app/build.sh b/app/build.sh index 385f0f398..8642f4c7b 100755 --- a/app/build.sh +++ b/app/build.sh @@ -7,22 +7,21 @@ logcurrent_time=$(date "+%H:%M:%S %d.%m.%Y") current_time=$(date "+%Y.%m.%d-%H.%M.%S") compileAndUpload() { - if [[ $2 == "--$5" ]] + if [[ $2 == "--$4" ]] then - switchConfigs "$5" + switchConfigs "$4" if [[ $1 == "--run" ]] then - echo "[$5]: Running." + echo "[$4]: Running." flutter run -t lib/main.dart elif [[ $1 == "--switch" ]] then - echo "[$5]: Switched configs." + echo "[$4]: Switched configs." else - echo "[$5]: Building apk." + echo "[$4]: Building apk." - setConfigsAndBuild - msgTelegramAndUploadToAppServer "$5" $4 + setConfigsAndBuild "$3" fi exit 0 @@ -43,27 +42,19 @@ switchConfigs() { cp android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_$1.png android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png cp ios/Runner/Info_$1 ios/Runner/Info.plist - - # cp android/app/google-services_$1 android/app/google-services.json - # cp ios/Runner/GoogleService-Info_$1 ios/Runner/GoogleService-Info.plist } setConfigsAndBuild() { sed -i -e "s/githashvalue/$githash/g" lib/helpers/env_config.dart sed -i -e "s/timevalue/$logcurrent_time/g" lib/helpers/env_config.dart - flutter build apk -t lib/main.dart -v --target-platform android-arm,android-arm64 --release -} - -msgTelegramAndUploadToAppServer () { - mv build/app/outputs/apk/release/app-release.apk "build/app/outputs/apk/release/$current_time-TF-Connect-$1-$githash.apk" - - scp "build/app/outputs/apk/release/$current_time-TF-Connect-$1-$githash.apk" jimber@192.168.3.10:/opt/apps/threefold/$1/ - - # curl --http1.1 -s -X POST "https://api.telegram.org/bot868129294:AAEd-UDDSru9zGeGklzWL6mPO33NovuXYqo/sendMessage" -d parse_mode=markdown -d chat_id=-1001186043363 -d parse_mode=markdown -d text="Type: *$1* %0AGit user: *$gituser* %0AGit branch: *$gitbranch* %0AGit hash: *$githash* %0ATime: *$logcurrent_time* %0AMessage: *$2* %0AURL: *https://apps.staging.jimber.io/threefold/$1/*" - # curl --http1.1 -s -X POST "https://api.telegram.org/bot868129294:AAEd-UDDSru9zGeGklzWL6mPO33NovuXYqo/sendDocument" -F chat_id=-1001186043363 -F document="@build/app/outputs/apk/release/$githash-TF-Connect-$1-$current_time.apk" - - paplay /usr/share/sounds/gnome/default/alerts/glass.ogg + if [[ "$1" == "--debug" ]]; then + echo "Running local debug build..." + flutter build apk -t lib/main.dart --target-platform android-arm,android-arm64 --debug + else + echo "Running release build..." + flutter build apk -t lib/main.dart --target-platform android-arm,android-arm64 --release + fi } generateFile () { @@ -87,8 +78,10 @@ then AndroidManifestMainPath=android/app/src/main/AndroidManifest.xml AndroidManifestDebugPath=android/app/src/debug/AndroidManifest.xml + env_configFilePath=lib/helpers/env_config.dart AppConfigLocalFilePath=lib/app_config_local.dart + ReflectablePath=lib/main.reflectable.dart BuildGradlePath=android/app/build.gradle @@ -113,13 +106,20 @@ then generateFile $AndroidManifestMainPath android/app/src/main/AndroidManifest_local generateFile $AndroidManifestDebugPath android/app/src/main/AndroidManifest_local + if ! test -f $ReflectablePath; then + echo "$ReflectablePath doesn't exist, generating ..." + dart run build_runner build + else + echo "$1 already exists." + fi + exit 0 fi -compileAndUpload "$1" "$2" "$3" "$4" "local" -compileAndUpload "$1" "$2" "$3" "$4" "testing" -compileAndUpload "$1" "$2" "$3" "$4" "staging" -compileAndUpload "$1" "$2" "$3" "$4" "production" +compileAndUpload "$1" "$2" "$3" "local" +compileAndUpload "$1" "$2" "$3" "testing" +compileAndUpload "$1" "$2" "$3" "staging" +compileAndUpload "$1" "$2" "$3" "production" echo "Syntax error." echo "Usage: ./build.sh --[[run|build|switch]] --[[local|testing|staging|production]]"