From 92fb84c430ca537711faf79a68f5b01f8a102e1a Mon Sep 17 00:00:00 2001 From: Giorgio Azzinnaro Date: Sat, 21 Dec 2024 18:40:23 +0100 Subject: [PATCH] ci: github --- .github/workflows/build.yaml | 93 +++++++++++++++++++ android/app/build.gradle | 21 ++++- .../gradle/wrapper/gradle-wrapper.properties | 2 +- android/settings.gradle | 4 +- pubspec.lock | 8 ++ pubspec.yaml | 1 + test/widget_test.dart | 14 +++ 7 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..2e8b8e8 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,93 @@ +name: Build + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + flutter: + runs-on: ubuntu-latest + + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get Flutter + uses: subosito/flutter-action@v2 + with: + channel: 'stable' + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + + - name: Download dependencies + run: flutter pub get + + # - name: Run tests + # run: | + # flutter test + + - name: Compare pubspec version and git tag + id: pubspec_tag + run: | + PUBSPEC_VERSION=v$(grep -oP '^version:\s*\K[0-9]+\.[0-9]+\.[0-9]+' pubspec.yaml) + echo "Found version in pubspec.yaml: $PUBSPEC_VERSION" + echo "tag_name=$PUBSPEC_VERSION" >> $GITHUB_OUTPUT + + # This step prepares a draft release with the release notes generated from the commit messages, + # and the tag name from the pubspec.yaml file. It will only update the release if it is a draft + # and has not been published yet. If the release is already published, it will not be updated and fail. + # Once a version is published to the app store, the release should be marked as published. + - name: Create or update draft release + uses: ncipollo/release-action@v1 + with: + name: ${{ steps.pubspec_tag.outputs.tag_name }} + tag: ${{ steps.pubspec_tag.outputs.tag_name }} + generateReleaseNotes: true + makeLatest: true + draft: true + allowUpdates: true + updateOnlyUnreleased: true + + # - name: Configure git + # run: | + # git config --global user.name "GitHub Actions Bot" + # git config --global user.email "tech+gitbot@sealambda.com" + # git fetch origin gh-pages:gh-pages + # + # - name: Compile web and put in gh-pages branch + # run: dart run peanut + # + # - name: Push gh-pages + # run: git push origin gh-pages + + - name: Retrieve the Android keystore and key properties + env: + UPLOAD_KEYSTORE_B64: ${{ secrets.UPLOAD_KEYSTORE_B64 }} + KEY_PROPERTIES: ${{ secrets.KEY_PROPERTIES }} + run: | + echo "$UPLOAD_KEYSTORE_B64" | base64 --decode > android/keystore.jks + echo "$KEY_PROPERTIES" > android/key.properties + + - name: Compile Android app + run: flutter build appbundle --build-number ${{ github.run_number }} + + - name: Upload Android app to Play Store + uses: r0adkll/upload-google-play@v1 + with: + serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }} + packageName: com.sealambda.artificialstupidity + releaseFiles: build/app/outputs/bundle/release/app-release.aab + track: internal + status: completed + mappingFile: build/app/outputs/mapping/release/mapping.txt + debugSymbols: build/app/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib diff --git a/android/app/build.gradle b/android/app/build.gradle index bc1e764..cad3454 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -5,10 +5,18 @@ plugins { id "dev.flutter.flutter-gradle-plugin" } +def keystoreProperties = new Properties() +def keystorePropertiesFile = rootProject.file('key.properties') +if (keystorePropertiesFile.exists()) { + keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) +} + android { namespace = "com.sealambda.artificialstupidity" compileSdk = flutter.compileSdkVersion - ndkVersion = flutter.ndkVersion + // ndkVersion = flutter.ndkVersion + // This was failing as the Flutter NDK version is now 26 - which is not compatible with the Android Gradle Plugin + ndkVersion = "27.0.12077973" compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 @@ -30,11 +38,20 @@ android { versionName = flutter.versionName } + signingConfigs { + release { + keyAlias = keystoreProperties['keyAlias'] + keyPassword = keystoreProperties['keyPassword'] + storeFile = keystoreProperties['storeFile'] ? rootProject.file(keystoreProperties['storeFile']) : null + storePassword = keystoreProperties['storePassword'] + } + } + 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.debug + signingConfig = signingConfigs.release } } } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 7bb2df6..afa1e8e 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip diff --git a/android/settings.gradle b/android/settings.gradle index b9e43bd..c749982 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -18,8 +18,8 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.1.0" apply false - id "org.jetbrains.kotlin.android" version "1.8.22" apply false + id "com.android.application" version '8.7.3' apply false + id "org.jetbrains.kotlin.android" version "2.0.21" apply false } include ":app" diff --git a/pubspec.lock b/pubspec.lock index 9b9f3f1..0bf116d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -490,6 +490,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + mocktail: + dependency: "direct dev" + description: + name: mocktail + sha256: "890df3f9688106f25755f26b1c60589a92b3ab91a22b8b224947ad041bf172d8" + url: "https://pub.dev" + source: hosted + version: "1.0.4" nested: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 63c101f..1735f6c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -80,6 +80,7 @@ dev_dependencies: build_runner: ^2.4.13 freezed: ^2.5.7 json_serializable: ^6.9.0 + mocktail: ^1.0.4 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/test/widget_test.dart b/test/widget_test.dart index 9f20e16..c3326ca 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -10,9 +10,23 @@ import 'dart:async'; import 'package:artificialstupidity/app/app.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:hydrated_bloc/hydrated_bloc.dart'; +import 'package:mocktail/mocktail.dart'; import 'package:receive_sharing_intent/receive_sharing_intent.dart'; +class MockStorage extends Mock implements Storage {} + void main() { + late Storage storage; + + setUp(() { + storage = MockStorage(); + when( + () => storage.write(any(), any()), + ).thenAnswer((_) async {}); + HydratedBloc.storage = storage; + }); + testWidgets('Receive SharedMediaFile', (WidgetTester tester) async { final streamController = StreamController>();