release apk
All checks were successful
Release / meta (push) Successful in 24s
Release / linux-build (push) Successful in 1m15s
Release / android-build (push) Successful in 48m22s
Release / release-dev (push) Successful in 6s
Release / release-master (push) Successful in 59s

This commit is contained in:
2025-12-14 10:05:01 +00:00
parent f0dfbd185b
commit eb01cf0e8e
4 changed files with 195 additions and 100 deletions

View File

@@ -81,16 +81,63 @@ jobs:
- name: Flutter dependencies - name: Flutter dependencies
run: flutter pub get run: flutter pub get
- name: Build APK (release) - name: Prepare Android keystore (optional)
if: ${{ secrets.ANDROID_KEYSTORE_BASE64 != '' }}
run: | run: |
flutter build apk --release echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > android-release-key.jks
cp build/app/outputs/flutter-apk/app-release.apk app-release.apk echo "ANDROID_KEYSTORE_PATH=$PWD/android-release-key.jks" >> "$GITHUB_ENV"
echo "ANDROID_KEYSTORE_PASSWORD=${{ secrets.ANDROID_KEYSTORE_PASSWORD }}" >> "$GITHUB_ENV"
echo "ANDROID_KEY_ALIAS=${{ secrets.ANDROID_KEY_ALIAS }}" >> "$GITHUB_ENV"
echo "ANDROID_KEY_PASSWORD=${{ secrets.ANDROID_KEY_PASSWORD }}" >> "$GITHUB_ENV"
- name: Build Android App Bundle (release)
run: flutter build appbundle --release
- name: Download bundletool
run: |
BUNDLETOOL_VERSION=1.15.6
curl -fsSL -o bundletool.jar "https://github.com/google/bundletool/releases/download/${BUNDLETOOL_VERSION}/bundletool-all-${BUNDLETOOL_VERSION}.jar"
- name: Extract universal APK from bundle
env:
BASE_VERSION: ${{ needs.meta.outputs.base_version }}
run: |
set -euo pipefail
BUNDLE="build/app/outputs/bundle/release/app-release.aab"
OUTPUT_APKS="app-release.apks"
APK_NAME="mileograph-${BASE_VERSION}.apk"
if [ ! -f "$BUNDLE" ]; then
echo "Bundle not found at $BUNDLE"
exit 1
fi
SIGNING_ARGS=()
if [ -n "${ANDROID_KEYSTORE_PATH:-}" ] && [ -f "$ANDROID_KEYSTORE_PATH" ]; then
SIGNING_ARGS+=(--ks="$ANDROID_KEYSTORE_PATH")
SIGNING_ARGS+=(--ks-pass="pass:${ANDROID_KEYSTORE_PASSWORD}")
SIGNING_ARGS+=(--ks-key-alias="${ANDROID_KEY_ALIAS}")
KEY_PASS="${ANDROID_KEY_PASSWORD:-$ANDROID_KEYSTORE_PASSWORD}"
SIGNING_ARGS+=(--key-pass="pass:${KEY_PASS}")
else
echo "No release keystore provided; bundletool will sign with the debug keystore."
fi
java -jar bundletool.jar build-apks \
--bundle="$BUNDLE" \
--output="$OUTPUT_APKS" \
--mode=universal \
"${SIGNING_ARGS[@]}"
unzip -p "$OUTPUT_APKS" universal.apk > "$APK_NAME"
ls -lh "$APK_NAME"
- name: Upload Android APK artifact - name: Upload Android APK artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: android-apk name: android-apk
path: app-release.apk path: mileograph-${{ needs.meta.outputs.base_version }}.apk
linux-build: linux-build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -157,54 +204,36 @@ jobs:
name: android-apk name: android-apk
path: artifacts path: artifacts
- name: Download Linux bundle - name: Prepare APK and tag
if: ${{ github.ref == 'refs/heads/dev' }}
uses: actions/download-artifact@v3
with:
name: linux-bundle
path: artifacts
- name: Download Windows bundle (optional)
if: ${{ github.ref == 'refs/heads/dev' && env.BUILD_WINDOWS == 'true' }}
uses: actions/download-artifact@v3
with:
name: windows-zip
path: artifacts
- name: Prepare artefacts and tag
if: ${{ github.ref == 'refs/heads/dev' }} if: ${{ github.ref == 'refs/heads/dev' }}
id: bundle id: bundle
run: | run: |
BASE="${{ needs.meta.outputs.base_version }}" BASE="${{ needs.meta.outputs.base_version }}"
TAG="v${BASE}-dev" TAG="v${BASE}-dev.${{ github.run_number }}"
mv artifacts/app-release.apk "artifacts/app-${BASE}-dev.apk" mv "artifacts/mileograph-${BASE}.apk" "artifacts/mileograph-${BASE}-dev.apk"
mv artifacts/app-linux-x64.tar.gz "artifacts/app-linux-x64-${BASE}-dev.tar.gz"
if [ -f artifacts/app-windows-x64.zip ]; then
mv artifacts/app-windows-x64.zip "artifacts/app-windows-x64-${BASE}-dev.zip"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT" echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "files=artifacts/*" >> "$GITHUB_OUTPUT" echo "apk=artifacts/mileograph-${BASE}-dev.apk" >> "$GITHUB_OUTPUT"
- name: Create prerelease on Gitea - name: Create prerelease on Gitea
if: ${{ github.ref == 'refs/heads/dev' }} if: ${{ github.ref == 'refs/heads/dev' }}
uses: ncipollo/release-action@v1 uses: ncipollo/release-action@v1
with: with:
tag: v${{ needs.meta.outputs.base_version }}-dev.${{ github.run_number }} tag: ${{ steps.bundle.outputs.tag }}
name: v${{ needs.meta.outputs.base_version }}-dev build ${{ github.run_number }} name: v${{ needs.meta.outputs.base_version }}-dev build ${{ github.run_number }}
prerelease: true prerelease: true
commit: ${{ github.sha }} commit: ${{ github.sha }}
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.GITEA_TOKEN }}
# NOTE: no `artifacts:` here # NOTE: no `artifacts:` here
- name: Attach artefacts to Gitea release - name: Attach APK to Gitea release
if: ${{ github.ref == 'refs/heads/dev' }} if: ${{ github.ref == 'refs/heads/dev' }}
run: | run: |
set -euo pipefail set -euo pipefail
BASE="${{ needs.meta.outputs.base_version }}" TAG="${{ steps.bundle.outputs.tag }}"
TAG="v${BASE}-dev.${{ github.run_number }}" APK="${{ steps.bundle.outputs.apk }}"
# 1. Find release ID by tag # 1. Find release ID by tag
RELEASE_JSON=$(curl -sS \ RELEASE_JSON=$(curl -sS \
@@ -215,19 +244,16 @@ jobs:
echo "Release ID: $RELEASE_ID" echo "Release ID: $RELEASE_ID"
# 2. Upload each artefact with multipart/form-data # 2. Upload APK with multipart/form-data
for f in artifacts/*; do NAME=$(basename "$APK")
[ -f "$f" ] || continue echo "Uploading $NAME"
NAME=$(basename "$f")
echo "Uploading $NAME"
curl -sS -X POST \ curl -sS -X POST \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \ -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-F "attachment=@${f}" \ -F "attachment=@${APK}" \
-F "name=${NAME}" \ -F "name=${NAME}" \
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \ "${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
>/dev/null >/dev/null
done
release-master: release-master:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -236,6 +262,15 @@ jobs:
- android-build - android-build
- linux-build - linux-build
steps: steps:
- name: Install jq
run: |
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
else
SUDO=""
fi
$SUDO apt-get update
$SUDO apt-get install -y jq
- name: Download Android APK - name: Download Android APK
if: ${{ github.ref == 'refs/heads/master' }} if: ${{ github.ref == 'refs/heads/master' }}
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
@@ -243,35 +278,15 @@ jobs:
name: android-apk name: android-apk
path: artifacts path: artifacts
- name: Download Linux bundle - name: Prepare APK and tag
if: ${{ github.ref == 'refs/heads/master' }}
uses: actions/download-artifact@v3
with:
name: linux-bundle
path: artifacts
- name: Download Windows bundle (optional)
if: ${{ github.ref == 'refs/heads/master' && env.BUILD_WINDOWS == 'true' }}
uses: actions/download-artifact@v3
with:
name: windows-zip
path: artifacts
- name: Prepare artefacts and tag
if: ${{ github.ref == 'refs/heads/master' }} if: ${{ github.ref == 'refs/heads/master' }}
id: bundle id: bundle
run: | run: |
BASE="${{ needs.meta.outputs.base_version }}" BASE="${{ needs.meta.outputs.base_version }}"
TAG="v${BASE}" TAG="v${BASE}"
mv artifacts/app-release.apk "artifacts/app-${BASE}.apk"
mv artifacts/app-linux-x64.tar.gz "artifacts/app-linux-x64-${BASE}.tar.gz"
if [ -f artifacts/app-windows-x64.zip ]; then
mv artifacts/app-windows-x64.zip "artifacts/app-windows-x64-${BASE}.zip"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT" echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "files=artifacts/*" >> "$GITHUB_OUTPUT" echo "apk=artifacts/mileograph-${BASE}.apk" >> "$GITHUB_OUTPUT"
- name: Create release on Gitea - name: Create release on Gitea
if: ${{ github.ref == 'refs/heads/master' }} if: ${{ github.ref == 'refs/heads/master' }}
@@ -281,4 +296,32 @@ jobs:
name: ${{ steps.bundle.outputs.tag }} name: ${{ steps.bundle.outputs.tag }}
prerelease: false prerelease: false
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.GITEA_TOKEN }}
artifacts: ${{ steps.bundle.outputs.files }} commit: ${{ github.sha }}
- name: Attach APK to Gitea release
if: ${{ github.ref == 'refs/heads/master' }}
run: |
set -euo pipefail
TAG="${{ steps.bundle.outputs.tag }}"
APK="${{ steps.bundle.outputs.apk }}"
# 1. Find release ID by tag
RELEASE_JSON=$(curl -sS \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/tags/${TAG}")
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id')
echo "Release ID: $RELEASE_ID"
# 2. Upload APK with multipart/form-data
NAME=$(basename "$APK")
echo "Uploading $NAME"
curl -sS -X POST \
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
-F "attachment=@${APK}" \
-F "name=${NAME}" \
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
>/dev/null

View File

@@ -1,3 +1,5 @@
import java.util.Properties
plugins { plugins {
id("com.android.application") id("com.android.application")
id("kotlin-android") id("kotlin-android")
@@ -5,6 +7,28 @@ plugins {
id("dev.flutter.flutter-gradle-plugin") id("dev.flutter.flutter-gradle-plugin")
} }
val keystoreProperties = Properties()
val keystorePropertiesFile = rootProject.file("key.properties")
if (keystorePropertiesFile.exists()) {
keystorePropertiesFile.inputStream().use { keystoreProperties.load(it) }
}
val releaseStoreFile = System.getenv("ANDROID_KEYSTORE_PATH")
?: keystoreProperties.getProperty("storeFile")
val releaseStorePassword = System.getenv("ANDROID_KEYSTORE_PASSWORD")
?: keystoreProperties.getProperty("storePassword")
val releaseKeyAlias = System.getenv("ANDROID_KEY_ALIAS")
?: keystoreProperties.getProperty("keyAlias")
val releaseKeyPassword = System.getenv("ANDROID_KEY_PASSWORD")
?: keystoreProperties.getProperty("keyPassword")
val hasReleaseKeystore = listOf(
releaseStoreFile,
releaseStorePassword,
releaseKeyAlias,
releaseKeyPassword
).all { !it.isNullOrBlank() }
android { android {
namespace = "com.example.mileograph_flutter" namespace = "com.example.mileograph_flutter"
compileSdk = flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
@@ -30,11 +54,21 @@ android {
versionName = flutter.versionName versionName = flutter.versionName
} }
signingConfigs {
if (hasReleaseKeystore) {
create("release") {
storeFile = file(releaseStoreFile!!)
storePassword = releaseStorePassword
keyAlias = releaseKeyAlias!!
keyPassword = releaseKeyPassword
}
}
}
buildTypes { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. // Use a real release keystore when provided; fall back to debug keys otherwise.
// Signing with the debug keys for now, so `flutter run --release` works. signingConfig = signingConfigs.getByName(if (hasReleaseKeystore) "release" else "debug")
signingConfig = signingConfigs.getByName("debug")
} }
} }
} }

View File

@@ -83,11 +83,16 @@ class _NewEntryPageState extends State<NewEntryPage> {
Widget _buildTripSelector(BuildContext context) { Widget _buildTripSelector(BuildContext context) {
final trips = context.watch<DataService>().tripList; final trips = context.watch<DataService>().tripList;
final sorted = [...trips]..sort((a, b) => b.tripId.compareTo(a.tripId)); final sorted = [...trips]..sort((a, b) => b.tripId.compareTo(a.tripId));
final tripIds = sorted.map((t) => t.tripId).toSet();
final selectedValue =
(_selectedTripId != null && tripIds.contains(_selectedTripId))
? _selectedTripId
: null;
return Row( return Row(
children: [ children: [
Expanded( Expanded(
child: DropdownButtonFormField<int>( child: DropdownButtonFormField<int?>(
value: _selectedTripId, value: selectedValue,
decoration: const InputDecoration( decoration: const InputDecoration(
labelText: 'Trip', labelText: 'Trip',
border: OutlineInputBorder(), border: OutlineInputBorder(),
@@ -96,7 +101,7 @@ class _NewEntryPageState extends State<NewEntryPage> {
const DropdownMenuItem(value: null, child: Text('No trip')), const DropdownMenuItem(value: null, child: Text('No trip')),
...sorted.map( ...sorted.map(
(t) => (t) =>
DropdownMenuItem(value: t.tripId, child: Text(t.tripName)), DropdownMenuItem<int?>(value: t.tripId, child: Text(t.tripName)),
), ),
], ],
onChanged: (val) { onChanged: (val) {
@@ -350,9 +355,10 @@ class _NewEntryPageState extends State<NewEntryPage> {
_notesController.clear(); _notesController.clear();
_mileageController.clear(); _mileageController.clear();
_networkController.clear(); _networkController.clear();
final now = DateTime.now();
setState(() { setState(() {
_selectedDate = DateTime.now(); _selectedDate = now;
_selectedTime = TimeOfDay.now(); _selectedTime = TimeOfDay.fromDateTime(now);
_useManualMileage = false; _useManualMileage = false;
_routeResult = null; _routeResult = null;
_tractionItems _tractionItems
@@ -600,18 +606,9 @@ class _NewEntryPageState extends State<NewEntryPage> {
_buildTractionList(), _buildTractionList(),
]); ]);
final mileagePanel = _section('Mileage', [ final mileagePanel = _section(
SwitchListTile( 'Mileage',
title: const Text('Use manual mileage'), [
subtitle: const Text('Turn on to enter mileage manually'),
value: _useManualMileage,
onChanged: (val) {
setState(() {
_useManualMileage = val;
});
_saveDraft();
},
),
if (_useManualMileage) if (_useManualMileage)
TextFormField( TextFormField(
controller: _mileageController, controller: _mileageController,
@@ -635,12 +632,21 @@ class _NewEntryPageState extends State<NewEntryPage> {
Align( Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: ElevatedButton.icon( child: ElevatedButton.icon(
onPressed: _openCalculator, onPressed: _openCalculator,
icon: const Icon(Icons.calculate), icon: const Icon(Icons.calculate),
label: const Text('Open mileage calculator'), label: const Text('Open mileage calculator'),
),
), ),
]); ),
],
trailing: FilterChip(
label: Text(_useManualMileage ? 'Manual' : 'Automatic'),
selected: _useManualMileage,
onSelected: (val) {
setState(() => _useManualMileage = val);
_saveDraft();
},
),
);
return SingleChildScrollView( return SingleChildScrollView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
@@ -666,6 +672,14 @@ class _NewEntryPageState extends State<NewEntryPage> {
], ],
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
OutlinedButton.icon(
onPressed: _submitting
? null
: () => _resetFormState(clearDraft: true),
icon: const Icon(Icons.clear),
label: const Text('Clear form'),
),
const SizedBox(height: 8),
ElevatedButton.icon( ElevatedButton.icon(
onPressed: _submitting ? null : _submit, onPressed: _submitting ? null : _submit,
icon: _submitting icon: _submitting
@@ -767,18 +781,24 @@ class _NewEntryPageState extends State<NewEntryPage> {
); );
} }
Widget _section(String title, List<Widget> children) { Widget _section(String title, List<Widget> children, {Widget? trailing}) {
return Card( return Card(
child: Padding( child: Padding(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Text( Row(
title, mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: Theme.of( children: [
context, Text(
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold), title,
style: Theme.of(
context,
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
),
if (trailing != null) trailing,
],
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
...children.map( ...children.map(

View File

@@ -721,13 +721,11 @@ class _TractionPageState extends State<TractionPage> {
if (field.enumValues != null && field.enumValues!.isNotEmpty) { if (field.enumValues != null && field.enumValues!.isNotEmpty) {
final options = field.enumValues!.map((e) => e.toString()).toSet().toList(); final options = field.enumValues!.map((e) => e.toString()).toSet().toList();
final currentValue = _enumSelections[field.name]; final currentValue = _enumSelections[field.name];
if (currentValue != null && !options.contains(currentValue)) { final safeValue = options.contains(currentValue) ? currentValue : null;
options.insert(0, currentValue);
}
return SizedBox( return SizedBox(
width: width, width: width,
child: DropdownButtonFormField<String?>( child: DropdownButtonFormField<String?>(
value: currentValue, value: safeValue,
decoration: InputDecoration( decoration: InputDecoration(
labelText: field.display, labelText: field.display,
border: const OutlineInputBorder(), border: const OutlineInputBorder(),