Automate screenshots, metadata, and builds with Fastlane.
Fastlane Overview
# Install: sudo gem install fastlane
# Or: brew install fastlane
# Init: fastlane init
# Config: fastlane/Fastfile, fastlane/AppfileFastfile - iOS Lanes
# fastlane/Fastfile
default_platform(:ios)
platform :ios do
# Setup
before_all do
setup_ci if ENV['CI']
ensure_git_status_clean unless ENV['CI']
end
# ========================================
# BUILD LANES
# ========================================
lane :build_dev do
build_app(
scheme: "MyApp",
configuration: "Debug",
export_method: "development",
output_directory: "./build",
output_name: "MyApp-dev.ipa"
)
end
lane :build_release do
build_app(
scheme: "MyApp",
configuration: "Release",
export_method: "app-store",
output_directory: "./build",
output_name: "MyApp-release.ipa"
)
end
# ========================================
# SCREENSHOTS
# ========================================
lane :screenshots do
capture_screenshots(
scheme: "MyAppUITests",
devices: [
"iPhone 15 Pro",
"iPhone 15 Pro Max",
"iPhone SE (3rd generation)",
"iPad Pro (12.9-inch) (6th generation)"
],
languages: ["en-US", "es-ES", "fr-FR", "de-DE", "ja-JP"],
output_directory: "./fastlane/screenshots",
clear_previous_screenshots: true,
skip_open_summary: true
)
end
# ========================================
# TESTFLIGHT
# ========================================
lane :beta do
# Increment build number
increment_build_number(
build_number: latest_testflight_build_number + 1,
xcodeproj: "MyApp.xcodeproj"
)
# Build
build_release
# Upload to TestFlight
upload_to_testflight(
api_key_path: "./fastlane/app_store_connect.json",
skip_waiting_for_build_processing: true,
changelog: "Build #{lane_context[SharedValues::BUILD_NUMBER]}",
groups: ["Internal Testers", "External Testers"],
notify_external_testers: true
)
# Clean up
clean_build_artifacts
end
lane :beta_internal do
increment_build_number(
build_number: latest_testflight_build_number + 1,
xcodeproj: "MyApp.xcodeproj"
)
build_release
upload_to_testflight(
api_key_path: "./fastlane/app_store_connect.json",
skip_waiting_for_build_processing: true,
groups: ["Internal Testers"],
notify_external_testers: false
)
clean_build_artifacts
end
# ========================================
# APP STORE
# ========================================
lane :release do
# Ensure clean git
ensure_git_status_clean
ensure_git_branch(branch: 'main')
# Increment version
increment_version_number(
version_number: get_version_from_user,
xcodeproj: "MyApp.xcodeproj"
)
increment_build_number(
build_number: latest_testflight_build_number + 1,
xcodeproj: "MyApp.xcodeproj"
)
# Build
build_release
# Upload to TestFlight first (for review)
upload_to_testflight(
api_key_path: "./fastlane/app_store_connect.json",
skip_waiting_for_build_processing: false,
changelog: get_changelog_from_user,
groups: ["Internal Testers"],
notify_external_testers: false
)
# Wait for processing
wait_for_testflight_processing
# Submit for review
deliver(
api_key_path: "./fastlane/app_store_connect.json",
submit_for_review: true,
automatic_release: true,
force: true,
skip_metadata: false,
skip_screenshots: false,
skip_binary_upload: true,
precheck_include_in_app_purchases: false
)
# Tag release
add_git_tag(tag: "v#{get_version_number(xcodeproj: "MyApp.xcodeproj")}")
push_git_tags
clean_build_artifacts
end
# ========================================
# CODE SIGNING (Match)
# ========================================
lane :certificates do
match(
type: "development",
readonly: is_ci,
git_url: "https://github.com/your-org/certificates.git",
storage_mode: "git"
)
match(
type: "appstore",
readonly: is_ci,
git_url: "https://github.com/your-org/certificates.git",
storage_mode: "git"
)
end
lane :nuke_certificates do
match_nuke(type: "development")
match_nuke(type: "appstore")
end
# ========================================
# METADATA
# ========================================
lane :metadata do
deliver(
api_key_path: "./fastlane/app_store_connect.json",
skip_binary_upload: true,
skip_screenshots: false,
overwrite_screenshots: true,
force: true
)
end
# ========================================
# HELPER LANES
# ========================================
lane :refresh_dsyms do
download_dsyms(
version: get_version_number(xcodeproj: "MyApp.xcodeproj"),
build_number: get_build_number(xcodeproj: "MyApp.xcodeproj"),
api_key_path: "./fastlane/app_store_connect.json"
)
upload_symbols_to_crashlytics
clean_build_artifacts
end
private_lane :wait_for_testflight_processing do
# Wait for build to process (up to 30 minutes)
30.times do
build = testflight_build_information(
api_key_path: "./fastlane/app_store_connect.json"
)
if build[:build_status] == "VALID"
break
end
sleep(60)
end
end
endAppfile
# fastlane/Appfile
app_identifier "com.example.myapp"
apple_id "your@appleid.com"
team_id "YOUR_TEAM_ID"
itc_team_id "YOUR_ITC_TEAM_ID"
# For App Store Connect API (preferred)
# api_key_path "./fastlane/app_store_connect.json"App Store Connect API Key
# 1. App Store Connect → Users and Access → Keys
# 2. Generate API Key with "Admin" or "App Manager" role
# 3. Download .p8 file
# 4. Note Key ID and Issuer ID
# 5. Save as fastlane/app_store_connect.json// fastlane/app_store_connect.json
{
"key_id": "YOUR_KEY_ID",
"issuer_id": "YOUR_ISSUER_ID",
"key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
"in_house": false
}Snapshot Configuration
# fastlane/Snapfile
devices([
"iPhone 15 Pro",
"iPhone 15 Pro Max",
"iPhone SE (3rd generation)",
"iPad Pro (12.9-inch) (6th generation)",
"iPad Pro (11-inch) (4th generation)"
])
languages([
"en-US",
"es-ES",
"fr-FR",
"de-DE",
"ja-JP",
"zh-Hans",
"ko-KR"
])
scheme "MyAppUITests"
output_directory "./fastlane/screenshots"
clear_previous_screenshots true
skip_open_summary true
concurrent_simulators false
stop_after_first_error true
reinstall_app true
erase_simulator true
# Custom launch arguments for screenshots
launch_arguments([
"-UITest_Screenshots",
"-UITest_Language", "{{language}}",
"-UITest_Region", "{{region}}"
])UI Tests for Screenshots
// MyAppUITests/SnapshotTests.swift
import XCTest
final class SnapshotTests: XCTestCase {
let app = XCUIApplication()
override func setUp() {
super.setUp()
continueAfterFailure = false
// Launch arguments from snapshot
let args = ProcessInfo.processInfo.arguments
app.launchArguments = args
app.launch()
}
func testHomeScreen() {
snapshot("01_Home")
}
func testDetailScreen() {
app.cells.firstMatch.tap()
snapshot("02_Detail")
}
func testSettingsScreen() {
app.tabBars.buttons["Settings"].tap()
snapshot("03_Settings")
}
func testOnboardingScreen() {
// Reset to onboarding state
app.launchArguments += ["-UITest_Onboarding"]
app.launch()
snapshot("04_Onboarding")
}
}
// Snapshot helper (add to test target)
/*
extension XCTestCase {
func snapshot(_ name: String, waitForLoading: Bool = true) {
if waitForLoading {
sleep(1) // Wait for animations
}
let screenshot = XCUIScreen.main.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.name = name
attachment.lifetime = .keepAlways
add(attachment)
}
}
*/Match (Certificate Management)
# Setup match repository
# 1. Create private git repo for certificates
# 2. Run: fastlane match init
# 3. Enter git URL
# 4. Enter passphrase
# Generate certificates
fastlane match development
fastlane match appstore
# In CI (readonly)
fastlane match development --readonly
fastlane match appstore --readonly
# Decrypt in CI
# MATCH_PASSWORD environment variable# Matchfile
git_url("https://github.com/your-org/certificates.git")
storage_mode("git")
type("development") # or "appstore", "adhoc", "enterprise"
app_identifier(["com.example.myapp", "com.example.myapp.clip"])
username("your@appleid.com")
team_id("YOUR_TEAM_ID")
readonly(false)
keychain_name("fastlane_tmp_keychain")GitHub Actions Integration
# .github/workflows/ios-fastlane.yml
name: iOS Fastlane
on:
push:
branches: [main, develop]
workflow_dispatch:
inputs:
lane:
description: 'Fastlane lane to run'
required: true
default: 'beta'
jobs:
fastlane:
runs-on: macos-latest
timeout-minutes: 60
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
APP_STORE_CONNECT_API_KEY: ${{ secrets.APP_STORE_CONNECT_API_KEY }}
APP_STORE_CONNECT_KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }}
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }}
steps:
- uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Install Fastlane
run: bundle install
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_15.2.app
- name: Run Fastlane
run: bundle exec fastlane ${{ github.event.inputs.lane || 'beta' }}
- name: Upload build artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: build
path: build/
- name: Upload screenshots
uses: actions/upload-artifact@v4
if: always()
with:
name: screenshots
path: fastlane/screenshots/Advanced Lanes
# Feature branch deployment
lane :deploy_feature do |options|
branch = git_branch
version = get_version_number(xcodeproj: "MyApp.xcodeproj")
build = latest_testflight_build_number + 1
increment_build_number(build_number: build)
build_app(
scheme: "MyApp",
configuration: "Release",
export_method: "app-store",
output_name: "MyApp-#{branch}-#{version}-#{build}.ipa"
)
upload_to_testflight(
api_key_path: "./fastlane/app_store_connect.json",
groups: ["Feature Branch Testers"],
changelog: "Feature branch: #{branch}\nVersion: #{version}\nBuild: #{build}"
)
end
# Emergency hotfix
lane :hotfix do |options|
version = options[:version] || UI.input("Hotfix version: ")
ensure_git_branch(branch: 'main')
# Create hotfix branch
sh("git checkout -b hotfix/#{version}")
increment_version_number(version_number: version)
increment_build_number(build_number: latest_testflight_build_number + 1)
build_release
upload_to_testflight(
api_key_path: "./fastlane/app_store_connect.json",
groups: ["Internal Testers"]
)
# Commit and push
git_commit(path: ".", message: "Hotfix #{version}")
push_to_git_remote
# Create PR
create_pull_request(
title: "Hotfix #{version}",
body: "Emergency hotfix release",
base: "main"
)
endTry It
Install fastlane. Run fastlane init. Configure Match. Create lanes for beta/release. Test screenshots. Set up GitHub Actions.
sudo gem install fastlane
cd ios
fastlane init
fastlane match development
fastlane betaFastlane mastery
- Install and configure Fastlane
- Set up Match for certificate management
- Create lanes: build, beta, release, screenshots
- Configure App Store Connect API key
- Write UI tests for snapshot screenshots
- Set up GitHub Actions workflow
- Automate version/build number management
- Test full release pipeline
Fastlane automates iOS deployment: certificates (match), builds, screenshots, TestFlight, App Store. Use App Store Connect API key for auth. Lanes for different workflows. Integrate with CI/CD. Snapshot for localized screenshots.
Resources
- Fastlane Docs: https://docs.fastlane.tools/
- Fastlane iOS: https://docs.fastlane.tools/getting-started/ios/setup/
- Match: https://docs.fastlane.tools/actions/match/
- App Store Connect API: https://developer.apple.com/app-store-connect/api/