iOS Build and Deploy #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: iOS Build and Deploy to App Store Connect | |
on: | |
workflow_dispatch: | |
jobs: | |
ios_deployment: | |
runs-on: macos-latest | |
steps: | |
# Step 1: Checkout Code | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
# Step 2: Set up Flutter SDK | |
- name: Set up Flutter SDK | |
uses: flutter-actions/setup-flutter@v3 | |
with: | |
channel: stable | |
version: 3.27.1 # Keep this up to date with flutter --version | |
# Step 3: Install Dependencies | |
- name: Install Dependencies | |
run: | | |
flutter clean | |
flutter pub get | |
flutter analyze --fatal-infos | |
# Step 4: Install Codemagic CLI | |
- name: Install Codemagic CLI | |
run: pip install codemagic-cli-tools | |
# Step 5: Initialize Keychain | |
- name: Initialize Keychain | |
env: | |
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | |
run: | | |
security create-keychain -p "$KEYCHAIN_PASSWORD" $RUNNER_TEMP/app-signing.keychain-db | |
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $RUNNER_TEMP/app-signing.keychain-db | |
security list-keychain -d user -s $RUNNER_TEMP/app-signing.keychain-db | |
# Step 6: Configure Provisioning Profile | |
- name: Configure Provisioning Profile | |
env: | |
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }} | |
run: | | |
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles | |
echo "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode > ~/Library/MobileDevice/Provisioning\ Profiles/profile.mobileprovision | |
# Step 7: Configure Distribution Certificate | |
- name: Configure Distribution Certificate | |
env: | |
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }} | |
P12_PASSWORD: ${{ secrets.P12_PASSWORD }} | |
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | |
run: | | |
echo "$BUILD_CERTIFICATE_BASE64" | base64 --decode > /tmp/certificate.p12 | |
security import /tmp/certificate.p12 -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $RUNNER_TEMP/app-signing.keychain-db | |
security set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" $RUNNER_TEMP/app-signing.keychain-db | |
# Step 8: Parse Build Number and Name from pubspec.yaml | |
- name: Parse Build Number and Name | |
id: version | |
run: | | |
VERSION_LINE=$(grep '^version:' pubspec.yaml) | |
VERSION=$(echo $VERSION_LINE | cut -d' ' -f2 | cut -d'+' -f1) | |
BUILD_NUMBER=$(echo $VERSION_LINE | cut -d'+' -f2) | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV | |
# Step 9: Generate ExportOptions.plist from Template | |
- name: Generate ExportOptions.plist | |
env: | |
EXPORT_METHOD: "app-store" | |
EXPORT_DESTINATION: "export" | |
BUNDLE_ID: "de.equirinya.piusapp" #change this when adapting to another app | |
PROVISIONING_PROFILE: "profile.mobileprovision" | |
TEAM_ID: ${{ secrets.TEAM_ID }} | |
run: | | |
envsubst < ios/Runner/ExportOptions-Template.plist > ios/Runner/ExportOptions.plist | |
# Step 10: Build IPA | |
- name: Build IPA | |
run: | | |
flutter build ipa \ | |
--release \ | |
--build-number=$BUILD_NUMBER \ | |
--build-name=$VERSION \ | |
--export-options-plist=ios/Runner/ExportOptions.plist | |
# Step 11: Upload IPA to App Store Connect | |
- name: Upload to App Store Connect | |
env: | |
APPSTORE_API_KEY_ID: ${{ secrets.APPSTORE_API_KEY_ID }} | |
APPSTORE_API_PRIVATE_KEY: ${{ secrets.APPSTORE_API_PRIVATE_KEY }} | |
APPSTORE_ISSUER_ID: ${{ secrets.APPSTORE_ISSUER_ID }} | |
run: | | |
APP_FILE=$(find $(pwd) -name "*.ipa") | |
app-store-connect publish \ | |
--api-key-id "$APPSTORE_API_KEY_ID" \ | |
--api-key "$APPSTORE_API_PRIVATE_KEY" \ | |
--issuer-id "$APPSTORE_ISSUER_ID" \ | |
--path "$APP_FILE" | |
# Step 12: Cleanup Keychain and Profiles | |
- name: Cleanup | |
if: ${{ always() }} | |
run: | | |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db | |
rm -rf ~/Library/MobileDevice/Provisioning\ Profiles |