diff --git a/.github/workflows/build_apk.yml b/.github/workflows/build_apk.yml index 54ba110..3ea2ed2 100644 --- a/.github/workflows/build_apk.yml +++ b/.github/workflows/build_apk.yml @@ -3,29 +3,73 @@ # separate terms of service, privacy policy, and support # documentation. -name: Build .apk +name: Build Android + +run-name: Build Android (${{ inputs.binary-type == 'apk' && '.apk' || '.aab' }}) v${{ inputs.version }} on: - workflow_dispatch: + workflow_call: inputs: - flavor: - description: 'Flavor' - type: choice + version: + description: "Version" + required: true + type: string + binary-type: + description: "Binary type" + type: string + required: true + flavor: + description: "Flavor" + type: string required: true - options: - - dev - - prod - default: 'dev' include-iap: type: boolean description: Include IAP package default: true + stage-backend: + type: boolean + description: Use stage backend + default: true + workflow_dispatch: + inputs: + version: + description: "Version" + required: true + type: string + binary-type: + description: "Binary type" + type: choice + required: true + options: + - apk + - appbundle + flavor: + description: "Flavor" + type: choice + required: true + options: + - dev + - prod + default: dev + include-iap: + type: boolean + description: Include IAP package + default: true + stage-backend: + type: boolean + description: Use stage backend + default: true + +env: + BUILD_ARGS: --release --flavor ${{ inputs.flavor }} -t lib/main_${{ inputs.flavor }}.dart + BUILD_APK_PATH: build/app/outputs/flutter-apk/app-${{ inputs.flavor }}-release.apk + BUILD_AAB_PATH: build/app/outputs/bundle/${{ inputs.flavor }}Release/app-${{ inputs.flavor }}-release.aab jobs: - build: - name: Build .apk + build-android: + name: Build ${{ inputs.binary-type == 'apk' && '.apk' || '.aab' }} runs-on: macos-11 - timeout-minutes: 15 + timeout-minutes: 30 steps: - uses: actions/checkout@v3 with: @@ -40,57 +84,48 @@ jobs: - name: Override iap package with stub if: ${{ !inputs.include-iap }} run: bash ./.github/scripts/stub_iap.sh - - - uses: actions/setup-java@v2 + + - uses: actions/setup-java@v3 with: distribution: "zulu" java-version: "11" - name: Restore Android keystore .jsk and .properties files - env: - KEYSTORE: ${{ secrets.KEYSTORE }} - KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }} run: | - KEYSTORE_PATH=$RUNNER_TEMP/keystore.jks - echo -n "$KEYSTORE" | base64 --decode --output $KEYSTORE_PATH - cp $KEYSTORE_PATH ./android/app - KEYSTORE_PROPERTIES_PATH=$RUNNER_TEMP/key.properties - echo -n "$KEYSTORE_PROPERTIES" | base64 --decode --output $KEYSTORE_PROPERTIES_PATH - cp $KEYSTORE_PROPERTIES_PATH ./android + bash .github/scripts/restore_from_base64.sh "${{ secrets.KEYSTORE_PROPERTIES }}" "android/key.properties" + bash .github/scripts/restore_from_base64.sh "${{ secrets.KEYSTORE }}" "android/app/keystore.jks" - - name: Restore android/app/google-services.json - env: - GOOGLE_SERVICES_JSON_ANDROID: ${{ secrets.GOOGLE_SERVICES_JSON_ANDROID }} - run: | - GOOGLE_SERVICES_JSON_ANDROID_PATH=$RUNNER_TEMP/google-services.json - echo -n "$GOOGLE_SERVICES_JSON_ANDROID" | base64 --decode --output $GOOGLE_SERVICES_JSON_ANDROID_PATH - cp $GOOGLE_SERVICES_JSON_ANDROID_PATH ./android/app + - name: Restore google-services.json + run: bash .github/scripts/restore_from_base64.sh "${{ secrets.GOOGLE_SERVICES_JSON_ANDROID }}" "android/app/google-services.json" - name: Restore firebase_options.dart run: bash .github/scripts/restore_from_base64.sh "${{ secrets.FIREBASE_OPTIONS }}" "lib/firebase_options.dart" - name: Restore constants.dart - run: bash .github/scripts/restore_from_base64.sh "${{ secrets.CONSTANTS }}" "lib/constants.dart" + env: + CONSTANTS: ${{inputs.stage-backend && secrets.CONSTANTS_STAGE || secrets.CONSTANTS }} + run: bash .github/scripts/restore_from_base64.sh "${{ env.CONSTANTS }}" "lib/constants.dart" + + - name: Increment build number & replace version number + run: bash ./.github/scripts/increment_build_number.sh ${{ github.event.inputs.version }} - name: Install Flutter uses: subosito/flutter-action@v2 with: channel: "stable" - flutter-version: '3.10.0' + flutter-version: "3.10.0" - name: Prepare flutter project - run: | + run: | flutter --version flutter pub get flutter pub run intl_utils:generate - - name: Build .apk - env: - FLAVOR: ${{ github.event.inputs.flavor }} - run: flutter build apk --release --flavor $FLAVOR -t lib/main_$FLAVOR.dart + - name: Build ${{ inputs.binary-type }} + run: flutter build ${{ inputs.binary-type }} $BUILD_ARGS - - name: Upload artifact + - name: Upload ${{ inputs.binary-type }} to artifacts uses: actions/upload-artifact@v3 with: - name: m3_lightmeter_${{ github.event.inputs.flavor }}_apk - path: build/app/outputs/flutter-apk/app-${{ github.event.inputs.flavor }}-release.apk + name: m3_lightmeter_${{ inputs.binary-type }} + path: ${{ inputs.binary-type == 'apk' && env.BUILD_APK_PATH || env.BUILD_AAB_PATH }} diff --git a/.github/workflows/build_ipa.yml b/.github/workflows/build_ipa.yml index 91c4247..1bdaef9 100644 --- a/.github/workflows/build_ipa.yml +++ b/.github/workflows/build_ipa.yml @@ -3,10 +3,39 @@ # separate terms of service, privacy policy, and support # documentation. -name: Build Prod .ipa +name: Build iOS + +run-name: Build iOS v${{ inputs.version }} on: + workflow_call: + inputs: + version: + description: "Version" + required: true + type: string + include-iap: + type: boolean + description: Include IAP package + default: true + stage-backend: + type: boolean + description: Use stage backend + default: true workflow_dispatch: + inputs: + version: + description: "Version" + required: true + type: string + include-iap: + type: boolean + description: Include IAP package + default: true + stage-backend: + type: boolean + description: Use stage backend + default: true env: FLAVOR: "prod" @@ -14,7 +43,7 @@ env: jobs: build: name: Build .ipa - runs-on: macos-11 + runs-on: macos-13 timeout-minutes: 60 steps: - uses: actions/checkout@v3 @@ -55,14 +84,25 @@ jobs: mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles cp $PROVISION_PATH ~/Library/MobileDevice/Provisioning\ Profiles - - name: Restore ios/Runner/ExportOptions.plist + - name: Restore GoogleService-Info.plist + run: bash .github/scripts/restore_from_base64.sh "${{ secrets.GOOGLE_SERVICES_JSON_IOS }}" "ios/Runner/GoogleService-Info.plist" + + - name: Restore ExportOptions.plist run: bash .github/scripts/restore_from_base64.sh "${{ secrets.APP_STORE_EXPORT_OPTIONS }}" "ios/Runner/ExportOptions.plist" + - name: Restore firebase_app_id_file.json + run: bash .github/scripts/restore_from_base64.sh "${{ secrets.FIREBASE_APP_ID_FILE }}" "ios/firebase_app_id_file.json" + - name: Restore firebase_options.dart run: bash .github/scripts/restore_from_base64.sh "${{ secrets.FIREBASE_OPTIONS }}" "lib/firebase_options.dart" - name: Restore constants.dart - run: bash .github/scripts/restore_from_base64.sh "${{ secrets.CONSTANTS }}" "lib/constants.dart" + env: + CONSTANTS: ${{inputs.stage-backend && secrets.CONSTANTS_STAGE || secrets.CONSTANTS }} + run: bash .github/scripts/restore_from_base64.sh "${{ env.CONSTANTS }}" "lib/constants.dart" + + - name: Increment build number & replace version number + run: bash ./.github/scripts/increment_build_number.sh ${{ github.event.inputs.version }} - name: Install Flutter uses: subosito/flutter-action@v2 @@ -87,9 +127,9 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: m3_lightmeter_$FLAVOR_ipa + name: m3_lightmeter_ipa path: build/ios/ipa/lightmeter.ipa - + - name: Clean up keychain and provisioning profile if: ${{ always() }} run: | diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 0d444c6..87ee674 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -3,7 +3,6 @@ # separate terms of service, privacy policy, and support # documentation. - # This workflow uses perl regex. For better syntaxis understading see these docs: # https://perldoc.perl.org/perlrequick#Search-and-replace # https://perldoc.perl.org/perlre#Other-Modifiers @@ -23,116 +22,47 @@ on: description: "Release notes" required: true type: string - github-release: + run-integration-tests: + description: "Run integration tests" + required: true type: boolean - description: Create Github release default: true - google-play-release: - type: boolean - description: Create Google Play release - default: true - include-iap: - type: boolean - description: Include IAP package - default: true - -env: - BUILD_ARGS: --release --flavor prod -t lib/main_prod.dart jobs: - build: - name: Build .apk & .aab - if: ${{ inputs.github-release || inputs.google-play-release }} - runs-on: macos-11 - timeout-minutes: 30 - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive + run-integration-tests: + name: Run integration tests + if: ${{ inputs.run-integration-tests }} + uses: ./.github/workflows/run_integration_tests.yml + secrets: inherit - - name: Connect private iap package - uses: webfactory/ssh-agent@v0.8.0 - if: ${{ inputs.include-iap }} - with: - ssh-private-key: ${{ secrets.M3_LIGHTMETER_IAP_KEY }} + build-android: + name: Build Android + needs: [run-integration-tests] + if: ${{ always() && !failure() && !cancelled() }} + strategy: + matrix: + binary-type: [apk, appbundle] + uses: ./.github/workflows/build_apk.yml + secrets: inherit + with: + binary-type: ${{ matrix.binary-type }} + flavor: prod + stage-backend: false + version: ${{ inputs.version }} - - name: Override iap package with stub - if: ${{ !inputs.include-iap }} - run: bash ./.github/scripts/stub_iap.sh - - - uses: actions/setup-java@v3 - with: - distribution: "zulu" - java-version: "11" - - - name: Restore Android keystore .jsk and .properties files - env: - KEYSTORE: ${{ secrets.KEYSTORE }} - KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }} - run: | - KEYSTORE_PATH=$RUNNER_TEMP/keystore.jks - echo -n "$KEYSTORE" | base64 --decode --output $KEYSTORE_PATH - cp $KEYSTORE_PATH ./android/app - KEYSTORE_PROPERTIES_PATH=$RUNNER_TEMP/key.properties - echo -n "$KEYSTORE_PROPERTIES" | base64 --decode --output $KEYSTORE_PROPERTIES_PATH - cp $KEYSTORE_PROPERTIES_PATH ./android - - - name: Restore android/app/google-services.json - env: - GOOGLE_SERVICES_JSON_ANDROID: ${{ secrets.GOOGLE_SERVICES_JSON_ANDROID }} - run: | - GOOGLE_SERVICES_JSON_ANDROID_PATH=$RUNNER_TEMP/google-services.json - echo -n "$GOOGLE_SERVICES_JSON_ANDROID" | base64 --decode --output $GOOGLE_SERVICES_JSON_ANDROID_PATH - cp $GOOGLE_SERVICES_JSON_ANDROID_PATH ./android/app - - - name: Restore firebase_options.dart - run: bash .github/scripts/restore_from_base64.sh "${{ secrets.FIREBASE_OPTIONS }}" "lib/firebase_options.dart" - - - name: Restore constants.dart - run: bash .github/scripts/restore_from_base64.sh "${{ secrets.CONSTANTS }}" "lib/constants.dart" - - # This step makes sense when Github release is enabled because this release increments the build number. - # Therefore here we have to increment it as well to build an apk with the same build number. - - name: Increment build number & replace version number - if: ${{ inputs.github-release }} - run: bash ./.github/scripts/increment_build_number.sh ${{ github.event.inputs.version }} - - - name: Install Flutter - uses: subosito/flutter-action@v2 - with: - channel: "stable" - flutter-version: '3.10.0' - - - name: Prepare flutter project - run: | - flutter --version - flutter pub get - flutter pub run intl_utils:generate - - - name: Build apk - if: ${{ inputs.github-release }} - run: flutter build apk $BUILD_ARGS - - - name: Upload apk to artifacts - if: ${{ inputs.github-release }} - uses: actions/upload-artifact@v3 - with: - name: m3_lightmeter_apk - path: build/app/outputs/flutter-apk/app-prod-release.apk - - - name: Build appbundle - if: ${{ inputs.google-play-release }} - run: flutter build appbundle $BUILD_ARGS - - - name: Upload app bundle to artifacts - if: ${{ inputs.google-play-release }} - uses: actions/upload-artifact@v3 - with: - name: m3_lightmeter_bundle - path: build/app/outputs/bundle/prodRelease/app-prod-release.aab + build-ios: + name: Build iOS + needs: [run-integration-tests] + if: ${{ always() && !failure() && !cancelled() }} + uses: ./.github/workflows/build_ipa.yml + secrets: inherit + with: + stage-backend: false + version: ${{ inputs.version }} generate-release-notes: name: Generate release notes + needs: [build-android, build-ios] runs-on: ubuntu-latest steps: - name: Generate release notes @@ -146,16 +76,22 @@ jobs: name: whatsnew-en-US path: whatsnew-en-US.md - update-version-in-repo: - name: Update repo version - if: ${{ inputs.github-release }} - needs: [build] + create-github-release: + name: Create Github release + needs: [generate-release-notes] runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v3 with: submodules: recursive + - name: Download apk + uses: actions/download-artifact@v3 + with: + name: m3_lightmeter_apk + - name: Increment build number & replace version number run: bash ./.github/scripts/increment_build_number.sh ${{ github.event.inputs.version }} @@ -173,19 +109,6 @@ jobs: branch: ${{ github.ref_name }} unprotect_reviews: true - create-github-release: - name: Create Github release - if: ${{ inputs.github-release }} - needs: [build, generate-release-notes, update-version-in-repo] - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Download apk - uses: actions/download-artifact@v3 - with: - name: m3_lightmeter_apk - - name: Rename apk run: mv app-prod-release.apk m3_lightmeter.apk @@ -201,15 +124,9 @@ jobs: tag: "v${{ github.event.inputs.version }}" bodyFile: "whatsnew-en-US.md" - - name: Delete apk artifact - uses: geekyeggo/delete-artifact@v2 - with: - name: m3_lightmeter_apk - create-google-play-release: name: Create Google Play release - if: ${{ inputs.google-play-release }} - needs: [build, generate-release-notes] + needs: [generate-release-notes] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -219,7 +136,7 @@ jobs: - name: Download app bundle uses: actions/download-artifact@v3 with: - name: m3_lightmeter_bundle + name: m3_lightmeter_appbundle - name: Extract & zip merged_native_libs run: | @@ -258,31 +175,36 @@ jobs: debugSymbols: merged_native_libs.zip whatsNewDirectory: whatsnew - # https://docs.github.com/en/actions/learn-github-actions/expressions#failure-with-conditions - - name: Zip app bundle and merged_native_libs - if: ${{ failure() && steps.create-google-play-release-step.conclusion == 'failure' }} - run: zip m3_lightmeter_release.zip app-prod-release.aab merged_native_libs.zip + upload-to-app-store: + name: Upload to App Store + needs: [generate-release-notes] + runs-on: macos-13 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive - - name: Upload release zip to artifacts - if: ${{ failure() && steps.create-google-play-release-step.conclusion == 'failure' }} - uses: actions/upload-artifact@v3 + - name: Download ipa + uses: actions/download-artifact@v3 with: - name: m3_lightmeter_release - path: m3_lightmeter_release.zip - - - name: Delete app bundle & merged native libs artifacts - if: ${{ always() }} - uses: geekyeggo/delete-artifact@v2 - with: - name: m3_lightmeter_bundle + name: m3_lightmeter_ipa + + - name: Upload app to TestFlight + run: xcrun altool --upload-app -f lightmeter.ipa -t ios -u ${{ secrets.APP_STORE_USERNAME }} -p ${{ secrets.APP_STORE_PASSWORD }} cleanup: name: Cleanup if: ${{ always() }} - needs: [create-github-release, create-google-play-release] + needs: + [create-github-release, create-google-play-release, upload-to-app-store] runs-on: ubuntu-latest steps: - - name: Delete release notes artifact + - name: Delete release artifacts uses: geekyeggo/delete-artifact@v2 with: - name: whatsnew-en-US + failOnError: false + name: | + m3_lightmeter_apk + m3_lightmeter_appbundle + m3_lightmeter_ipa + whatsnew-en-US diff --git a/.github/workflows/run_integration_tests.yml b/.github/workflows/run_integration_tests.yml index ba4d6fb..c378b4b 100644 --- a/.github/workflows/run_integration_tests.yml +++ b/.github/workflows/run_integration_tests.yml @@ -20,7 +20,6 @@ jobs: submodules: recursive - name: Override iap package with stub - id: override-iap run: bash ./.github/scripts/stub_iap.sh - name: Restore secrets diff --git a/iap/lib/src/providers/iap_products_provider.dart b/iap/lib/src/providers/iap_products_provider.dart index 799e8a6..c8ad2ba 100644 --- a/iap/lib/src/providers/iap_products_provider.dart +++ b/iap/lib/src/providers/iap_products_provider.dart @@ -54,10 +54,10 @@ class IAPProducts extends InheritedModel { } @override - bool updateShouldNotify(IAPProducts oldWidget) => false; + bool updateShouldNotify(IAPProducts oldWidget) => true; @override - bool updateShouldNotifyDependent(IAPProducts oldWidget, Set dependencies) => false; + bool updateShouldNotifyDependent(IAPProducts oldWidget, Set dependencies) => true; IAPProduct? _findProduct(IAPProductType type) { try { diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 801a43b..7d56341 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -399,11 +399,9 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ""; - "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 489Z6UQMGN; + DEVELOPMENT_TEAM = 489Z6UQMGN; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Lightmeter; @@ -415,7 +413,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.vodemn.lightmeter; PRODUCT_NAME = Lightmeter; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Lightmeter Development"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -537,11 +534,9 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = ""; - "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 489Z6UQMGN; + DEVELOPMENT_TEAM = 489Z6UQMGN; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Lightmeter; @@ -553,7 +548,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.vodemn.lightmeter; PRODUCT_NAME = Lightmeter; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Lightmeter Development"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -569,7 +563,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = ""; @@ -585,7 +579,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.vodemn.lightmeter; PRODUCT_NAME = Lightmeter; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Lightmeter Development"; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Lightmeter Distribution"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic";