Skip to content

Commit 4357d0d

Browse files
committed
feat: close #308 with environment variables.
From now on, the app should be built with run_build scripts.
1 parent 7d6588c commit 4357d0d

File tree

5 files changed

+96
-21
lines changed

5 files changed

+96
-21
lines changed

.github/workflows/ci_android.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ jobs:
2525
flutter pub get
2626
flutter pub global activate intl_utils
2727
flutter pub global run intl_utils:generate
28-
29-
- name: Generate Models
30-
run: dart run build_runner build --delete-conflicting-outputs
3128
3229
- name: Import Secrets
3330
uses: actions/checkout@v2
@@ -44,7 +41,7 @@ jobs:
4441
4542
- name: Build APK
4643
run: |
47-
flutter build apk --release
44+
./run_build.sh android
4845
4946
- if: github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != 'nightly'
5047
name: Release

.github/workflows/ci_windows.yml

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ jobs:
3232
flutter pub global activate intl_utils
3333
flutter pub global run intl_utils:generate
3434
35-
- name: Generate Models
36-
run: dart run build_runner build --delete-conflicting-outputs
37-
3835
- name: Build Executable
3936
run: |
4037
flutter build windows --release

lib/page/subpage_settings.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ class SettingsSubpageState extends PlatformSubpageState<SettingsSubpage> {
10341034
Align(
10351035
alignment: Alignment.centerRight,
10361036
child: Text(
1037-
'${S.of(context).version} ${FlutterApp.versionName} build ${Pubspec.version.build.single}',
1037+
'${S.of(context).version} ${FlutterApp.versionName} build ${Pubspec.version.build.single} #${const String.fromEnvironment("GIT_HASH", defaultValue: "?")}',
10381038
textScaleFactor: 0.7,
10391039
style: const TextStyle(fontWeight: FontWeight.bold),
10401040
),

run_build.bat

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@echo off
2+
setlocal enabledelayedexpansion
3+
24
echo.
35
echo Warning: Before building task, ensure that you have uncommented
46
echo the line "signingConfig signingConfigs.release" in android/app/build.gradle,
@@ -7,6 +9,8 @@ echo.
79
set /P version_code=Input your version name to continue:
810
echo Start building...
911

12+
for /f %%i in ('git rev-parse --short HEAD') do set GIT_HASH=%%i
13+
1014
:exec_build_runner
1115
echo Executing build runner...
1216
echo.
@@ -17,15 +21,15 @@ echo Build for Android...
1721
echo.
1822
echo Clean old files...
1923
del /Q build\app\DanXi-%version_code%-release.android.apk
20-
start /WAIT cmd /C flutter build apk
24+
start /WAIT cmd /C flutter build apk --release --dart-define=GIT_HASH=!GIT_HASH!
2125
echo Move file...
2226
move build\app\outputs\flutter-apk\app-release.apk build\app\DanXi-%version_code%-release.android.apk
2327
echo.
2428

2529
:build_windows
2630
echo Build for Windows...
2731
echo.
28-
start /WAIT cmd /C flutter build windows
32+
start /WAIT cmd /C flutter build windows --release --dart-define=GIT_HASH=!GIT_HASH!
2933
echo Clean old files...
3034
del /Q build\app\DanXi-%version_code%-release.windows-x64.zip
3135
cd build\windows\runner\Release\
@@ -35,17 +39,13 @@ cd ..\..\..\..\
3539
echo.
3640

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

5050
:end_success
5151
echo Build success.

run_build.sh

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (C) 2024 DanXi-Dev
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
#
19+
20+
echo "Warning: Before building task, ensure that you have uncommented"
21+
echo "the line \"signingConfig signingConfigs.release\" in android/app/build.gradle,"
22+
echo "and choose your signing key in android/key.properties."
23+
echo
24+
read -p "Input your version name to continue: " version_code
25+
echo "Start building..."
26+
27+
# get current hash
28+
git_hash=$(git rev-parse --short HEAD)
29+
30+
ENV_FLAG="--dart-define=GIT_HASH=$git_hash"
31+
32+
exec_build_runner() {
33+
echo "Executing build runner..."
34+
dart run build_runner build --delete-conflicting-outputs
35+
}
36+
37+
build_android() {
38+
echo "Build for Android..."
39+
echo "Clean old files..."
40+
rm -f build/app/DanXi-$version_code-release.android.apk
41+
flutter build apk --release $ENV_FLAG
42+
echo "Copy file..."
43+
cp build/app/outputs/flutter-apk/app-release.apk build/app/DanXi-$version_code-release.android.apk
44+
echo
45+
}
46+
47+
build_windows() {
48+
echo "Build for Windows..."
49+
flutter build windows --release $ENV_FLAG
50+
echo "Clean old files..."
51+
rm -f build/app/DanXi-$version_code-release.windows-x64.zip
52+
pushd build/windows/runner/Release/
53+
echo "Copy file..."
54+
7z a -r -sse ../../../../build/app/DanXi-$version_code-release.windows-x64.zip *
55+
popd
56+
echo
57+
}
58+
59+
build_bundle() {
60+
echo "Build for Android App Bundle..."
61+
echo "Clean old files..."
62+
rm -f build/app/DanXi-$version_code-release.android.aab
63+
flutter build appbundle --release $ENV_FLAG
64+
echo "Copy file..."
65+
cp build/app/outputs/bundle/release/app-release.aab build/app/DanXi-$version_code-release.android.aab
66+
echo
67+
}
68+
69+
exec_build_runner
70+
71+
if [ "$1" == "android" ]; then
72+
build_android
73+
elif [ "$1" == "windows" ]; then
74+
build_windows
75+
elif [ "$1" == "aab" ]; then
76+
build_bundle
77+
else
78+
build_android
79+
build_windows
80+
build_bundle
81+
fi

0 commit comments

Comments
 (0)