ML-157 Improve CI/CD (#162)

* Update README.md

* Set exact Flutter version for workflows

* Added stub `DefaultFirebaseOptions`

* Fixed `rm`

* Removed `rm`

* Update .gitignore

* Added readable name to ci workflow

* Build -> Development

* Update ci.yml

* Extract merged native libraries

* More descriptive run name

* Delete no longer used artifacts

* Replaced "Build ..." flow with "Create release"

* renamed other flows

* try using script for iap stub

* typo

* typo

* typo

* removed working dir

* added comment to stub_iap.sh

* checkout first

* increment build number by script

* Update increment_build_number.sh

* fixed iap repo

* stub

* updated stub script to work with tags

* depend on step conclusion

* check PR number

* run integration tests before build

* reuse Build Android workflow

* added stage backend option

* reuse Build iOS workflow

* temporeraly skip release jobs

* [ios] use distribution profile for release builds

* temporary skip tests

* typo

* checkout actions

* incremented macos runner version

* Restore GoogleService-Info.plist

* Restore firebase_app_id_file.json

* style

* separated android and ios builds

* fixed invalid workflow

* simplified release workflow tree

* fixed android keystore path

* enabled integration tests

* added option to skip integration tests

* fixed android folders...

* enabled releases

* increment build number for ios

* upload ipa to app store

* test ipa upload

* typo

* try to force ipa upload

* removed flavor from ipa artefact name

* try manual ipa upload

* switched to ubuntu for upload

* decode to repo

* Update create_release.yml

* auth with username + password

* reverted temporary settings

* typo

* disable pre-release integration tests by default

* fixed integration tests

* increased integration tests timeout

* delete ipa after upload

* delete all artifacts after the run

* fixed integration tests

* reduce integration tests timeout
This commit is contained in:
Vadim 2024-03-17 20:02:00 +01:00
parent 7787558713
commit d6c4240646
6 changed files with 196 additions and 206 deletions

View file

@ -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_call:
inputs:
version:
description: "Version"
required: true
type: string
binary-type:
description: "Binary type"
type: string
required: true
flavor:
description: "Flavor"
type: string
required: true
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'
description: "Flavor"
type: choice
required: true
options:
- dev
- prod
default: 'dev'
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:
@ -41,42 +85,35 @@ jobs:
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: |
@ -84,13 +121,11 @@ jobs:
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 }}

View file

@ -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,7 +127,7 @@ 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

View file

@ -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
run-integration-tests:
name: Run integration tests
if: ${{ inputs.run-integration-tests }}
uses: ./.github/workflows/run_integration_tests.yml
secrets: inherit
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:
submodules: recursive
binary-type: ${{ matrix.binary-type }}
flavor: prod
stage-backend: false
version: ${{ inputs.version }}
- name: Connect private iap package
uses: webfactory/ssh-agent@v0.8.0
if: ${{ inputs.include-iap }}
build-ios:
name: Build iOS
needs: [run-integration-tests]
if: ${{ always() && !failure() && !cancelled() }}
uses: ./.github/workflows/build_ipa.yml
secrets: inherit
with:
ssh-private-key: ${{ secrets.M3_LIGHTMETER_IAP_KEY }}
- 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
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
- name: Upload release zip to artifacts
if: ${{ failure() && steps.create-google-play-release-step.conclusion == 'failure' }}
uses: actions/upload-artifact@v3
upload-to-app-store:
name: Upload to App Store
needs: [generate-release-notes]
runs-on: macos-13
steps:
- uses: actions/checkout@v3
with:
name: m3_lightmeter_release
path: m3_lightmeter_release.zip
submodules: recursive
- name: Delete app bundle & merged native libs artifacts
if: ${{ always() }}
uses: geekyeggo/delete-artifact@v2
- name: Download ipa
uses: actions/download-artifact@v3
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

View file

@ -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

View file

@ -54,10 +54,10 @@ class IAPProducts extends InheritedModel<IAPProductType> {
}
@override
bool updateShouldNotify(IAPProducts oldWidget) => false;
bool updateShouldNotify(IAPProducts oldWidget) => true;
@override
bool updateShouldNotifyDependent(IAPProducts oldWidget, Set<IAPProductType> dependencies) => false;
bool updateShouldNotifyDependent(IAPProducts oldWidget, Set<IAPProductType> dependencies) => true;
IAPProduct? _findProduct(IAPProductType type) {
try {

View file

@ -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";