Skip to content

Commit

Permalink
Setup CI/CD for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneha-s committed Apr 5, 2024
1 parent 1859590 commit fee81af
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 66 deletions.
1 change: 0 additions & 1 deletion .github/script/install_secret_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ echo $GOOGLE_SERVICES_JSON_BASE64 | base64 -di > android/app/google-services.jso
echo $GOOGLE_SERVICES_PLIST_IOS_BASE64 | base64 -di > ios/Runner/GoogleService-Info.plist
echo $GOOGLE_SERVICES_PLIST_MACOS_BASE64 | base64 -di > macos/Runner/GoogleService-Info.plist
echo $DESKTOP_CREDENTIALS_BASE64 | base64 -di > lib/desktop_credentials.dart
echo $FIREBASE_OPTIONS_BASE64 | base64 -di > lib/firebase_options.dart
echo $WEB_INDEX_HTML_BASE64 | base64 -di > web/index.html
88 changes: 47 additions & 41 deletions .github/workflows/ios_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,66 @@
name: iOS build
name: Publish to App Store Connect

on: push

on:
push:
branches:
- main
workflow_dispatch:

jobs:
ios_deploy_testflight:
runs-on: macos-latest
env:
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }}
APP_STORE_CONNECT_KEY_IDENTIFIER: ${{ secrets.APP_STORE_CONNECT_KEY_IDENTIFIER }}
APP_STORE_CONNECT_PRIVATE_KEY: ${{ secrets.APP_STORE_CONNECT_PRIVATE_KEY }}
APP_STORE_APP_ID: ${{ secrets.APP_STORE_APP_ID }}
DIST_CERTIFICATE: ${{ secrets.DIST_CERTIFICATE_BASE64 }}
DIST_CERTIFICATE_PASSWORD: ${{ secrets.DIST_CERTIFICATE_PASSWORD }}
DIST_PROFILE: ${{ secrets.DIST_PROFILE_BASE64 }}

steps:

- name: Checkout
uses: actions/checkout@v2

- name: Install the Apple certificate and provisioning profile
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.PROVISIONING_PROFILE }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}

run: |
# create variables
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate and provisioning profile from secrets
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode > $CERTIFICATE_PATH
# create temporary keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
chmod +x ios/install_dist_profile.sh && ./ios/install_dist_profile.sh
- name: Set up Flutter SDK
uses: subosito/flutter-action@v2
with:
channel: 'stable'
cache: true

- name: Retrieve the secret and decode it to file
env:
FIREBASE_OPTIONS_BASE64: ${{ secrets.FIREBASE_OPTIONS_BASE64 }}
GOOGLE_SERVICES_PLIST_IOS_BASE64: ${{ secrets.GOOGLE_SERVICES_PLIST_IOS_BASE64 }}
run: |
echo $FIREBASE_OPTIONS_BASE64 | base64 -di > lib/firebase_options.dart
echo $GOOGLE_SERVICES_PLIST_IOS_BASE64 | base64 -di > ios/Runner/GoogleService-Info.plist
- name: Install dependencies
run: |
flutter pub get
- name: Building ipa
- name: Install Codemagic CLI tools
run: pip install codemagic-cli-tools

- name: Set up keychain
run: keychain initialize

- name: Set up Provisioning Profiles
run: |
PROFILES_HOME="$HOME/Library/MobileDevice/Provisioning Profiles"
mkdir -p "$PROFILES_HOME"
PROFILE_PATH="$(mktemp "$PROFILES_HOME"/$(uuidgen).mobileprovision)"
echo ${DIST_PROFILE} | base64 --decode > "$PROFILE_PATH"
- name: Set up signing certificate
run: |
echo DIST_CERTIFICATE | base64 --decode > /tmp/certificate.p12
keychain add-certificates --certificate /tmp/certificate.p12 --certificate-password $DIST_CERTIFICATE_PASSWORD
- name: Setup Code signing settings on Xcode project
run: xcode-project user-profiles


- name: Build ipa for Distribution
run: |
file='VERSION'
fileData=`cat $file`
Expand All @@ -62,12 +70,10 @@ jobs:
IFS=''
buildName="${versionValue[0]}.${versionValue[1]}.${{ github.run_number }}"
echo "Uploading build $buildName"
flutter build ipa --build-number=$buildNumber --build-name=$buildName --export-options-plist=ios/Runner/ExportOptions.plist
echo "Uploading app to iTC..."
xcrun altool --upload-app -t ios -f build/ios/ipa/*.ipa -u $ITC_USER_NAME -p $ITC_USER_PASSWORD
flutter build ipa --release --build-number=$buildNumber --build-name=$buildName --export-options-plist=$HOME/export_options.plist
- name: Clean up keychain and provisioning profile
if: ${{ always() }}
- name: Upload to App Store Connect
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision
APP_FILE=$(find $(pwd) -name "*.ipa")
app-store-connect publish \
--path "$APP_FILE"
11 changes: 0 additions & 11 deletions ios/install_dist_certs.sh

This file was deleted.

12 changes: 0 additions & 12 deletions ios/install_dist_profile.sh

This file was deleted.

4 changes: 3 additions & 1 deletion lib/ui/sign_in/bloc/sign_in_view_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import 'package:projectunity/data/services/account_service.dart';
Expand Down Expand Up @@ -55,7 +56,8 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
} else {
emit(state.copyWith(appleSignInLoading: false));
}
} on Exception {
} catch(e,stack) {
FirebaseCrashlytics.instance.recordError(e, stack);
emit(state.copyWith(
appleSignInLoading: false, error: somethingWentWrongError));
}
Expand Down

0 comments on commit fee81af

Please sign in to comment.