1 Commits

Author SHA1 Message Date
eb01cf0e8e 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
2025-12-14 10:05:01 +00:00
4 changed files with 195 additions and 100 deletions

View File

@@ -81,16 +81,63 @@ jobs:
- name: Flutter dependencies
run: flutter pub get
- name: Build APK (release)
- name: Prepare Android keystore (optional)
if: ${{ secrets.ANDROID_KEYSTORE_BASE64 != '' }}
run: |
flutter build apk --release
cp build/app/outputs/flutter-apk/app-release.apk app-release.apk
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > android-release-key.jks
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
uses: actions/upload-artifact@v3
with:
name: android-apk
path: app-release.apk
path: mileograph-${{ needs.meta.outputs.base_version }}.apk
linux-build:
runs-on: ubuntu-latest
@@ -157,54 +204,36 @@ jobs:
name: android-apk
path: artifacts
- name: Download Linux bundle
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
- name: Prepare APK and tag
if: ${{ github.ref == 'refs/heads/dev' }}
id: bundle
run: |
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/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
mv "artifacts/mileograph-${BASE}.apk" "artifacts/mileograph-${BASE}-dev.apk"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "files=artifacts/*" >> "$GITHUB_OUTPUT"
echo "apk=artifacts/mileograph-${BASE}-dev.apk" >> "$GITHUB_OUTPUT"
- name: Create prerelease on Gitea
if: ${{ github.ref == 'refs/heads/dev' }}
uses: ncipollo/release-action@v1
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 }}
prerelease: true
commit: ${{ github.sha }}
token: ${{ secrets.GITEA_TOKEN }}
# NOTE: no `artifacts:` here
- name: Attach artefacts to Gitea release
- name: Attach APK to Gitea release
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
set -euo pipefail
BASE="${{ needs.meta.outputs.base_version }}"
TAG="v${BASE}-dev.${{ github.run_number }}"
TAG="${{ steps.bundle.outputs.tag }}"
APK="${{ steps.bundle.outputs.apk }}"
# 1. Find release ID by tag
RELEASE_JSON=$(curl -sS \
@@ -215,19 +244,16 @@ jobs:
echo "Release ID: $RELEASE_ID"
# 2. Upload each artefact with multipart/form-data
for f in artifacts/*; do
[ -f "$f" ] || continue
NAME=$(basename "$f")
echo "Uploading $NAME"
# 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=@${f}" \
-F "name=${NAME}" \
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
>/dev/null
done
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
release-master:
runs-on: ubuntu-latest
@@ -236,6 +262,15 @@ jobs:
- android-build
- linux-build
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
if: ${{ github.ref == 'refs/heads/master' }}
uses: actions/download-artifact@v3
@@ -243,35 +278,15 @@ jobs:
name: android-apk
path: artifacts
- name: Download Linux bundle
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
- name: Prepare APK and tag
if: ${{ github.ref == 'refs/heads/master' }}
id: bundle
run: |
BASE="${{ needs.meta.outputs.base_version }}"
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 "files=artifacts/*" >> "$GITHUB_OUTPUT"
echo "apk=artifacts/mileograph-${BASE}.apk" >> "$GITHUB_OUTPUT"
- name: Create release on Gitea
if: ${{ github.ref == 'refs/heads/master' }}
@@ -281,4 +296,32 @@ jobs:
name: ${{ steps.bundle.outputs.tag }}
prerelease: false
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 {
id("com.android.application")
id("kotlin-android")
@@ -5,6 +7,28 @@ plugins {
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 {
namespace = "com.example.mileograph_flutter"
compileSdk = flutter.compileSdkVersion
@@ -30,11 +54,21 @@ android {
versionName = flutter.versionName
}
signingConfigs {
if (hasReleaseKeystore) {
create("release") {
storeFile = file(releaseStoreFile!!)
storePassword = releaseStorePassword
keyAlias = releaseKeyAlias!!
keyPassword = releaseKeyPassword
}
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
// Use a real release keystore when provided; fall back to debug keys otherwise.
signingConfig = signingConfigs.getByName(if (hasReleaseKeystore) "release" else "debug")
}
}
}

View File

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

View File

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