1. एक समर्पित Mac पर Fastlane क्यों?
Fastlane iOS और Android विकास के लिए मानक ऑटोमेशन टूल है। यह कोड साइनिंग से लेकर TestFlight डिप्लॉयमेंट तक सब कुछ संभालता है। एक समर्पित Mac Mini M4 पर Fastlane चलाना आपको देता है:
कोड साइनिंग सर्टिफ़िकेट रन के बीच बने रहते हैं। हर बिल्ड पर इंपोर्ट/एक्सपोर्ट करने की आवश्यकता नहीं।
DerivedData बना रहता है, इसलिए fastlane build 15+ के बजाय 2-4 मिनट लेता है।
सभी डिवाइस आकारों के लिए वास्तविक सिम्युलेटर के साथ fastlane snapshot चलाएं।
एक स्थिर, समर्पित वातावरण का अर्थ है कम अस्थिर डिप्लॉयमेंट और कोड साइनिंग समस्याएँ।
2. Fastlane इंस्टॉल करें
अपने Mac Mini M4 में SSH करें और Fastlane इंस्टॉल करें। हम सबसे सरल सेटअप के लिए Homebrew की सलाह देते हैं:
विकल्प A: Homebrew के ज़रिए इंस्टॉल करें (अनुशंसित)
# Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
# Install Fastlane
brew install fastlane
# Verify installation
fastlane --version
# fastlane 2.225.0
विकल्प B: RubyGems के ज़रिए इंस्टॉल करें
# Use the system Ruby or install rbenv for version management
gem install fastlane -NV
# Or with Bundler (recommended for team consistency):
# Create a Gemfile in your project root
cat > Gemfile <<'EOF'
source "https://rubygems.org"
gem "fastlane"
gem "cocoapods" # if using CocoaPods
EOF
bundle install
अपने प्रोजेक्ट में Fastlane आरंभ करें
# Navigate to your project directory
cd /path/to/your/ios-project
# Initialize Fastlane
fastlane init
# Choose option 4: "Manual setup"
# This creates the fastlane/ directory with Appfile and Fastfile
3. कोड साइनिंग के लिए Match कॉन्फ़िगर करें
Fastlane Match आपके कोड साइनिंग सर्टिफ़िकेट और प्रोविज़निंग प्रोफ़ाइल को एक निजी Git रिपॉज़िटरी या क्लाउड स्टोरेज में संग्रहीत करता है। यह सुनिश्चित करता है कि सभी मशीनें (और टीम सदस्य) समान साइनिंग पहचान का उपयोग करें।
Match आरंभ करें
# Initialize match (choose "git" for storage)
fastlane match init
# This creates fastlane/Matchfile
Matchfile कॉन्फ़िगर करें
# fastlane/Matchfile
git_url("https://github.com/your-org/ios-certificates.git")
storage_mode("git")
type("appstore") # default type, can be overridden per lane
app_identifier(["com.yourcompany.myapp"])
username("your-apple-id@example.com")
# For CI environments, use App Store Connect API key instead of username/password
# api_key_path("fastlane/AuthKey.json")
सर्टिफ़िकेट जनरेट करें
# Generate development certificates and profiles
fastlane match development
# Generate App Store distribution certificates and profiles
fastlane match appstore
# For ad-hoc distribution
fastlane match adhoc
# On CI, use readonly mode to avoid accidentally creating new certs
fastlane match appstore --readonly
4. Fastfile बनाएं (बिल्ड, टेस्ट, डिप्लॉय लेन)
अपने iOS ऐप को बिल्ड, टेस्ट, और डिप्लॉय करने के लिए लेन के साथ यहाँ एक संपूर्ण Fastfile है:
# fastlane/Fastfile
default_platform(:ios)
platform :ios do
# ---- SHARED ----
before_all do
setup_ci if ENV['CI'] # Configures keychain for CI environments
end
# ---- BUILD ----
desc "Build the app for testing"
lane :build do
match(type: "development", readonly: true)
build_app(
workspace: "MyApp.xcworkspace",
scheme: "MyApp",
configuration: "Debug",
destination: "generic/platform=iOS Simulator",
derived_data_path: "DerivedData",
skip_archive: true,
skip_codesigning: true
)
end
# ---- TEST ----
desc "Run all unit and UI tests"
lane :test do
run_tests(
workspace: "MyApp.xcworkspace",
scheme: "MyApp",
devices: ["iPhone 16 Pro"],
derived_data_path: "DerivedData",
result_bundle: true,
output_directory: "fastlane/test_results",
parallel_testing: true,
concurrent_workers: 4
)
end
# ---- BETA ----
desc "Build and push a new beta to TestFlight"
lane :beta do
# Ensure we are on a clean git state
ensure_git_status_clean
# Fetch App Store certificates
match(type: "appstore", readonly: true)
# Increment build number
increment_build_number(
build_number: latest_testflight_build_number + 1
)
# Build the app
build_app(
workspace: "MyApp.xcworkspace",
scheme: "MyApp",
export_method: "app-store",
derived_data_path: "DerivedData",
output_directory: "fastlane/builds"
)
# Upload to TestFlight
upload_to_testflight(
skip_waiting_for_build_processing: true,
api_key_path: "fastlane/AuthKey.json"
)
# Commit the version bump
commit_version_bump(
message: "chore: bump build number [skip ci]",
force: true
)
# Tag the release
add_git_tag(
tag: "beta/#{lane_context[SharedValues::BUILD_NUMBER]}"
)
push_to_git_remote
end
# ---- RELEASE ----
desc "Build and submit to App Store Review"
lane :release do
match(type: "appstore", readonly: true)
# Increment version number (patch)
increment_version_number(bump_type: "patch")
increment_build_number(
build_number: latest_testflight_build_number + 1
)
build_app(
workspace: "MyApp.xcworkspace",
scheme: "MyApp",
export_method: "app-store",
derived_data_path: "DerivedData"
)
upload_to_app_store(
submit_for_review: true,
automatic_release: false,
api_key_path: "fastlane/AuthKey.json",
precheck_include_in_app_purchases: false
)
commit_version_bump(message: "chore: release #{lane_context[SharedValues::VERSION_NUMBER]}")
add_git_tag
push_to_git_remote
end
# ---- ERROR HANDLING ----
error do |lane, exception|
# Send notification on failure (Slack, email, etc.)
# slack(
# message: "Lane #{lane} failed: #{exception.message}",
# success: false
# )
end
end
5. स्वचालित स्क्रीनशॉट सेट करें
Fastlane Snapshot कई डिवाइसों और भाषाओं में App Store स्क्रीनशॉट स्वचालित रूप से कैप्चर करता है। एक समर्पित Mac पर, यह संसाधनों के लिए प्रतिस्पर्धा किए बिना विश्वसनीय रूप से चलता है।
# Initialize snapshot
fastlane snapshot init
# This creates:
# - fastlane/Snapfile
# - fastlane/SnapshotHelper.swift (add to UI test target)
Snapfile कॉन्फ़िगर करें
# fastlane/Snapfile
devices([
"iPhone 16 Pro Max",
"iPhone 16 Pro",
"iPhone SE (3rd generation)",
"iPad Pro 13-inch (M4)"
])
languages([
"en-US",
"fr-FR",
"de-DE",
"ja"
])
scheme("MyAppUITests")
output_directory("./fastlane/screenshots")
clear_previous_screenshots(true)
# Speed up by running in parallel
concurrent_simulators(true)
अपने UI टेस्ट में Snapshot जोड़ें
// In your XCUITest file:
import XCTest
class ScreenshotTests: XCTestCase {
override func setUp() {
continueAfterFailure = false
let app = XCUIApplication()
setupSnapshot(app)
app.launch()
}
func testHomeScreen() {
snapshot("01_HomeScreen")
}
func testDetailScreen() {
let app = XCUIApplication()
app.cells.firstMatch.tap()
snapshot("02_DetailScreen")
}
func testSettings() {
let app = XCUIApplication()
app.tabBars.buttons["Settings"].tap()
snapshot("03_Settings")
}
}
एक स्क्रीनशॉट लेन जोड़ें
# Add to your Fastfile:
desc "Capture App Store screenshots"
lane :screenshots do
capture_screenshots
frame_screenshots(white: true) # Add device frames
upload_to_app_store(
skip_binary_upload: true,
skip_metadata: true,
api_key_path: "fastlane/AuthKey.json"
)
end
6. TestFlight पर डिप्लॉय करें
CI वातावरणों के लिए, अपने Apple ID क्रेडेंशियल के बजाय App Store Connect API कुंजी का उपयोग करें। यह हेडलेस सर्वरों पर 2FA प्रॉम्प्ट से बचाता है।
एक API कुंजी बनाएं
- App Store Connect > Users and Access > Keys पर जाएं
- एक नई API कुंजी जनरेट करने के लिए + बटन पर क्लिक करें
- App Manager भूमिका चुनें
.p8फ़ाइल डाउनलोड करें- Key ID और Issuer ID नोट करें
API कुंजी JSON बनाएं
# fastlane/AuthKey.json
{
"key_id": "YOUR_KEY_ID",
"issuer_id": "YOUR_ISSUER_ID",
"key": "-----BEGIN PRIVATE KEY-----\nYOUR_P8_KEY_CONTENT\n-----END PRIVATE KEY-----",
"in_house": false
}
# IMPORTANT: Add this to .gitignore!
echo "fastlane/AuthKey.json" >> .gitignore
डिप्लॉयमेंट चलाएं
# Deploy to TestFlight
fastlane beta
# Or run the full release pipeline
fastlane release
7. CI/CD के साथ एकीकृत करें
Fastlane किसी भी CI/CD प्लेटफ़ॉर्म के साथ सहजता से एकीकृत होता है। आपके सेल्फ-होस्टेड Mac Mini M4 रनर का उपयोग करते हुए यहाँ एक GitHub Actions उदाहरण है:
# .github/workflows/deploy.yml
name: Deploy to TestFlight
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: [self-hosted, macOS, ARM64, M4]
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up App Store Connect API Key
run: |
mkdir -p fastlane
echo '${{ secrets.APP_STORE_CONNECT_API_KEY }}' > fastlane/AuthKey.json
- name: Install dependencies
run: |
bundle install
pod install # if using CocoaPods
- name: Deploy to TestFlight
run: bundle exec fastlane beta
- name: Clean up API key
if: always()
run: rm -f fastlane/AuthKey.json
8. सर्वोत्तम प्रथाएँ
एक पिन किए गए Fastlane संस्करण के साथ एक Gemfile जोड़ें। सभी वातावरणों में सुसंगत संस्करण सुनिश्चित करने के लिए bundle exec fastlane चलाएं।
API कुंजियाँ 2FA प्रॉम्प्ट से बचाती हैं और CI वातावरणों के लिए अधिक सुरक्षित हैं।
match --readonly का उपयोग करें
नए सर्टिफ़िकेट के आकस्मिक निर्माण को रोकता है। केवल आवश्यकता पड़ने पर मैन्युअल रूप से सर्ट जनरेट करें।
setup_ci का उपयोग करें
यह सिस्टम कीचेन को प्रदूषित करने से बचने के लिए एक अस्थायी कीचेन बनाता है और कीचेन अनुमति संवादों को रोकता है।
एक समर्पित Mac पर, रन के बीच बिल्ड आर्टिफ़ैक्ट का पुनः उपयोग करने के लिए derived_data_path निर्दिष्ट करें।