Skip to content

Commit

Permalink
Merge pull request #163 from nimblehq/feature/61-setup-cd-to-build-an…
Browse files Browse the repository at this point in the history
…d-deploy-android-app-to-playstore

[#61] As a developer, I can have a CD process to build and deploy the Android app to Play Store
  • Loading branch information
luongvo authored Mar 23, 2023
2 parents 61ffd4d + 6a3bbce commit 57ef547
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 49 deletions.
34 changes: 26 additions & 8 deletions .github/wiki/Deployment.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
# Deployment Process

## For Android

### Guide

- Before publishing the Android application, we have to prepare the necessary credentials and information:
- A Play Store developer account.
- Your application's app id. This could be multiple bundle ids according to the number of application’s flavors.
- A new app on Play Store.

- Add these variables as the secrets of CI:
- **ENV_PRODUCTION**: the production .env configuration file content.
- **GOOGLE_PLAY_SERVICE_ACCOUNT_JSON**: the json file content of the Play Store's Service Account for app publishing. Please check out [how to create the Service Account](https://support.staffbase.com/hc/en-us/articles/360018569579-Preparing-Automated-Publishing-for-Google-Play-Store).

### Resources

- [Build and release an Android app](https://docs.flutter.dev/deployment/android#build-an-apk).
- [Preparing Automated Publishing for Google Play Store](https://support.staffbase.com/hc/en-us/articles/360018569579-Preparing-Automated-Publishing-for-Google-Play-Store).

## For iOS

### Guide

- Before deploying the iOS application, we have to prepare the necessary credentials and information:
- Before publishing the iOS application, we have to prepare the necessary credentials and information:

- An Apple developer account.
- Your application’s bundle id. This could be multiple bundle ids according to the number of application’s flavors.
- A new app's on Apple Store Connect that links to the bundle id.
- A new app on Apple Store Connect that links to the bundle id.
- The access to Git’s [Match repository](https://codesigning.guide/).

- Create certificates for distribution and [code signing](https://codesigning.guide/) so we are able to fetch the certificates through [Match](https://docs.fastlane.tools/actions/match/).
- Setup [Fastlane](https://docs.fastlane.tools/getting-started/ios/setup/) and [Match](https://docs.fastlane.tools/actions/match/).
- Adding these variables as the environment variable of CI:
- Create certificates for distribution and [code signing](https://codesigning.guide/) so we are able to fetch the certificates through the [Match](https://docs.fastlane.tools/actions/match/) repository.
- Set up [Fastlane](https://docs.fastlane.tools/getting-started/ios/setup/) and [Match](https://docs.fastlane.tools/actions/match/).
- Add these variables as the secrets of CI:

- **FASTLANE_USER**: This will be referred to in `Appfile` and `Fastfile`. Set your Apple ID to this variable.
- **FASTLANE_PASSWORD**: This variable will be referred to internally in Fastlane. Set the password of your Apple ID to this variable.
Expand All @@ -23,10 +41,10 @@
- **KEYCHAIN_PASSWORD**: We can create a keychain password for ourself and it could be anything.
- **SSH_PRIVATE_KEY**: In order to fetch the distribution files from Git’s [Match repository](https://codesigning.guide/), we have to generate an SSH key and save it as the environment variable in CI.

- Run the corresponding workflows CI or `fastlane` commands and enjoy the result!
- Run the corresponding workflows or `fastlane` commands and enjoy the result!

### Resource
### Resources

- [https://medium.com/flutter-community/deploying-flutter-ios-apps-with-fastlane-and-github-actions-2e87465e056e](https://medium.com/flutter-community/deploying-flutter-ios-apps-with-fastlane-and-github-actions-2e87465e056e)
- [https://docs.flutter.dev/deployment/cd](https://docs.flutter.dev/deployment/cd)
- [https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-2-ios-a4b281921d39](https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-2-ios-a4b281921d39)
- [https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-2-ios-a4b281921d39](https://jaysavsani07.medium.com/flutter-ci-cd-with-github-actions-fastlane-part-2-ios-a4b281921d39)
16 changes: 9 additions & 7 deletions .github/workflows/android_deploy_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,38 @@ jobs:
build_and_deploy_android:
name: Build & Deploy Android
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Generate new project
run: make run PACKAGE_NAME=co.nimblehq.flutter.template PROJECT_NAME=flutter_templates APP_NAME="Flutter Templates"

- name: Setup Java JDK
- name: Set up Java JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Setup Flutter environment
- name: Set up Flutter environment
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'

- name: Get flutter dependencies
- name: Get Flutter dependencies
run: flutter pub get

- name: Run code generator.
- name: Run code generator
run: flutter packages pub run build_runner build --delete-conflicting-outputs

- name: Setup .env
- name: Set up .env
env:
ENV_PRODUCTION: ${{ secrets.ENV_PRODUCTION }}
run: |
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/android_deploy_production_to_playstore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Android - Deploy Production build to Play Store

on:
push:
branches:
- main

jobs:
build_and_deploy_android:
name: Build & Deploy Android
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Generate new project
run: make run PACKAGE_NAME=co.nimblehq.flutter.template PROJECT_NAME=flutter_templates APP_NAME="Flutter Templates"

- name: Set up Java JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Set up Flutter environment
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'

- name: Get Flutter dependencies
run: flutter pub get

- name: Run code generator
run: flutter packages pub run build_runner build --delete-conflicting-outputs

- name: Set up .env
env:
ENV_PRODUCTION: ${{ secrets.ENV_PRODUCTION }}
run: |
echo $ENV_PRODUCTION > .env
- name: Build Production App Bundle
run: flutter build appbundle --flavor production --release --build-number $GITHUB_RUN_NUMBER

# TODO We will enable this step later when having a shared Service Account on our organization
# Basically, this step will work properly after providing a valid Service Account.
# - name: Upload Android Production Release bundle to Play Store
# uses: r0adkll/upload-google-play@v1
# with:
# serviceAccountJson: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
# packageName: co.nimblehq.flutter.template
# releaseFile: build/app/outputs/bundle/productionRelease/app-production-release.aab
# track: internal
# userFraction: 1.0
# whatsNewDirectory: .github/workflows/whatsnew
16 changes: 9 additions & 7 deletions .github/workflows/android_deploy_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,39 @@ jobs:
build_and_deploy_android:
name: Build & Deploy Android
runs-on: ubuntu-latest
timeout-minutes: 30
environment: staging
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Generate new project
run: make run PACKAGE_NAME=co.nimblehq.flutter.template PROJECT_NAME=flutter_templates APP_NAME="Flutter Templates"

- name: Setup Java JDK
- name: Set up Java JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Setup Flutter environment
- name: Set up Flutter environment
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'

- name: Get flutter dependencies
- name: Get Flutter dependencies
run: flutter pub get

- name: Run code generator.
- name: Run code generator
run: flutter packages pub run build_runner build --delete-conflicting-outputs

- name: Setup .env.staging
- name: Set up .env.staging
env:
ENV_STAGING: ${{ secrets.ENV_STAGING }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
bump_version:
name: Bump version
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout the latest code
uses: actions/checkout@v3
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,35 @@ jobs:
test:
name: Template initializing scripts test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/[email protected]

- name: Setup Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Generate new project
run: make run PACKAGE_NAME=co.nimblehq.flutter.template PROJECT_NAME=flutter_templates APP_NAME="Flutter Templates"

- name: Setup Flutter environment
- name: Set up Flutter environment
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'

- name: Get flutter dependencies.
- name: Get Flutter dependencies
run: flutter pub get

- name: Run code generator
run: flutter packages pub run build_runner build --delete-conflicting-outputs

- name: Check for any formatting issues in the code.
- name: Check for any formatting issues in the code
run: flutter format --set-exit-if-changed .

- name: Statically analyze the Dart code for any errors.
- name: Statically analyze the Dart code for any errors
run: flutter analyze .

- name: Run widget tests, unit tests.
- name: Run widget tests, unit tests
run: flutter test --machine --coverage
14 changes: 8 additions & 6 deletions template/.github/workflows/android_deploy_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ jobs:
build_and_deploy_android:
name: Build & Deploy Android
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Setup Java JDK
- name: Set up Java JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Setup Flutter environment
- name: Set up Flutter environment
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'

- name: Get flutter dependencies
- name: Get Flutter dependencies
run: flutter pub get

- name: Run code generator.
- name: Run code generator
run: flutter packages pub run build_runner build --delete-conflicting-outputs

- name: Setup .env
- name: Set up .env
env:
ENV_PRODUCTION: ${{ secrets.ENV_PRODUCTION }}
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Android - Deploy Production build to Play Store

on:
push:
branches:
- main

jobs:
build_and_deploy_android:
name: Build & Deploy Android
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Java JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Set up Flutter environment
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'

- name: Get Flutter dependencies
run: flutter pub get

- name: Run code generator
run: flutter packages pub run build_runner build --delete-conflicting-outputs

- name: Set up .env
env:
ENV_PRODUCTION: ${{ secrets.ENV_PRODUCTION }}
run: |
echo $ENV_PRODUCTION > .env
- name: Build Production App Bundle
run: flutter build appbundle --flavor production --release --build-number $GITHUB_RUN_NUMBER

- name: Upload Android Production Release bundle to Play Store
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJson: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
packageName: co.nimblehq.flutter.template
releaseFile: build/app/outputs/bundle/productionRelease/app-production-release.aab
track: internal
userFraction: 1.0
whatsNewDirectory: .github/workflows/whatsnew
14 changes: 8 additions & 6 deletions template/.github/workflows/android_deploy_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ jobs:
build_and_deploy_android:
name: Build & Deploy Android
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Setup Java JDK
- name: Set up Java JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Setup Flutter environment
- name: Set up Flutter environment
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'

- name: Get flutter dependencies
- name: Get Flutter dependencies
run: flutter pub get

- name: Run code generator.
- name: Run code generator
run: flutter packages pub run build_runner build --delete-conflicting-outputs

- name: Setup .env.staging
- name: Set up .env.staging
env:
ENV_STAGING: ${{ secrets.ENV_STAGING }}
run: |
Expand Down
1 change: 1 addition & 0 deletions template/.github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
bump_version:
name: Bump version
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout the latest code
uses: actions/checkout@v3
Expand Down
Loading

0 comments on commit 57ef547

Please sign in to comment.