Skip to content

Commit

Permalink
feat: close #308 with environment variables.
Browse files Browse the repository at this point in the history
From now on, the app should be built with run_build scripts.
  • Loading branch information
w568w committed Mar 7, 2024
1 parent 7d6588c commit 4357d0d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 21 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ jobs:
flutter pub get
flutter pub global activate intl_utils
flutter pub global run intl_utils:generate
- name: Generate Models
run: dart run build_runner build --delete-conflicting-outputs
- name: Import Secrets
uses: actions/checkout@v2
Expand All @@ -44,7 +41,7 @@ jobs:
- name: Build APK
run: |
flutter build apk --release
./run_build.sh android
- if: github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != 'nightly'
name: Release
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
flutter pub global activate intl_utils
flutter pub global run intl_utils:generate
- name: Generate Models
run: dart run build_runner build --delete-conflicting-outputs

- name: Build Executable
run: |
flutter build windows --release
Expand Down
2 changes: 1 addition & 1 deletion lib/page/subpage_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ class SettingsSubpageState extends PlatformSubpageState<SettingsSubpage> {
Align(
alignment: Alignment.centerRight,
child: Text(
'${S.of(context).version} ${FlutterApp.versionName} build ${Pubspec.version.build.single}',
'${S.of(context).version} ${FlutterApp.versionName} build ${Pubspec.version.build.single} #${const String.fromEnvironment("GIT_HASH", defaultValue: "?")}',
textScaleFactor: 0.7,
style: const TextStyle(fontWeight: FontWeight.bold),
),
Expand Down
26 changes: 13 additions & 13 deletions run_build.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@echo off
setlocal enabledelayedexpansion

echo.
echo Warning: Before building task, ensure that you have uncommented
echo the line "signingConfig signingConfigs.release" in android/app/build.gradle,
Expand All @@ -7,6 +9,8 @@ echo.
set /P version_code=Input your version name to continue:
echo Start building...

for /f %%i in ('git rev-parse --short HEAD') do set GIT_HASH=%%i

:exec_build_runner
echo Executing build runner...
echo.
Expand All @@ -17,15 +21,15 @@ echo Build for Android...
echo.
echo Clean old files...
del /Q build\app\DanXi-%version_code%-release.android.apk
start /WAIT cmd /C flutter build apk
start /WAIT cmd /C flutter build apk --release --dart-define=GIT_HASH=!GIT_HASH!
echo Move file...
move build\app\outputs\flutter-apk\app-release.apk build\app\DanXi-%version_code%-release.android.apk
echo.

:build_windows
echo Build for Windows...
echo.
start /WAIT cmd /C flutter build windows
start /WAIT cmd /C flutter build windows --release --dart-define=GIT_HASH=!GIT_HASH!
echo Clean old files...
del /Q build\app\DanXi-%version_code%-release.windows-x64.zip
cd build\windows\runner\Release\
Expand All @@ -35,17 +39,13 @@ cd ..\..\..\..\
echo.

:build_app_bundle
REM echo Build for App Bundle (Google Play Distribution)...
REM echo.
REM echo Ensure that you have choose your signing key in android/key.properties.
REM echo.
REM echo Press any key to continue.
REM pause
REM echo Clean old files...
REM del /Q build\app\DanXi-%version_code%-release.android.aab
REM start /WAIT cmd /C flutter build appbundle
REM echo Move file...
REM move build\app\outputs\bundle\release\app-release.aab build\app\DanXi-%version_code%-release.android.aab
echo Build for App Bundle (Google Play Distribution)...
echo.
echo Clean old files...
del /Q build\app\DanXi-%version_code%-release.android.aab
start /WAIT cmd /C flutter build appbundle --release --dart-define=GIT_HASH=!GIT_HASH!
echo Move file...
move build\app\outputs\bundle\release\app-release.aab build\app\DanXi-%version_code%-release.android.aab

:end_success
echo Build success.
81 changes: 81 additions & 0 deletions run_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

#
# Copyright (C) 2024 DanXi-Dev
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

echo "Warning: Before building task, ensure that you have uncommented"
echo "the line \"signingConfig signingConfigs.release\" in android/app/build.gradle,"
echo "and choose your signing key in android/key.properties."
echo
read -p "Input your version name to continue: " version_code
echo "Start building..."

# get current hash
git_hash=$(git rev-parse --short HEAD)

ENV_FLAG="--dart-define=GIT_HASH=$git_hash"

exec_build_runner() {
echo "Executing build runner..."
dart run build_runner build --delete-conflicting-outputs
}

build_android() {
echo "Build for Android..."
echo "Clean old files..."
rm -f build/app/DanXi-$version_code-release.android.apk
flutter build apk --release $ENV_FLAG
echo "Copy file..."
cp build/app/outputs/flutter-apk/app-release.apk build/app/DanXi-$version_code-release.android.apk
echo
}

build_windows() {
echo "Build for Windows..."
flutter build windows --release $ENV_FLAG
echo "Clean old files..."
rm -f build/app/DanXi-$version_code-release.windows-x64.zip
pushd build/windows/runner/Release/
echo "Copy file..."
7z a -r -sse ../../../../build/app/DanXi-$version_code-release.windows-x64.zip *
popd
echo
}

build_bundle() {
echo "Build for Android App Bundle..."
echo "Clean old files..."
rm -f build/app/DanXi-$version_code-release.android.aab
flutter build appbundle --release $ENV_FLAG
echo "Copy file..."
cp build/app/outputs/bundle/release/app-release.aab build/app/DanXi-$version_code-release.android.aab
echo
}

exec_build_runner

if [ "$1" == "android" ]; then
build_android
elif [ "$1" == "windows" ]; then
build_windows
elif [ "$1" == "aab" ]; then
build_bundle
else
build_android
build_windows
build_bundle
fi

0 comments on commit 4357d0d

Please sign in to comment.