-
Notifications
You must be signed in to change notification settings - Fork 11
364 lines (318 loc) · 16.8 KB
/
reusable-build-sample-apps.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
name: Reusable build sample apps workflow
on:
workflow_call:
inputs:
use_latest_sdk_version:
description: "Whether this workflow should build sample apps with latest SDK version or source code"
type: boolean
required: false
default: false
jobs:
build-android-sample-app:
strategy:
fail-fast: false # if one sample app fails to build, let the other sample apps continue to build and not cancel them.
matrix: # Use a matrix allowing us to build multiple apps in parallel. Just add an entry to the matrix and it will build!
sample-app:
# List all sample apps you want to have compiled.
# List item is name of directory inside of "apps" directory for the corresponding app to compile.
- name: "amiapp_flutter"
cio-workspace-name: "Mobile: Flutter"
defaults:
run:
working-directory: apps/${{ matrix.sample-app.name }}
runs-on: ubuntu-latest
outputs:
APP_VERSION_NAME: ${{ steps.set_output.outputs.APP_VERSION_NAME }}
APP_VERSION_CODE: ${{ steps.set_output.outputs.APP_VERSION_CODE }}
name: Building Android sample app ${{ matrix.sample-app.name }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Workaround for bug https://github.com/actions/checkout/issues/1471
- name: Capture Git Context
shell: bash
id: git-context
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
echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
- 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 }}
USE_LATEST_SDK_VERSION: ${{ inputs.use_latest_sdk_version }}
run: |
# Initialize with the default distribution group
distribution_groups=("$ALL_BUILDS_GROUP")
# Append distribution groups based on branch and context
[[ "$CURRENT_BRANCH" == "refs/heads/feature/"* ]] && distribution_groups+=("$FEATURE_BUILDS_GROUP")
[[ "$CURRENT_BRANCH" == "refs/heads/main" ]] && distribution_groups+=("$NEXT_BUILDS_GROUP")
[[ "$USE_LATEST_SDK_VERSION" == "true" ]] && distribution_groups+=("$PUBLIC_BUILDS_GROUP")
# Export the groups as an environment variable
echo "firebase_distribution_groups=$(IFS=','; echo "${distribution_groups[*]}")" >> $GITHUB_ENV
# Install CLI tools, Ruby, and Ruby dependencies for Fastlane
# CLI to replace strings in files. The CLI recommends using `cargo install` which is slow. This Action is fast because it downloads pre-built binaries.
# If using sd on macos, "brew install" works great. for Linux, this is the recommended way.
- name: Install sd CLI to use later in the workflow
uses: kenji-miyake/setup-sd@v2
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true # cache tools to make builds faster in future
working-directory: apps/${{ matrix.sample-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/${{ matrix.sample-app.name }}
lane: "generate_new_version"
options: '{"branch_name":"${{ github.ref_name }}", "pull_request_number":"${{ github.event.pull_request.number }}"}'
- name: Update Flutter SDK Version
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: apps/${{ matrix.sample-app.name }}
lane: "update_flutter_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/${{ matrix.sample-app.name }}
lane: "update_flutter_android_app_version"
options: ${{ inputs.use_latest_sdk_version == true && format('{{"version_name":"{0}"}}', env.LATEST_TAG) || '' }}
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 flutter environment files
run: |
ENV_FILE=".env"
touch "$ENV_FILE"
echo "BUILD_TIMESTAMP=$(date +%s)" >> "$ENV_FILE"
echo "CDP_API_KEY=${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', matrix.sample-app.name)] }}" >> "$ENV_FILE"
echo "SITE_ID=${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', matrix.sample-app.name)] }}" >> "$ENV_FILE"
echo "WORKSPACE_NAME=${{ matrix.sample-app.cio-workspace-name }}" >> "$ENV_FILE"
echo "BRANCH_NAME=${{ env.BRANCH_NAME }}" >> "$ENV_FILE"
echo "COMMIT_HASH=${{ env.COMMIT_HASH }}" >> "$ENV_FILE"
LAST_TAG="${{ env.LATEST_TAG :- "untagged" }}"
COMMITS_AHEAD=$(git rev-list $LAST_TAG..HEAD --count 2>/dev/null || echo "untracked")
echo "COMMITS_AHEAD_COUNT=$COMMITS_AHEAD" >> "$ENV_FILE"
if [ "${{ inputs.use_latest_sdk_version }}" == "true" ]; then
echo "SDK_VERSION=${{ env.LATEST_TAG }}" >> "$ENV_FILE"
fi
# Make sure to fetch dependencies only after updating the version numbers and workspace credentials
- name: Setup flutter environment and install dependencies
uses: ./.github/actions/setup-flutter
- name: Use SDK release version for sample app (if needed)
working-directory: apps/amiapp_flutter
run: |
dart run scripts/update_sample_app_sdk_version.dart
cat pubspec.lock
- name: Install flutter dependencies for sample app
run: flutter pub get
- 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/${{ matrix.sample-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()
uses: customerio/mobile-ci-tools/github-actions/slack-notify-sample-app/v1
with:
build_status: ${{ steps.android_build.outcome }}
app_icon_emoji: ":flutter:"
app_name: "Flutter"
firebase_app_id: ${{ secrets[format('SAMPLE_APPS_{0}_FIREBASE_APP_ID_ANDROID', matrix.sample-app.name)] }}
firebase_distribution_groups: ${{ env.firebase_distribution_groups }}
git_context: "${{ env.BRANCH_NAME }} (${{ env.COMMIT_HASH }})"
icon_url: "https://img.icons8.com/color/512/flutter.png"
instructions_guide_link: ${{ secrets.SAMPLE_APPS_INSTRUCTIONS_GUIDE_LINK }}
platform: "android"
sdk_name: "Flutter SDK"
sdk_version: ${{ env.SDK_VERSION_NAME }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
build-ios-sample-app:
strategy:
fail-fast: false # if one sample app fails to build, let the other sample apps continue to build and not cancel them.
matrix: # Use a matrix allowing us to build multiple apps in parallel. Just add an entry to the matrix and it will build!
sample-app:
# List all sample apps you want to have compiled.
# List item is name of directory inside of "apps" directory for the corresponding app to compile.
- name: "amiapp_flutter"
cio-workspace-name: "Mobile: Flutter"
defaults:
run:
working-directory: apps/${{ matrix.sample-app.name }}
runs-on: macos-14
outputs:
APP_VERSION_NAME: ${{ steps.set_output.outputs.APP_VERSION_NAME }}
APP_VERSION_CODE: ${{ steps.set_output.outputs.APP_VERSION_CODE }}
name: Building iOS sample app ${{ matrix.sample-app.name }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Workaround for bug https://github.com/actions/checkout/issues/1471
- name: Capture Git Context
shell: bash
id: git-context
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
echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
- 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 }}
USE_LATEST_SDK_VERSION: ${{ inputs.use_latest_sdk_version }}
run: |
# Initialize with the default distribution group
distribution_groups=("$ALL_BUILDS_GROUP")
# Append distribution groups based on branch and context
[[ "$CURRENT_BRANCH" == "refs/heads/feature/"* ]] && distribution_groups+=("$FEATURE_BUILDS_GROUP")
[[ "$CURRENT_BRANCH" == "refs/heads/main" ]] && distribution_groups+=("$NEXT_BUILDS_GROUP")
[[ "$USE_LATEST_SDK_VERSION" == "true" ]] && distribution_groups+=("$PUBLIC_BUILDS_GROUP")
# Export the groups as an environment variable
echo "firebase_distribution_groups=$(IFS=','; echo "${distribution_groups[*]}")" >> $GITHUB_ENV
# Install CLI tools, Ruby, and Ruby dependencies for Fastlane
- 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: '3.1'
bundler-cache: true # cache tools to make builds faster in future
working-directory: apps/${{ matrix.sample-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/${{ matrix.sample-app.name }}
lane: "generate_new_version"
options: '{"branch_name":"${{ github.ref_name }}", "pull_request_number":"${{ github.event.pull_request.number }}"}'
- name: Update Flutter SDK Version
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: apps/${{ matrix.sample-app.name }}
lane: "update_flutter_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/${{ matrix.sample-app.name }}
lane: "update_flutter_ios_app_version"
options: ${{ inputs.use_latest_sdk_version == true && format('{{"version_name":"{0}"}}', env.LATEST_TAG) || '' }}
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 flutter environment files
run: |
ENV_FILE=".env"
touch "$ENV_FILE"
echo "BUILD_TIMESTAMP=$(date +%s)" >> "$ENV_FILE"
echo "CDP_API_KEY=${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', matrix.sample-app.name)] }}" >> "$ENV_FILE"
echo "SITE_ID=${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_SITE_ID', matrix.sample-app.name)] }}" >> "$ENV_FILE"
echo "WORKSPACE_NAME=${{ matrix.sample-app.cio-workspace-name }}" >> "$ENV_FILE"
echo "BRANCH_NAME=${{ env.BRANCH_NAME }}" >> "$ENV_FILE"
echo "COMMIT_HASH=${{ env.COMMIT_HASH }}" >> "$ENV_FILE"
LAST_TAG="${{ env.LATEST_TAG :- "untagged" }}"
COMMITS_AHEAD=$(git rev-list $LAST_TAG..HEAD --count 2>/dev/null || echo "untracked")
echo "COMMITS_AHEAD_COUNT=$COMMITS_AHEAD" >> "$ENV_FILE"
if [ "${{ inputs.use_latest_sdk_version }}" == "true" ]; then
echo "SDK_VERSION=${{ env.LATEST_TAG }}" >> "$ENV_FILE"
fi
- name: Setup workspace credentials in iOS environment files
run: |
cp "ios/Env.swift.example" "ios/Env.swift"
sd 'cdpApiKey: String = ".*"' "cdpApiKey: String = \"${{ secrets[format('CUSTOMERIO_{0}_WORKSPACE_CDP_API_KEY', matrix.sample-app.name)] }}\"" "ios/Env.swift"
# Make sure to fetch dependencies only after updating the version numbers and workspace credentials
- name: Setup flutter environment and install dependencies
uses: ./.github/actions/setup-flutter
- name: Use SDK release version for sample app (if needed)
working-directory: apps/amiapp_flutter
run: |
dart run scripts/update_sample_app_sdk_version.dart
cat pubspec.lock
- name: Install flutter dependencies for sample app
run: flutter pub get
- name: Setup iOS environment for sample app
uses: customerio/customerio-ios/.github/actions/setup-ios@main
with:
xcode-version: ${{ env.XCODE_VERSION }}
- name: Cache CocoaPods downloaded dependencies for faster builds in the future
uses: actions/cache@v4
with:
path: Pods
key: ${{ runner.os }}-${{ matrix.sample-app.name }}-Pods-${{ github.ref }}
restore-keys: |
${{ runner.os }}-${{ matrix.sample-app.name }}-Pods
- name: pod install
run: pod install --project-directory=ios
- name: Build and upload iOS app via Fastlane
id: ios_build
uses: maierj/fastlane-action@v3.1.0
with:
subdirectory: apps/${{ matrix.sample-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()
uses: customerio/mobile-ci-tools/github-actions/slack-notify-sample-app/v1
with:
build_status: ${{ steps.ios_build.outcome }}
app_icon_emoji: ":flutter:"
app_name: "Flutter"
firebase_app_id: ${{ secrets[format('SAMPLE_APPS_{0}_FIREBASE_APP_ID_IOS', matrix.sample-app.name)] }}
firebase_distribution_groups: ${{ env.firebase_distribution_groups }}
git_context: "${{ env.BRANCH_NAME }} (${{ env.COMMIT_HASH }})"
icon_url: "https://img.icons8.com/color/512/flutter.png"
instructions_guide_link: ${{ secrets.SAMPLE_APPS_INSTRUCTIONS_GUIDE_LINK }}
platform: "ios"
sdk_name: "Flutter SDK"
sdk_version: ${{ env.SDK_VERSION_NAME }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}