Skip to content

Commit

Permalink
Merge pull request #489 from nimblehq/feature/448-part2-sample-yaml-f…
Browse files Browse the repository at this point in the history
…ile-for-codemagic

[#448] [Part2] sample yaml file for codemagic
  • Loading branch information
ryan-conway authored Jul 27, 2023
2 parents b51fd53 + e978915 commit c6cc06d
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 9 deletions.
34 changes: 34 additions & 0 deletions .cicdtemplate/.codemagic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Setup

Setting up the [Codemagic](https://codemagic.io/start/) to the project starts from adding project to
the Codemagic console.
After that, you can follow the instruction below to setup the environment variables and deployment.

# Environment Variables

You can configure the environment variables for Codemagic by accessing the `Environment Variables`
tab under `App Settings`.
For detailed instructions on how to configure these variables, please refer
to [this document](https://docs.codemagic.io/yaml-basic-configuration/configuring-environment-variables/#configuring-environment-variables)
.

# Deploy to Firebase App Distribution (FAD)

1. Set up the Firebase SDK in your app by following
the [Get started guide for Android](https://firebase.google.com/docs/android/setup).
2. Create service account for Codemagic by following
the [Firebase App Distribution with codemagic.yaml](https://docs.codemagic.io/yaml-publishing/firebase-app-distribution/)
at `Authenticating via service account` which is recommended.
3. Update the script on `app_id` and tester `groups` in `codemagic.yaml` file:

```yaml
publishing:
firebase:
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT
android:
app_id: x:xxxxxxxxxxxx:android:xxxxxxxxxxxxxxxxxxxxxx
groups:
- androidTesters
- ...
artifact_type: 'apk' # Replace with 'aab' to only publish the Android app bundle
```
108 changes: 108 additions & 0 deletions .cicdtemplate/.codemagic/codemagic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
definitions:
configure_environment: &configure_environment
# This running machine can be changed depends on the billing plan: https://docs.codemagic.io/knowledge-codemagic/machine-type/
instance_type: mac_mini_m1
max_build_duration: 30
environment:
groups:
- firebase_credentials
cache:
cache_paths:
- $HOME/.gradle/caches
scripts:
- &set_up_google_services_files_from_environment_variables
name: Set up google-services.json files
script: |
mkdir -p app/src/production
echo $GOOGLE_SERVICES_JSON > app/src/production/google-services.json
mkdir -p app/src/staging
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
- &detekt
name: Run detekt
script: ./gradlew detekt
- &unit_test
name: Run unit tests
script: ./gradlew koverMergedReport
artifacts:
- &artifacts_test_report build/reports/kover/merged/
- &artifacts_staging_apk app/build/outputs/apk/staging/debug/app-staging-debug.apk
- &artifacts_production_apk app/build/outputs/apk/production/debug/app-production-debug.apk
workflows:
unit-test-on-pr:
name: Unit test on PR
<<: *configure_environment
triggering:
events:
# Run when a pull request is opened or updated
- pull_request
branch_patterns:
# Review changes BEFORE they’re merged into any branches
- pattern: '*'
source: false
# Will not run on develop branch as it is already covered by build-and-deploy-template-compose-staging
- pattern: 'develop'
include: false
# Will not run on main branch as it is already covered by build-and-deploy-template-compose-production
- pattern: 'main'
include: false
cancel_previous_builds: true
scripts:
- *set_up_google_services_files_from_environment_variables
- *detekt
- *unit_test
artifacts:
- *artifacts_test_report

build-and-deploy-staging:
name: Build and deploy staging to Firebase App Distribution
<<: *configure_environment
triggering:
events:
- push
branch_patterns:
- pattern: develop
scripts:
- *set_up_google_services_files_from_environment_variables
- *detekt
- *unit_test
- name: Build APK for staging
script: |
./gradlew assembleStagingDebug -PversionCode=$BUILD_NUMBER
artifacts:
- *artifacts_test_report
- *artifacts_staging_apk
publishing:
firebase:
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
android:
app_id: $FIREBASE_APP_ID_STAGING
groups:
- android-chapter
artifact_type: 'apk'

build-and-deploy-production:
name: Build and deploy production to Firebase App Distribution
<<: *configure_environment
triggering:
events:
- push
branch_patterns:
- pattern: main
scripts:
- *set_up_google_services_files_from_environment_variables
- *detekt
- *unit_test
- name: Build APK for production
script: |
./gradlew assembleProductionDebug -PversionCode=$BUILD_NUMBER
artifacts:
- *artifacts_test_report
- *artifacts_production_apk
publishing:
firebase:
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
android:
app_id: $FIREBASE_APP_ID_PRODUCTION
groups:
- android-chapter
artifact_type: 'apk'
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up google-services.json files
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
run: |
mkdir -p app/src/production
echo $GOOGLE_SERVICES_JSON > app/src/production/google-services.json
mkdir -p app/src/staging
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
- name: Run Detekt
run: ./gradlew detekt

Expand Down
10 changes: 10 additions & 0 deletions .cicdtemplate/.github/workflows/review_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
run: |
mkdir -p app/src/production
echo $GOOGLE_SERVICES_JSON > app/src/production/google-services.json
mkdir -p app/src/staging
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
- name: Run Detekt
run: ./gradlew detekt

Expand Down
7 changes: 7 additions & 0 deletions .cicdtemplate/.github/workflows/run_detekt_and_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up google-services.json
env:
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
run: |
mkdir -p app/src/staging
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
- name: Run Detekt
run: ./gradlew detekt

Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/review_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
name: Review pull request
runs-on: ubuntu-latest
timeout-minutes: 30
environment: template-compose
steps:
- name: Set up JDK 11
uses: actions/setup-java@v2
Expand Down Expand Up @@ -46,6 +47,16 @@ jobs:

# template-compose

- name: Set up google-services.json on template-compose
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
run: |
mkdir -p template-compose/app/src/production
echo $GOOGLE_SERVICES_JSON > template-compose/app/src/production/google-services.json
mkdir -p template-compose/app/src/staging
echo $GOOGLE_SERVICES_JSON_STAGING > template-compose/app/src/staging/google-services.json
- name: Run Detekt on template-compose
working-directory: ./template-compose
run: ./gradlew detekt
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/run_detekt_and_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
name: Run Detekt and unit tests
runs-on: ubuntu-latest
timeout-minutes: 30
environment: template-compose
steps:
- name: Set up JDK 11
uses: actions/setup-java@v2
Expand Down Expand Up @@ -52,6 +53,13 @@ jobs:

# template-compose

- name: Set up google-services.json on template-compose
env:
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
run: |
mkdir -p template-compose/app/src/staging
echo $GOOGLE_SERVICES_JSON_STAGING > template-compose/app/src/staging/google-services.json
- name: Run Detekt on template-compose
working-directory: ./template-compose
run: ./gradlew detekt
Expand Down
90 changes: 82 additions & 8 deletions codemagic.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
definitions:
configure_environment: &configure_environment
# This running machine can be changed depends on the billing plan: https://docs.codemagic.io/knowledge-codemagic/machine-type/
instance_type: mac_mini_m1
max_build_duration: 30
environment:
groups:
- firebase_credentials
cache:
cache_paths:
- $HOME/.gradle/caches
scripts:
- &set_up_google_services_files_from_environment_variables
name: Set up google-services.json on template-compose
script: |
mkdir -p template-compose/app/src/production
echo $GOOGLE_SERVICES_JSON > template-compose/app/src/production/google-services.json
mkdir -p template-compose/app/src/staging
echo $GOOGLE_SERVICES_JSON_STAGING > template-compose/app/src/staging/google-services.json
- &detekt_on_template_compose
name: Run detekt on template-compose
working_directory: ./template-compose
Expand All @@ -25,24 +36,29 @@ definitions:
artifacts:
- &artifacts_template_compose template-compose/build/reports/kover/merged/
- &artifacts_template_xml template-xml/build/reports/kover/merged/
- &artifacts_staging_apk template-compose/app/build/outputs/apk/staging/debug/app-staging-debug.apk
- &artifacts_production_apk template-compose/app/build/outputs/apk/production/debug/app-production-debug.apk
workflows:
unit-test-on-pr-for-template-compose:
name: Unit test on PR for template-compose
<<: *configure_environment
triggering:
events:
# run when a pull request is opened or updated
# Run when a pull request is opened or updated
- pull_request
branch_patterns:
# review changes BEFORE they’re merged into any branches
# Review changes BEFORE they’re merged into any branches
- pattern: '*'
source: false
# review changes AFTER they have been merged into develop branch
# Will not run on develop branch as it is already covered by build-and-deploy-template-compose-staging
- pattern: 'develop'
# review changes AFTER they have been merged into main branch
include: false
# Will not run on main branch as it is already covered by build-and-deploy-template-compose-production
- pattern: 'main'
include: false
cancel_previous_builds: true
scripts:
- *set_up_google_services_files_from_environment_variables
- *detekt_on_template_compose
- *unit_test_on_template_compose
artifacts:
Expand All @@ -53,19 +69,77 @@ workflows:
<<: *configure_environment
triggering:
events:
# run when a pull request is opened or updated
# Run when a pull request is opened or updated
- pull_request
branch_patterns:
# review changes BEFORE they’re merged into any branches
# Review changes BEFORE they’re merged into any branches
- pattern: '*'
source: false
# review changes AFTER they have been merged into develop branch
# Will not run on develop branch as it is already covered by build-and-deploy-template-compose-staging
- pattern: 'develop'
# review changes AFTER they have been merged into main branch
include: false
# Will not run on main branch as it is already covered by build-and-deploy-template-compose-production
- pattern: 'main'
include: false
cancel_previous_builds: true
scripts:
- *detekt_on_template_xml
- *unit_test_on_template_xml
artifacts:
- *artifacts_template_xml

build-and-deploy-template-compose-staging:
name: Build and deploy template-compose staging to Firebase App Distribution
<<: *configure_environment
triggering:
events:
- push
branch_patterns:
- pattern: develop
scripts:
- *set_up_google_services_files_from_environment_variables
- *detekt_on_template_compose
- *unit_test_on_template_compose
- name: Build APK for staging
working_directory: ./template-compose
script: |
./gradlew assembleStagingDebug -PversionCode=$BUILD_NUMBER
artifacts:
- *artifacts_template_compose
- *artifacts_staging_apk
publishing:
firebase:
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
android:
app_id: $FIREBASE_APP_ID_STAGING
groups:
- android-chapter
artifact_type: 'apk'

build-and-deploy-template-compose-production:
name: Build and deploy template-compose production to Firebase App Distribution
<<: *configure_environment
triggering:
events:
- push
branch_patterns:
- pattern: main
scripts:
- *set_up_google_services_files_from_environment_variables
- *detekt_on_template_compose
- *unit_test_on_template_compose
- name: Build APK for production
working_directory: ./template-compose
script: |
./gradlew assembleProductionDebug -PversionCode=$BUILD_NUMBER
artifacts:
- *artifacts_template_compose
- *artifacts_production_apk
publishing:
firebase:
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
android:
app_id: $FIREBASE_APP_ID_PRODUCTION
groups:
- android-chapter
artifact_type: 'apk'
Loading

0 comments on commit c6cc06d

Please sign in to comment.