Skip to content

Commit c6cc06d

Browse files
authored
Merge pull request #489 from nimblehq/feature/448-part2-sample-yaml-file-for-codemagic
[#448] [Part2] sample yaml file for codemagic
2 parents b51fd53 + e978915 commit c6cc06d

File tree

11 files changed

+286
-9
lines changed

11 files changed

+286
-9
lines changed

.cicdtemplate/.codemagic/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Setup
2+
3+
Setting up the [Codemagic](https://codemagic.io/start/) to the project starts from adding project to
4+
the Codemagic console.
5+
After that, you can follow the instruction below to setup the environment variables and deployment.
6+
7+
# Environment Variables
8+
9+
You can configure the environment variables for Codemagic by accessing the `Environment Variables`
10+
tab under `App Settings`.
11+
For detailed instructions on how to configure these variables, please refer
12+
to [this document](https://docs.codemagic.io/yaml-basic-configuration/configuring-environment-variables/#configuring-environment-variables)
13+
.
14+
15+
# Deploy to Firebase App Distribution (FAD)
16+
17+
1. Set up the Firebase SDK in your app by following
18+
the [Get started guide for Android](https://firebase.google.com/docs/android/setup).
19+
2. Create service account for Codemagic by following
20+
the [Firebase App Distribution with codemagic.yaml](https://docs.codemagic.io/yaml-publishing/firebase-app-distribution/)
21+
at `Authenticating via service account` which is recommended.
22+
3. Update the script on `app_id` and tester `groups` in `codemagic.yaml` file:
23+
24+
```yaml
25+
publishing:
26+
firebase:
27+
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT
28+
android:
29+
app_id: x:xxxxxxxxxxxx:android:xxxxxxxxxxxxxxxxxxxxxx
30+
groups:
31+
- androidTesters
32+
- ...
33+
artifact_type: 'apk' # Replace with 'aab' to only publish the Android app bundle
34+
```
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
definitions:
2+
configure_environment: &configure_environment
3+
# This running machine can be changed depends on the billing plan: https://docs.codemagic.io/knowledge-codemagic/machine-type/
4+
instance_type: mac_mini_m1
5+
max_build_duration: 30
6+
environment:
7+
groups:
8+
- firebase_credentials
9+
cache:
10+
cache_paths:
11+
- $HOME/.gradle/caches
12+
scripts:
13+
- &set_up_google_services_files_from_environment_variables
14+
name: Set up google-services.json files
15+
script: |
16+
mkdir -p app/src/production
17+
echo $GOOGLE_SERVICES_JSON > app/src/production/google-services.json
18+
mkdir -p app/src/staging
19+
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
20+
- &detekt
21+
name: Run detekt
22+
script: ./gradlew detekt
23+
- &unit_test
24+
name: Run unit tests
25+
script: ./gradlew koverMergedReport
26+
artifacts:
27+
- &artifacts_test_report build/reports/kover/merged/
28+
- &artifacts_staging_apk app/build/outputs/apk/staging/debug/app-staging-debug.apk
29+
- &artifacts_production_apk app/build/outputs/apk/production/debug/app-production-debug.apk
30+
workflows:
31+
unit-test-on-pr:
32+
name: Unit test on PR
33+
<<: *configure_environment
34+
triggering:
35+
events:
36+
# Run when a pull request is opened or updated
37+
- pull_request
38+
branch_patterns:
39+
# Review changes BEFORE they’re merged into any branches
40+
- pattern: '*'
41+
source: false
42+
# Will not run on develop branch as it is already covered by build-and-deploy-template-compose-staging
43+
- pattern: 'develop'
44+
include: false
45+
# Will not run on main branch as it is already covered by build-and-deploy-template-compose-production
46+
- pattern: 'main'
47+
include: false
48+
cancel_previous_builds: true
49+
scripts:
50+
- *set_up_google_services_files_from_environment_variables
51+
- *detekt
52+
- *unit_test
53+
artifacts:
54+
- *artifacts_test_report
55+
56+
build-and-deploy-staging:
57+
name: Build and deploy staging to Firebase App Distribution
58+
<<: *configure_environment
59+
triggering:
60+
events:
61+
- push
62+
branch_patterns:
63+
- pattern: develop
64+
scripts:
65+
- *set_up_google_services_files_from_environment_variables
66+
- *detekt
67+
- *unit_test
68+
- name: Build APK for staging
69+
script: |
70+
./gradlew assembleStagingDebug -PversionCode=$BUILD_NUMBER
71+
artifacts:
72+
- *artifacts_test_report
73+
- *artifacts_staging_apk
74+
publishing:
75+
firebase:
76+
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
77+
android:
78+
app_id: $FIREBASE_APP_ID_STAGING
79+
groups:
80+
- android-chapter
81+
artifact_type: 'apk'
82+
83+
build-and-deploy-production:
84+
name: Build and deploy production to Firebase App Distribution
85+
<<: *configure_environment
86+
triggering:
87+
events:
88+
- push
89+
branch_patterns:
90+
- pattern: main
91+
scripts:
92+
- *set_up_google_services_files_from_environment_variables
93+
- *detekt
94+
- *unit_test
95+
- name: Build APK for production
96+
script: |
97+
./gradlew assembleProductionDebug -PversionCode=$BUILD_NUMBER
98+
artifacts:
99+
- *artifacts_test_report
100+
- *artifacts_production_apk
101+
publishing:
102+
firebase:
103+
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
104+
android:
105+
app_id: $FIREBASE_APP_ID_PRODUCTION
106+
groups:
107+
- android-chapter
108+
artifact_type: 'apk'

.cicdtemplate/.github/workflows/deploy_staging_and_production_to_firebase_app_distribution.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ jobs:
3838
restore-keys: |
3939
${{ runner.os }}-gradle-
4040
41+
- name: Set up google-services.json files
42+
env:
43+
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
44+
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
45+
run: |
46+
mkdir -p app/src/production
47+
echo $GOOGLE_SERVICES_JSON > app/src/production/google-services.json
48+
mkdir -p app/src/staging
49+
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
50+
4151
- name: Run Detekt
4252
run: ./gradlew detekt
4353

.cicdtemplate/.github/workflows/review_pull_request.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ jobs:
3030
restore-keys: |
3131
${{ runner.os }}-gradle-
3232
33+
- name: Set up google-services.json
34+
env:
35+
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
36+
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
37+
run: |
38+
mkdir -p app/src/production
39+
echo $GOOGLE_SERVICES_JSON > app/src/production/google-services.json
40+
mkdir -p app/src/staging
41+
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
42+
3343
- name: Run Detekt
3444
run: ./gradlew detekt
3545

.cicdtemplate/.github/workflows/run_detekt_and_unit_tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ jobs:
4141
restore-keys: |
4242
${{ runner.os }}-gradle-
4343
44+
- name: Set up google-services.json
45+
env:
46+
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
47+
run: |
48+
mkdir -p app/src/staging
49+
echo $GOOGLE_SERVICES_JSON_STAGING > app/src/staging/google-services.json
50+
4451
- name: Run Detekt
4552
run: ./gradlew detekt
4653

.github/workflows/review_pull_request.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
name: Review pull request
1010
runs-on: ubuntu-latest
1111
timeout-minutes: 30
12+
environment: template-compose
1213
steps:
1314
- name: Set up JDK 11
1415
uses: actions/setup-java@v2
@@ -46,6 +47,16 @@ jobs:
4647

4748
# template-compose
4849

50+
- name: Set up google-services.json on template-compose
51+
env:
52+
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
53+
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
54+
run: |
55+
mkdir -p template-compose/app/src/production
56+
echo $GOOGLE_SERVICES_JSON > template-compose/app/src/production/google-services.json
57+
mkdir -p template-compose/app/src/staging
58+
echo $GOOGLE_SERVICES_JSON_STAGING > template-compose/app/src/staging/google-services.json
59+
4960
- name: Run Detekt on template-compose
5061
working-directory: ./template-compose
5162
run: ./gradlew detekt

.github/workflows/run_detekt_and_unit_tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
name: Run Detekt and unit tests
88
runs-on: ubuntu-latest
99
timeout-minutes: 30
10+
environment: template-compose
1011
steps:
1112
- name: Set up JDK 11
1213
uses: actions/setup-java@v2
@@ -52,6 +53,13 @@ jobs:
5253

5354
# template-compose
5455

56+
- name: Set up google-services.json on template-compose
57+
env:
58+
GOOGLE_SERVICES_JSON_STAGING: ${{ secrets.GOOGLE_SERVICES_JSON_STAGING }}
59+
run: |
60+
mkdir -p template-compose/app/src/staging
61+
echo $GOOGLE_SERVICES_JSON_STAGING > template-compose/app/src/staging/google-services.json
62+
5563
- name: Run Detekt on template-compose
5664
working-directory: ./template-compose
5765
run: ./gradlew detekt

codemagic.yaml

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
definitions:
22
configure_environment: &configure_environment
3+
# This running machine can be changed depends on the billing plan: https://docs.codemagic.io/knowledge-codemagic/machine-type/
34
instance_type: mac_mini_m1
45
max_build_duration: 30
6+
environment:
7+
groups:
8+
- firebase_credentials
59
cache:
610
cache_paths:
711
- $HOME/.gradle/caches
812
scripts:
13+
- &set_up_google_services_files_from_environment_variables
14+
name: Set up google-services.json on template-compose
15+
script: |
16+
mkdir -p template-compose/app/src/production
17+
echo $GOOGLE_SERVICES_JSON > template-compose/app/src/production/google-services.json
18+
mkdir -p template-compose/app/src/staging
19+
echo $GOOGLE_SERVICES_JSON_STAGING > template-compose/app/src/staging/google-services.json
920
- &detekt_on_template_compose
1021
name: Run detekt on template-compose
1122
working_directory: ./template-compose
@@ -25,24 +36,29 @@ definitions:
2536
artifacts:
2637
- &artifacts_template_compose template-compose/build/reports/kover/merged/
2738
- &artifacts_template_xml template-xml/build/reports/kover/merged/
39+
- &artifacts_staging_apk template-compose/app/build/outputs/apk/staging/debug/app-staging-debug.apk
40+
- &artifacts_production_apk template-compose/app/build/outputs/apk/production/debug/app-production-debug.apk
2841
workflows:
2942
unit-test-on-pr-for-template-compose:
3043
name: Unit test on PR for template-compose
3144
<<: *configure_environment
3245
triggering:
3346
events:
34-
# run when a pull request is opened or updated
47+
# Run when a pull request is opened or updated
3548
- pull_request
3649
branch_patterns:
37-
# review changes BEFORE they’re merged into any branches
50+
# Review changes BEFORE they’re merged into any branches
3851
- pattern: '*'
3952
source: false
40-
# review changes AFTER they have been merged into develop branch
53+
# Will not run on develop branch as it is already covered by build-and-deploy-template-compose-staging
4154
- pattern: 'develop'
42-
# review changes AFTER they have been merged into main branch
55+
include: false
56+
# Will not run on main branch as it is already covered by build-and-deploy-template-compose-production
4357
- pattern: 'main'
58+
include: false
4459
cancel_previous_builds: true
4560
scripts:
61+
- *set_up_google_services_files_from_environment_variables
4662
- *detekt_on_template_compose
4763
- *unit_test_on_template_compose
4864
artifacts:
@@ -53,19 +69,77 @@ workflows:
5369
<<: *configure_environment
5470
triggering:
5571
events:
56-
# run when a pull request is opened or updated
72+
# Run when a pull request is opened or updated
5773
- pull_request
5874
branch_patterns:
59-
# review changes BEFORE they’re merged into any branches
75+
# Review changes BEFORE they’re merged into any branches
6076
- pattern: '*'
6177
source: false
62-
# review changes AFTER they have been merged into develop branch
78+
# Will not run on develop branch as it is already covered by build-and-deploy-template-compose-staging
6379
- pattern: 'develop'
64-
# review changes AFTER they have been merged into main branch
80+
include: false
81+
# Will not run on main branch as it is already covered by build-and-deploy-template-compose-production
6582
- pattern: 'main'
83+
include: false
6684
cancel_previous_builds: true
6785
scripts:
6886
- *detekt_on_template_xml
6987
- *unit_test_on_template_xml
7088
artifacts:
7189
- *artifacts_template_xml
90+
91+
build-and-deploy-template-compose-staging:
92+
name: Build and deploy template-compose staging to Firebase App Distribution
93+
<<: *configure_environment
94+
triggering:
95+
events:
96+
- push
97+
branch_patterns:
98+
- pattern: develop
99+
scripts:
100+
- *set_up_google_services_files_from_environment_variables
101+
- *detekt_on_template_compose
102+
- *unit_test_on_template_compose
103+
- name: Build APK for staging
104+
working_directory: ./template-compose
105+
script: |
106+
./gradlew assembleStagingDebug -PversionCode=$BUILD_NUMBER
107+
artifacts:
108+
- *artifacts_template_compose
109+
- *artifacts_staging_apk
110+
publishing:
111+
firebase:
112+
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
113+
android:
114+
app_id: $FIREBASE_APP_ID_STAGING
115+
groups:
116+
- android-chapter
117+
artifact_type: 'apk'
118+
119+
build-and-deploy-template-compose-production:
120+
name: Build and deploy template-compose production to Firebase App Distribution
121+
<<: *configure_environment
122+
triggering:
123+
events:
124+
- push
125+
branch_patterns:
126+
- pattern: main
127+
scripts:
128+
- *set_up_google_services_files_from_environment_variables
129+
- *detekt_on_template_compose
130+
- *unit_test_on_template_compose
131+
- name: Build APK for production
132+
working_directory: ./template-compose
133+
script: |
134+
./gradlew assembleProductionDebug -PversionCode=$BUILD_NUMBER
135+
artifacts:
136+
- *artifacts_template_compose
137+
- *artifacts_production_apk
138+
publishing:
139+
firebase:
140+
firebase_service_account: $FIREBASE_SERVICE_ACCOUNT_CREDENTIALS
141+
android:
142+
app_id: $FIREBASE_APP_ID_PRODUCTION
143+
groups:
144+
- android-chapter
145+
artifact_type: 'apk'

0 commit comments

Comments
 (0)