Skip to content

Commit 8a3513c

Browse files
renefloorxsahil03x
andauthored
feat(repo): add sample-app distribution workflow (#2124)
Co-authored-by: Sahil Kumar <[email protected]>
1 parent f20a393 commit 8a3513c

34 files changed

+1211
-452
lines changed
+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: distribute_external
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
platform:
9+
description: 'Platform to build (android, ios, or both)'
10+
required: true
11+
default: 'both'
12+
type: choice
13+
options:
14+
- android
15+
- ios
16+
- both
17+
18+
env:
19+
FLUTTER_VERSION: '3.x'
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
determine_platforms:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
run_ios: ${{ steps.set_matrix.outputs.run_ios }}
30+
run_android: ${{ steps.set_matrix.outputs.run_android }}
31+
steps:
32+
- name: Determine platforms to build
33+
id: set_matrix
34+
run: |
35+
# Is this a release?
36+
is_release="${{ github.event_name == 'release' }}"
37+
38+
# If it's a release event, build both platforms
39+
if [[ "$is_release" == "true" ]]; then
40+
echo "Building all platforms due to release"
41+
echo "run_ios=true" >> $GITHUB_OUTPUT
42+
echo "run_android=true" >> $GITHUB_OUTPUT
43+
exit 0
44+
fi
45+
46+
# For manual workflow dispatch, store platform in a variable
47+
platform="${{ github.event.inputs.platform }}"
48+
echo "Selected platform: $platform"
49+
50+
# Set outputs only if they should be true
51+
[[ "$platform" == "ios" || "$platform" == "both" ]] && echo "run_ios=true" >> $GITHUB_OUTPUT
52+
[[ "$platform" == "android" || "$platform" == "both" ]] && echo "run_android=true" >> $GITHUB_OUTPUT
53+
54+
android:
55+
needs: determine_platforms
56+
if: ${{ needs.determine_platforms.outputs.run_android == 'true' }}
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Connect Bot
60+
uses: webfactory/[email protected]
61+
with:
62+
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
63+
64+
- name: "Git Checkout"
65+
uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
69+
- name: "Install Flutter"
70+
uses: subosito/flutter-action@v2
71+
with:
72+
flutter-version: ${{ env.FLUTTER_VERSION }}
73+
channel: stable
74+
cache: true
75+
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
76+
77+
- name: "Install Tools"
78+
run: flutter pub global activate melos
79+
80+
- name: "Bootstrap Workspace"
81+
run: melos bootstrap
82+
83+
- name: Setup Ruby
84+
uses: ruby/setup-ruby@v1
85+
with:
86+
bundler-cache: true
87+
working-directory: sample_app/android
88+
89+
- name: Setup Firebase Service Account'
90+
working-directory: sample_app/android
91+
run: echo "${{ secrets.SAMPLE_FIREBASE_UPLOAD_CREDENTIALS }}" | base64 --decode | jq > ./firebase-service-account.json
92+
93+
- name: Distribute to Firebase
94+
working-directory: sample_app/android
95+
run: bundle exec fastlane distribute_to_firebase
96+
97+
ios:
98+
needs: determine_platforms
99+
if: ${{ needs.determine_platforms.outputs.run_ios == 'true' }}
100+
runs-on: macos-15 # Testflight requires macOS 15 or later
101+
steps:
102+
- name: Connect Bot
103+
uses: webfactory/[email protected]
104+
with:
105+
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
106+
107+
- name: "Git Checkout"
108+
uses: actions/checkout@v4
109+
with:
110+
fetch-depth: 0
111+
112+
- name: "Install Flutter"
113+
uses: subosito/flutter-action@v2
114+
with:
115+
flutter-version: ${{ env.FLUTTER_VERSION }}
116+
channel: stable
117+
cache: true
118+
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
119+
120+
- name: "Install Tools"
121+
run: flutter pub global activate melos
122+
123+
- name: "Bootstrap Workspace"
124+
run: melos bootstrap
125+
126+
- name: Setup Ruby
127+
uses: ruby/setup-ruby@v1
128+
with:
129+
bundler-cache: true
130+
working-directory: sample_app/ios
131+
132+
- name: Distribute to TestFlight
133+
working-directory: sample_app/ios
134+
env:
135+
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
136+
APPSTORE_API_KEY: ${{ secrets.APPSTORE_API_KEY }}
137+
run: bundle exec fastlane distribute_to_testflight
+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: distribute_internal
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
inputs:
9+
platform:
10+
description: 'Platform to build (android, ios, or both)'
11+
required: true
12+
default: 'both'
13+
type: choice
14+
options:
15+
- android
16+
- ios
17+
- both
18+
19+
env:
20+
FLUTTER_VERSION: '3.x'
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
determine_platforms:
28+
runs-on: ubuntu-latest
29+
outputs:
30+
run_ios: ${{ steps.set_matrix.outputs.run_ios }}
31+
run_android: ${{ steps.set_matrix.outputs.run_android }}
32+
steps:
33+
- name: Determine platforms to build
34+
id: set_matrix
35+
run: |
36+
# Is this a branch push?
37+
is_branch_push="${{ github.event_name == 'push' }}"
38+
39+
# If it's a branch push, build both platforms
40+
if [[ "$is_branch_push" == "true" ]]; then
41+
echo "Building all platforms due to branch push"
42+
echo "run_ios=true" >> $GITHUB_OUTPUT
43+
echo "run_android=true" >> $GITHUB_OUTPUT
44+
exit 0
45+
fi
46+
47+
# For manual workflow dispatch, store platform in a variable
48+
platform="${{ github.event.inputs.platform }}"
49+
echo "Selected platform: $platform"
50+
51+
# Set outputs only if they should be true
52+
[[ "$platform" == "ios" || "$platform" == "both" ]] && echo "run_ios=true" >> $GITHUB_OUTPUT
53+
[[ "$platform" == "android" || "$platform" == "both" ]] && echo "run_android=true" >> $GITHUB_OUTPUT
54+
55+
android:
56+
needs: determine_platforms
57+
if: ${{ needs.determine_platforms.outputs.run_android == 'true' }}
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 30
60+
steps:
61+
- name: Connect Bot
62+
uses: webfactory/[email protected]
63+
with:
64+
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
65+
66+
- name: "Git Checkout"
67+
uses: actions/checkout@v4
68+
with:
69+
fetch-depth: 0
70+
71+
- name: "Install Flutter"
72+
uses: subosito/flutter-action@v2
73+
with:
74+
flutter-version: ${{ env.FLUTTER_VERSION }}
75+
channel: stable
76+
cache: true
77+
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
78+
79+
- name: "Install Tools"
80+
run: flutter pub global activate melos
81+
82+
- name: "Bootstrap Workspace"
83+
run: melos bootstrap
84+
85+
- name: Setup Ruby
86+
uses: ruby/setup-ruby@v1
87+
with:
88+
bundler-cache: true
89+
working-directory: sample_app/android
90+
91+
- name: Setup Firebase Service Account'
92+
working-directory: sample_app/android
93+
run: echo "${{ secrets.SAMPLE_FIREBASE_UPLOAD_CREDENTIALS }}" | base64 --decode | jq > ./firebase-service-account.json
94+
95+
- name: Distribute to Firebase
96+
working-directory: sample_app/android
97+
run: bundle exec fastlane distribute_to_firebase
98+
99+
ios:
100+
needs: determine_platforms
101+
if: ${{ needs.determine_platforms.outputs.run_ios == 'true' }}
102+
runs-on: macos-latest
103+
timeout-minutes: 30
104+
steps:
105+
- name: Connect Bot
106+
uses: webfactory/[email protected]
107+
with:
108+
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
109+
110+
- name: "Git Checkout"
111+
uses: actions/checkout@v4
112+
with:
113+
fetch-depth: 0
114+
115+
- name: "Install Flutter"
116+
uses: subosito/flutter-action@v2
117+
with:
118+
flutter-version: ${{ env.FLUTTER_VERSION }}
119+
channel: stable
120+
cache: true
121+
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
122+
123+
- name: "Install Tools"
124+
run: flutter pub global activate melos
125+
126+
- name: "Bootstrap Workspace"
127+
run: melos bootstrap
128+
129+
- name: Setup Ruby
130+
uses: ruby/setup-ruby@v1
131+
with:
132+
bundler-cache: true
133+
working-directory: sample_app/ios
134+
135+
- name: Setup Firebase Service Account
136+
working-directory: sample_app/ios
137+
run: echo "${{ secrets.SAMPLE_FIREBASE_UPLOAD_CREDENTIALS }}" | base64 --decode | jq > ./firebase-service-account.json
138+
139+
- name: Distribute to Firebase
140+
working-directory: sample_app/ios
141+
env:
142+
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
143+
APPSTORE_API_KEY: ${{ secrets.APPSTORE_API_KEY }}
144+
run: bundle exec fastlane distribute_to_firebase

.github/workflows/pr_title.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
doc
2727
repo
2828
localization
29+
samples
2930
requireScope: true
3031
env:
3132
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/stream_flutter_workflow.yml

+43
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,49 @@ jobs:
139139
path: packages/stream_chat_flutter/coverage/lcov.info
140140
min_coverage: 44
141141

142+
build:
143+
name: build (${{ matrix.platform }})
144+
runs-on: ${{ matrix.os }}
145+
if: github.event.pull_request.draft == false
146+
timeout-minutes: 30
147+
strategy:
148+
fail-fast: false
149+
matrix:
150+
include:
151+
- platform: android
152+
os: ubuntu-latest
153+
working-directory: sample_app/android
154+
build-command: bundle exec fastlane build_apk
155+
- platform: ios
156+
os: macos-latest
157+
working-directory: sample_app/ios
158+
build-command: bundle exec fastlane build_ipa no_codesign:true
159+
160+
steps:
161+
- name: "Git Checkout"
162+
uses: actions/checkout@v4
163+
with:
164+
fetch-depth: 0
165+
- name: "Install Flutter"
166+
uses: subosito/flutter-action@v2
167+
with:
168+
flutter-version: ${{ env.flutter_version }}
169+
channel: stable
170+
cache: true
171+
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
172+
- name: "Install Tools"
173+
run: flutter pub global activate melos
174+
- name: "Bootstrap Workspace"
175+
run: melos bootstrap
176+
- name: Setup Ruby and Gems
177+
uses: ruby/setup-ruby@v1
178+
with:
179+
working-directory: ${{ matrix.working-directory }}
180+
bundler-cache: true
181+
- name: "Build ${{ matrix.platform }} App"
182+
working-directory: ${{ matrix.working-directory }}
183+
run: ${{ matrix.build-command }}
184+
142185
draft-build:
143186
runs-on: ubuntu-latest
144187
if: github.event.pull_request.draft == true

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ GeneratedPluginRegistrant.*
4646
**/android/gradlew.bat
4747
**/android/local.properties
4848
**/android/**/GeneratedPluginRegistrant.java
49+
**/android/app/.cxx
4950

5051
# iOS/XCode related
5152
**/ios/**/*.mode1v3
@@ -124,9 +125,16 @@ gradle-wrapper.jar
124125
**/test/**/failures/**/*.*
125126
!**/test/**/goldens/ci/*.*
126127

128+
# Fastlane related
129+
**/fastlane/report.xml
130+
**/fastlane/Preview.html
131+
**/fastlane/screenshots
132+
**/fastlane/test_output
133+
127134
# Exceptions to the above rules
128135
!/pubspec.lock
129136
!**/example/web/sql-wasm.js
130137
!**/example/web/sql-wasm.wasm
131138
!/sample_app/web/sql-wasm.js
132-
!/sample_app/web/sql-wasm.wasm
139+
!/sample_app/web/sql-wasm.wasm
140+
!/sample_app/android/app/google-services.json

sample_app/Fastfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
opt_out_usage
2+
3+
# Have an easy way to get the root of the project
4+
def root_path
5+
Dir.pwd.sub(/.*\Kfastlane/, '').sub(/.*\Kandroid/, '').sub(/.*\Kios/, '').sub(/.*\K\/\//, '')
6+
end
7+
8+
# Have an easy way to run flutter tasks on the root of the project
9+
lane :sh_on_root do |options|
10+
Dir.chdir(root_path) { sh(options[:command]) }
11+
end
12+
13+
# Tasks to be reused on each platform flow
14+
lane :fetch_dependencies do
15+
sh_on_root(command: "flutter pub get --suppress-analytics")
16+
end

sample_app/android/.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.1.0

sample_app/android/Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source "https://rubygems.org"
2+
3+
gem "fastlane"
4+
5+
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
6+
eval_gemfile(plugins_path) if File.exist?(plugins_path)

0 commit comments

Comments
 (0)