-
Notifications
You must be signed in to change notification settings - Fork 13
296 lines (261 loc) · 12.4 KB
/
build-sample-app.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: Build Sample App
on:
workflow_call:
inputs:
app_name:
description: "Name of the sample app to build"
required: true
type: string
branch_name:
description: "Branch name for versioning"
required: false
type: string
cio-workspace-name:
description: "Name of the Customer.io workspace to use"
required: true
type: string
sdk_version:
default: ""
description: "SDK version to use (optional, defaults to local dependency)"
required: false
type: string
outputs:
sdk_version_name:
description: "SDK version used in the build"
value: ${{ jobs.build-sample-app.outputs.sdk_version_name }}
app_version_name:
description: "Generated app version name"
value: ${{ jobs.build-sample-app.outputs.app_version_name }}
app_version_code:
description: "Generated app version code"
value: ${{ jobs.build-sample-app.outputs.app_version_code }}
env:
XCODE_VERSION: "15.3"
RUBY_VERSION: "3.0"
NODE_VERSION: "18"
jobs:
build-sample-app:
name: Building sample app ${{ inputs.app_name }} with SDK version ${{ inputs.sdk_version }}
runs-on: macos-14
defaults:
run:
working-directory: Apps/${{ inputs.app_name }} # sets working directory for all steps in this job
outputs:
sdk_version_name: ${{ steps.export-vars.outputs.sdk_version_name }}
app_version_name: ${{ steps.export-vars.outputs.app_version_name }}
app_version_code: ${{ steps.export-vars.outputs.app_version_code }}
steps:
- name: Check out code with conditional fetch-depth
uses: actions/checkout@v4
with:
fetch-depth: 0 # Workaround for bug https://github.com/actions/checkout/issues/1471
# Install CLI tools, Ruby, and Ruby dependencies for Fastlane
- name: Set IS_PRIMARY_APP
run: |
if [[ "${{ inputs.app_name }}" == "APN" ]]; then
echo "IS_PRIMARY_APP=true" >> $GITHUB_ENV
else
echo "IS_PRIMARY_APP=false" >> $GITHUB_ENV
fi
- name: Set Default Firebase Distribution Groups
shell: bash
env:
# Distribution group constants
ALL_BUILDS_GROUP: all-builds
FEATURE_BUILDS_GROUP: feature-branch
NEXT_BUILDS_GROUP: next
PUBLIC_BUILDS_GROUP: public
# Input variables
CURRENT_BRANCH: ${{ github.ref }}
run: |
# Initialize with the default distribution group
distribution_groups=("$ALL_BUILDS_GROUP")
# Append distribution groups based on branch and context if the app is primary
if [[ "$IS_PRIMARY_APP" == "true" ]]; then
[[ "$CURRENT_BRANCH" == "refs/heads/feature/"* ]] && distribution_groups+=("$FEATURE_BUILDS_GROUP")
[[ "$CURRENT_BRANCH" == "refs/heads/main" ]] && distribution_groups+=("$NEXT_BUILDS_GROUP")
[[ -n "${{ inputs.sdk_version }}" ]] && distribution_groups+=("$PUBLIC_BUILDS_GROUP")
fi
# Export the groups as an environment variable
echo "firebase_distribution_groups=$(IFS=','; echo "${distribution_groups[*]}")" >> $GITHUB_ENV
- name: Install CLI tools used in CI script
shell: bash
run: |
brew install sd # used in CI script as an easier to use sed CLI. Replaces text in files.
brew install xcbeautify # used by fastlane for output
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true # cache tools to make builds faster in future
working-directory: Apps/${{ inputs.app_name }}
# Update version numbers and workspace credentials before building the app
- name: Generate New Version
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: Apps/${{ inputs.app_name }}
lane: "generate_new_version"
options: >
{
"branch_name": "${{ inputs.branch_name || github.ref_name }}",
"pull_request_number": "${{ github.event.pull_request.number }}",
"sdk_version": "${{ inputs.sdk_version }}"
}
- name: Export App and SDK Version Info
id: export-vars
run: |
echo "Exporting SDK and App Version..."
echo "sdk_version_name=${SDK_VERSION_NAME}" >> $GITHUB_OUTPUT
echo "app_version_name=${APP_VERSION_NAME}" >> $GITHUB_OUTPUT
echo "app_version_code=${APP_VERSION_CODE}" >> $GITHUB_OUTPUT
env:
SDK_VERSION_NAME: ${{ env.SDK_VERSION_NAME }}
APP_VERSION_NAME: ${{ env.APP_VERSION_NAME }}
APP_VERSION_CODE: ${{ env.APP_VERSION_CODE }}
- name: Update React Native SDK Version
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: Apps/${{ inputs.app_name }}
lane: "update_react_native_sdk_version"
env:
SDK_VERSION_NAME: ${{ env.SDK_VERSION_NAME }}
APP_VERSION_NAME: ${{ env.APP_VERSION_NAME }}
APP_VERSION_CODE: ${{ env.APP_VERSION_CODE }}
- name: Update Sample App Version
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: Apps/${{ inputs.app_name }}
lane: "update_react_native_app_version"
env:
SDK_VERSION_NAME: ${{ env.SDK_VERSION_NAME }}
APP_VERSION_NAME: ${{ env.APP_VERSION_NAME }}
APP_VERSION_CODE: ${{ env.APP_VERSION_CODE }}
- name: Set Git Context Variables
run: |
echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> $GITHUB_ENV
COMMIT_HASH="${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}"
echo "COMMIT_HASH=${COMMIT_HASH:0:7}" >> $GITHUB_ENV
- name: Setup workspace credentials in React Native environment files
run: |
# Determine the correct file extension (.js or .ts)
if [ -f "env.sample.js" ]; then
ENV_FILE="env.js"
cp "env.sample.js" "$ENV_FILE"
elif [ -f "env.sample.ts" ]; then
ENV_FILE="env.ts"
cp "env.sample.ts" "$ENV_FILE"
else
echo "No env.sample.js or env.sample.ts file found."
exit 1
fi
# Update keys in the environment file
sd "buildTimestamp: .*" "buildTimestamp: $(date +%s)," "$ENV_FILE"
sd "cdpApiKey: '.*'" "cdpApiKey: '${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', inputs.app_name)] }}'" "$ENV_FILE"
sd "siteId: '.*'" "siteId: '${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', inputs.app_name)] }}'" "$ENV_FILE"
sd "workspaceName: '.*'" "workspaceName: '${{ inputs.cio-workspace-name }}'" "$ENV_FILE"
sd "branchName: '.*'" "branchName: '${{ env.BRANCH_NAME }}'" "$ENV_FILE"
sd "commitHash: '.*'" "commitHash: '${{ env.COMMIT_HASH }}'" "$ENV_FILE"
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "untagged")
COMMITS_AHEAD=$(git rev-list $LAST_TAG..HEAD --count 2>/dev/null || echo "untracked")
sd "commitsAheadCount: '.*'" "commitsAheadCount: '$COMMITS_AHEAD'" "$ENV_FILE"
- name: Setup workspace credentials in iOS environment files
working-directory: Apps/${{ inputs.app_name }}/ios
run: |
ENV_FILE="Env.swift"
cp "$ENV_FILE.example" "$ENV_FILE"
sd 'siteId: String = ".*"' "siteId: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', inputs.app_name)] }}\"" "$ENV_FILE"
sd 'cdpApiKey: String = ".*"' "cdpApiKey: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', inputs.app_name)] }}\"" "$ENV_FILE"
# Make sure to fetch dependencies only after updating version numbers and workspace credentials
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: |
**/package-lock.json
- name: Cache CocoaPods downloaded dependencies for faster builds in the future
uses: actions/cache@v4
with:
path: Apps/${{ inputs.app_name }}/Pods
key: ${{ runner.os }}-${{ inputs.app_name }}-Pods-${{ github.ref }}
restore-keys: |
${{ runner.os }}-${{ inputs.app_name }}-Pods
- name: Install dependencies to build SDK
run: npm ci
working-directory: .
- name: Install dependencies for sample app
run: |
SDK_VERSION="${{ inputs.sdk_version }}"
if [[ -n "$SDK_VERSION" ]]; then
npm run ci:install -- --cio-rn-sdk=$SDK_VERSION
else
npm run ci:install
fi
# Android setup
- name: Setup Android environment for sample app
uses: customerio/customerio-android/.github/actions/setup-android@main
- name: Build and upload Android app via Fastlane
id: android_build
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: Apps/${{ inputs.app_name }}
lane: 'android build'
options: '{"distribution_groups": "${{ env.firebase_distribution_groups }}"}'
env:
FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64 }}
continue-on-error: true # continue to build iOS app even if Android build fails
- name: Send Slack Notification for Sample App Builds (Android)
if: ${{ always() && env.IS_PRIMARY_APP == 'true' }}
uses: customerio/mobile-ci-tools/github-actions/slack-notify-sample-app/v1@main
with:
build_status: ${{ steps.android_build.outcome }}
app_icon_emoji: ":react:"
app_name: "React Native"
firebase_app_id: ${{ secrets[format('SAMPLE_APPS_{0}_FIREBASE_APP_ID_ANDROID', inputs.app_name)] }}
firebase_distribution_groups: ${{ env.firebase_distribution_groups }}
git_context: "${{ env.BRANCH_NAME }} (${{ env.COMMIT_HASH }})"
icon_url: "https://vectorified.com/images/icon-react-native-24.png"
instructions_guide_link: ${{ secrets.SAMPLE_APPS_INSTRUCTIONS_GUIDE_LINK }}
platform: "android"
sdk_name: "React Native SDK"
sdk_version: ${{ env.SDK_VERSION_NAME }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
# iOS setup
- name: Setup iOS environment for sample app
uses: customerio/customerio-ios/.github/actions/setup-ios@main
with:
xcode-version: ${{ env.XCODE_VERSION }}
- name: Build and upload iOS app via Fastlane
id: ios_build
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: Apps/${{ inputs.app_name }}
lane: "ios build"
options: '{"distribution_groups": "${{ env.firebase_distribution_groups }}"}'
env:
GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64: ${{ secrets.GOOGLE_CLOUD_MATCH_READONLY_SERVICE_ACCOUNT_B64 }}
FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_CREDS_B64 }}
- name: Send Slack Notification for Sample App Builds (iOS)
if: ${{ always() && env.IS_PRIMARY_APP == 'true' }}
uses: customerio/mobile-ci-tools/github-actions/slack-notify-sample-app/v1@main
with:
build_status: ${{ steps.ios_build.outcome }}
app_icon_emoji: ":react:"
app_name: "React Native"
firebase_app_id: ${{ secrets[format('SAMPLE_APPS_{0}_FIREBASE_APP_ID_IOS', inputs.app_name)] }}
firebase_distribution_groups: ${{ env.firebase_distribution_groups }}
git_context: "${{ env.BRANCH_NAME }} (${{ env.COMMIT_HASH }})"
icon_url: "https://vectorified.com/images/icon-react-native-24.png"
instructions_guide_link: ${{ secrets.SAMPLE_APPS_INSTRUCTIONS_GUIDE_LINK }}
platform: "ios"
sdk_name: "React Native SDK"
sdk_version: ${{ env.SDK_VERSION_NAME }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Check build statuses and mark failure
run: |
FAILED_BUILDS=()
[ "${{ steps.android_build.outcome }}" != "success" ] && FAILED_BUILDS+=("Android")
[ "${{ steps.ios_build.outcome }}" != "success" ] && FAILED_BUILDS+=("iOS")
if [ ${#FAILED_BUILDS[@]} -ne 0 ]; then
echo "Build failed for: ${FAILED_BUILDS[*]}"
exit 1
fi