Skip to content

Build iOS App Internal (beta) #2

Build iOS App Internal (beta)

Build iOS App Internal (beta) #2

name: Build iOS App Internal
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.APPLE_DISTRIBUTION_CERT }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.PROVISIONING_PROFILE_DEBUG_BASE64 }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
# create variables
BUILD_CERT_PATH=$RUNNER_TEMP/build_certificate.p12
PP_PATH=$RUNNER_TEMP/FlutterAppStoreProfileDebug.mobileprovision
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate and provisioning profile from secrets
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 $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_KEY_ID: ${{ secrets.APP_STORE_KEY_ID }}
APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }}
run: |
# Get app version from file
FILE_VALUE=$(echo | grep "^version: " pubspec.yaml)
PARTS=(${FILE_VALUE//:/ })
FULL_VERSION=${PARTS[1]}
VERSION_NUMBER=(${FULL_VERSION//-/ })
# Change bundleId in project.pbxproj
sed -i '' 's/com.web3modal.flutterExample/com.web3modal.flutterExample.debug/g' ios/Runner.xcodeproj/project.pbxproj
# Change provisioning prfile in project.pbxproj
sed -i '' 's/FlutterAppStoreProfileWithPush/FlutterAppStoreProfileDebug/g' ios/Runner.xcodeproj/project.pbxproj
# Build ios app with flutter
flutter build ios --build-name $VERSION_NUMBER --dart-define="PROJECT_ID=$PROJECT_ID" --config-only --release
cd ios
agvtool new-marketing-version $VERSION_NUMBER
agvtool next-version -all
# 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 -allowProvisioningUpdates -sdk iphoneos -archivePath "$GITHUB_WORKSPACE/example/ios/Runner.xcarchive" -exportOptionsPlist "$GITHUB_WORKSPACE/example/ios/Runner/ExportOptionsDebug.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"
# 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
- name: Notify Channel
uses: slackapi/[email protected]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: 'INCOMING_WEBHOOK'
with:
payload: |-
{
"text":"New iOS ALPHA VERSION for Web3Modal Flutter ${{ github.event.release.name }} was just deployed."
}
# Clean up
- name: Clean up
if: ${{ always() }}
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
rm ~/Library/MobileDevice/Provisioning\ Profiles/FlutterAppStoreProfileDebug.mobileprovision
flutter clean
cd example
flutter clean