-
Notifications
You must be signed in to change notification settings - Fork 26
190 lines (161 loc) · 7.33 KB
/
reusable-android-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
##################################################################################
# About
##################################################################################
# Reuseable workflow to be called from content repos.
# Build and deploy app bundle for android
#
# Version : 1.0
#
##################################################################################
# Configuration
##################################################################################
env:
APP_ID: ${{vars.APP_ID}}
APP_NAME: ${{vars.APP_NAME}}
DEPLOYMENT_NAME: ${{vars.DEPLOYMENT_NAME}}
APP_CODE_BRANCH: ${{vars.APP_CODE_BRANCH}}
PARENT_DEPLOYMENT_REPO: ${{vars.PARENT_DEPLOYMENT_REPO}}
PARENT_DEPLOYMENT_NAME: ${{vars.PARENT_DEPLOYMENT_NAME}}
PARENT_DEPLOYMENT_BRANCH: ${{vars.PARENT_DEPLOYMENT_BRANCH}}
GOOGLE_SERVICES_JSON: ${{secrets.GOOGLE_SERVICES_JSON}}
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
ALIAS: ${{secrets.ALIAS}}
KEY_STORE_PASSWORD: ${{secrets.KEY_STORE_PASSWORD}}
KEY_PASSWORD: ${{secrets.KEY_PASSWORD}}
##################################################################################
# Main Code
##################################################################################
name: Android Build
# Only keep one active build per ref (e.g. pr branch, push branch, triggering workflow ref)
concurrency:
group: android-build-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_call:
jobs:
build_action:
uses: ./.github/workflows/contentflows/reusable-app-build.yml
secrets: inherit
build_android:
runs-on: ubuntu-latest
needs: build_action
env:
GIT_SHA: ${{ needs.web_build.outputs.GIT_SHA }}
steps:
- name: Check out app code
uses: actions/checkout@v3
with:
repository: "IDEMSInternational/parenting-app-ui.git"
ref: ${{env.APP_CODE_BRANCH}}
lfs: true
- name: Checkout parent repo if needed
if: env.PARENT_DEPLOYMENT_REPO != ''
uses: actions/checkout@v3
with:
path: ".idems_app/deployments/${{env.PARENT_DEPLOYMENT_NAME}}"
repository: ${{env.PARENT_DEPLOYMENT_REPO}}
ref: ${{env.PARENT_DEPLOYMENT_BRANCH}}
- name: Checkout deployment
uses: actions/checkout@v3
with:
path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}"
- name: Populate google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ env.GOOGLE_SERVICES_JSON }}
run: echo $GOOGLE_SERVICES_JSON > android/app/google-services.json
#############################################################################
# Sync web files
# Setup node same way as web build to allow calling `npx cap sync` command
#############################################################################
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- uses: actions/cache/restore@v3
id: cache
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-yarn-v1-
- name: Install node modules
run: yarn install --immutable
- name: Set deployment
run: yarn workflow deployment set $DEPLOYMENT_NAME
- name: Populate android assets
run: yarn workflow populate_android_assets
- name: Update config names in android files
run: |
sed -i -e "s/international.idems.plh_teens/$APP_ID/g" -e "s/PLH Teens/$APP_NAME/g" ./capacitor.config.ts ./android/app/src/main/assets/capacitor.config.json ./android/app/src/main/res/values/strings.xml ./android/app/src/main/AndroidManifest.xml ./android/app/src/main/java/international/idems/plh_teens/MainActivity.java ./android/app/build.gradle
- name: Add version number to build.gradle
run: |
# Define the path to the file
FILE_PATH="./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/config.ts"
# Extract the version number
VERSION=$(grep 'content_tag_latest:' $FILE_PATH | sed 's/content_tag_latest: *"\(.*\)",/\1/')
echo "Extracted Version: $VERSION"
# Split the version into major, minor, and patch components
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
if [[ ${#VERSION_PARTS[@]} -ne 3 ]]; then
echo "Error: Version format is not as expected."
exit 1
fi
# Convert minor and patch segment to 3-digit representation
MINOR=$(printf "%03d" "${VERSION_PARTS[1]}")
PATCH=$(printf "%03d" "${VERSION_PARTS[2]}")
# Construct the new version
VERSION_CODE="${VERSION_PARTS[0]}${MINOR}${PATCH}"
echo "Version Code: $VERSION_CODE"
echo "Version: $VERSION"
# This will need to change currently looking for specific version and not place holder
sed -i -e "s/16023/$VERSION_CODE/g" -e "s/0.16.23/$VERSION/g" ./android/app/build.gradle
- name: Download Build Artifact
uses: actions/download-artifact@v3
with:
name: needs.build.outputs.artifactname
- name: Extract Build folder
run: |
mkdir www
tar -xf artifact.tar --directory www
- name: Sync Android Files
run: npx cap sync
#############################################################################
# Android Build
#############################################################################
# Java version mapping: https://stackoverflow.com/a/47457251/5693245
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "17"
java-package: jdk
cache: "gradle"
- name: Setup Android SDK
uses: android-actions/setup-android@v2
# Debug APK
- name: Build Android Debug APK
working-directory: android
run: ./gradlew :app:assembleDebug
- name: Upload debug apk
uses: actions/upload-artifact@v3
with:
name: debug_apk
path: android/app/build/outputs/apk/debug/app-debug.apk
# Signed Release Bundle
- name: Build Android Release Bundle
working-directory: android
run: ./gradlew :app:bundleRelease
- name: Sign Android Release
id: sign_aab
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: ./android/app/build/outputs/bundle/release
signingKeyBase64: ${{ env.SIGNING_KEY }}
alias: ${{ env.ALIAS }}
keyStorePassword: ${{ env.KEY_STORE_PASSWORD }}
keyPassword: ${{ env.KEY_PASSWORD }}
- name: Upload release bundle
uses: actions/upload-artifact@v3
with:
name: release_bundle
path: ${{steps.sign_aab.outputs.signedReleaseFile}}