Skip to content

Build iOS App Release #10

Build iOS App Release

Build iOS App Release #10

Workflow file for this run

name: Build iOS App
on: workflow_dispatch
# release:
# types: [published]
jobs:
build_with_signing:
runs-on: macos-latest
steps:
# Checkout the repo
- name: Checkout repository
uses: actions/checkout@v4
# Install the Apple certificate and provisioning profile
- name: Install the Apple certificate and provisioning profile
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
DISTRIBUTION_CERT_BASE64: ${{ secrets.DISTRIBUTION_CERT_BASE64 }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
# create variables
BUILD_CERT_PATH=$RUNNER_TEMP/build_certificate.p12
DISTRIB_CERT_PATH=$RUNNER_TEMP/ios_distribution.cer
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate and provisioning profile from secrets
echo -n "$DISTRIBUTION_CERT_BASE64" | base64 --decode -o $DISTRIB_CERT_PATH
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $BUILD_CERT_PATH
echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_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 $DISTRIB_CERT_PATH -P "$P12_PASSWORD" -A -t cert -k $KEYCHAIN_PATH
security import $BUILD_CERT_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
# apply provisioning profile
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
# Create p8 Auth Key from secrets
- name: Create p8 Auth Key
env:
APP_STORE_CONNECT_KEY: ${{ secrets.APP_STORE_CONNECT_KEY }}
APP_STORE_KEY_ID: ${{ secrets.APP_STORE_KEY_ID }}
run: |
# Create private_keys folder
KEY_PATH=$GITHUB_WORKSPACE/example/build/ios/ipa/private_keys
mkdir -p $KEY_PATH
AUTH_KEY_PATH=$KEY_PATH/AuthKey_$APP_STORE_KEY_ID.p8
# import certificate and provisioning profile from secrets
echo -n "$APP_STORE_CONNECT_KEY" | base64 --decode -o $AUTH_KEY_PATH
# Install Flutter SDK
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"
architecture: x64
# Get package dependencies and generate files
- name: Get package dependencies and generate files
run: |
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
# Get example app dependencies and generate files
- name: Get example app dependencies and generate files
working-directory: example
run: |
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
# Build ios example app
- name: Build ios example app
working-directory: example
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
APP_STORE_CONNECT_KEY: ${{ secrets.APP_STORE_CONNECT_KEY }}
APP_STORE_KEY_ID: ${{ secrets.APP_STORE_KEY_ID }}
APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }}
run: |
# Get app version from file
FILE_VALUE=`cat $GITHUB_WORKSPACE/lib/version.dart`
VERSION=`echo $FILE_VALUE | sed "s/[^']*'\([^']*\)'.*/\1/"`
VNAME=`echo $VERSION | sed "s/+.*//"`
VBUILD=${VERSION#*+}
# Build ios app with flutter
# flutter build ipa --build-name $VNAME --build-number $VBUILD --dart-define="PROJECT_ID=$PROJECT_ID" --release
flutter build ios --config-only --dart-define="PROJECT_ID=$PROJECT_ID" --release
# Set version values to Info.plist
/usr/libexec/Plistbuddy -c "Set CFBundleVersion $VBUILD" "ios/Runner/Info.plist"
/usr/libexec/Plistbuddy -c "Set CFBundleShortVersionString $VNAME" "ios/Runner/Info.plist"
# Archive and export
xcodebuild -workspace "$GITHUB_WORKSPACE/example/ios/Runner.xcworkspace" -scheme Runner -sdk iphoneos -destination generic/platform=iOS -archivePath "$GITHUB_WORKSPACE/example/ios/Runner.xcarchive" archive
xcodebuild -exportArchive -sdk iphoneos -archivePath "$GITHUB_WORKSPACE/example/ios/Runner.xcarchive" -exportOptionsPlist "$GITHUB_WORKSPACE/example/ios/Runner/ExportOptionsRelease.plist" -exportPath "$GITHUB_WORKSPACE/example/build/ios/ipa" -authenticationKeyIssuerID $APPLE_ISSUER_ID -authenticationKeyID $APP_STORE_KEY_ID -authenticationKeyPath "$GITHUB_WORKSPACE/example/build/ios/ipa/private_keys/AuthKey_$APP_STORE_KEY_ID.p8"
# Run fastlane
# - name: Delivering with fastlane
# working-directory: example/ios
# env:
# FASTLANE_USER: ${{ secrets.FASTLANE_USER }}
# FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: ${{ secrets.FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD }}
# run: fastlane beta
# - name: Get App Store Connect API Key
# uses: timheuer/[email protected]
# with:
# fileName: AuthKey_${{ secrets.APP_STORE_KEY_ID }}.p8
# fileDir: example/build/ios/ipa/private_keys
# encodedString: ${{ secrets.APP_STORE_CONNECT_KEY }}
# Upload IPA to Testflight
- name: Upload IPA to Testflight
working-directory: example/build/ios/ipa
env:
APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }}
APP_STORE_KEY_ID: ${{ secrets.APP_STORE_KEY_ID }}
run: xcrun altool --upload-app --type ios -f web3modal_flutter.ipa --apiKey $APP_STORE_KEY_ID --apiIssuer $APPLE_ISSUER_ID
# Clean up keychain and provisioning profile
- name: Clean up keychain and provisioning profile
if: ${{ always() }}
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision
# Clean up Flutter envs
- name: Clean up Flutter envs
if: ${{ always() }}
run: |
flutter clean
cd example
flutter clean