Skip to content

Instantly share code, notes, and snippets.

@heyhey1028
Last active March 29, 2023 10:29
Show Gist options
  • Save heyhey1028/5d14b22aa2990e1253c95d356a2d0fed to your computer and use it in GitHub Desktop.
Save heyhey1028/5d14b22aa2990e1253c95d356a2d0fed to your computer and use it in GitHub Desktop.
Continuous delivery of flutter app (Fastlane + Github Actions + Firebase App Distribution) -- flutter build ipa ---

created 2022/10/12

Continuous Delivery of Flutter test app

About

A sample code for distributing test ios app built with flutter via Firebase App Distribution with one tap of github actions. Sample is dedicated for circumstances using below.

  • flutter
  • fastlane
  • github actions
  • Firebase App Distribution

You can use the code by copy and paste, after preparing the prerequisites and environmental variables introduced below.

Prerequisites

Whom using the sample is expected to have done below using the code

  • manages flutter version with fvm
  • manages flavors for flutter project
  • manages iOS certificates and provisioning profiles with fastlane match
  • have activated firebase project and app distribution for the app

Environment variables you need to prepare

  • MATCH_PASSWORD: passphrase you specified at first run of fastlane match reference
  • FIREBASE_TOKEN: token generated by firebase login:ci command reference
  • PERSONAL_TOKEN: personal access token of whom has access authorization to repository used by fastlane match reference

Notes: using flutter build ipa

flutter has flutter build ios and flutter build ipa commands for building ios app. The difference is where build ios builds app without archiving, build ipa will build and archive in one go.

pros:

  • can shorten execution time up to 40% compared to doing same execution with flutter build ios

スクリーンショット 2022-10-12 11 49 03

cons:

  • certificates and provisioning files must be downloaded before execution which in this case, fastlane commands needs to be separated into two. (executing fastlane match before build command and executing fastlane firebase_app_distribution after the build.)
  • need to prepare ExportOptions.plist

shortening execution time will save time and also money spent on github actions. If there are no obstacles, I would say go with flutter build ipa command.

Example with flutter build ios is also introduced below https://gist.github.com/heyhey1028/fc8f999cc197373404ef0614d0063e25

References

Please leave a comment if you have any trouble trying to reference the code. Also pressing a star would help me motivated in creating sample codes. Thanks!!

name: App Distribution
on:
workflow_dispatch
jobs:
ios:
runs-on: macos-latest
timeout-minutes: 60
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 10
- name: Get flutter version from fvm
uses: kuhnroyal/flutter-fvm-config-action@v1
- name: Install flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: ${{ env.FLUTTER_CHANNEL }}
cache: true
cache-key: flutter
cache-path: ${{ runner.tool_cache }}/flutter
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
bundler-cache: true
- name: Setup Xcode
uses: maxim-lobanov/setup-xcode@v1.4.1
with:
xcode-version: latest-stable
- name: instal firebase cli
run: npm install -g firebase-tools
- name: Bundle install fastlane
run: cd ios && bundle install
- name: match provisioning profile
run: cd ios && bundle exec fastlane sync_adhoc_provisioning_files
- name: Build Runner
run: flutter build ipa --target lib/main_dev.dart --release --flavor Dev --export-options-plist=ios/ExportOptions.plist
- name: Distribute by App Distribution
run: cd ios && bundle exec fastlane app_distribution_dev
env:
IPA_PATH: ${{ github.workspace }}/build/ios/ipa/<YOUR IPA FILE NAME>.ipa
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<true/>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>ad-hoc</string>
<key>provisioningProfiles</key>
<dict>
<key>YOUR_APP_BUNDLE_NAME</key>
<string>match AdHoc YOUR_APP_BUNDLE_NAME</string>
</dict>
<key>signingCertificate</key>
<string>Apple Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>YOUR_TEAM_ID</string>
<key>thinning</key>
<string>&lt;none&gt;</string>
</dict>
</plist>
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:ios)
platform :ios do
desc "match adhoc for ci"
lane :sync_adhoc_provisioning_files do
if is_ci
ENV['MATCH_KEYCHAIN_NAME'] = 'TempKeychain'
ENV['MATCH_KEYCHAIN_PASSWORD'] = 'TempKeychainPassword'
create_keychain(
name: ENV['MATCH_KEYCHAIN_NAME'],
password: ENV['MATCH_KEYCHAIN_PASSWORD'],
timeout: 1800
)
match(type: "adhoc", readonly: true)
end
end
desc "upload AppDistribution Dev"
lane :app_distribution_dev do
firebase_app_distribution(
app: <YOUR FIREBASE APP ID>, (ex. 1:xxxxxxxxxxxx:ios:xxxxxxxxxxxxxxxxxxxx)
ipa_path: ENV["IPA_PATH"],
testers: [<YOUR TESTER EMAIL ADDRESS>]
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment