// ci-generator/ios-jobs.ts — iOS CI job builders for Xcode Cloud + TestFlight + App Store (SPEC-325)
// -- Shared helpers -----------------------------------------------------------
function checkoutStep() {
    return { name: 'Checkout code', uses: 'actions/checkout@v4' };
}
function rubySetupStep() {
    return {
        name: 'Setup Ruby for Fastlane',
        uses: 'ruby/setup-ruby@v1',
        with: { 'ruby-version': 'bundler-cache: true' },
    };
}
function selectXcodeStep() {
    return {
        name: 'Select Xcode version',
        run: 'sudo xcode-select -s /Applications/Xcode.app',
    };
}
function installFastlaneStep() {
    return {
        name: 'Install Fastlane',
        run: 'gem install fastlane --no-document',
    };
}
/** Common env vars required for Apple API authentication. */
function appleApiEnv() {
    return {
        APPLE_API_KEY: '${{ secrets.APPLE_API_KEY }}',
        APPLE_API_ISSUER_ID: '${{ secrets.APPLE_API_ISSUER_ID }}',
        APPLE_API_KEY_ID: '${{ secrets.APPLE_API_KEY_ID }}',
    };
}
function resolveScheme(config) {
    return config.scheme ?? 'MyApp';
}
// -- Job builders -------------------------------------------------------------
/**
 * Build a basic Xcode Cloud setup job that compiles and runs unit tests.
 * Uses macos-latest runner with Apple API key authentication.
 */
export function buildXcodeCloudJob(config) {
    const scheme = resolveScheme(config);
    const steps = [
        checkoutStep(),
        selectXcodeStep(),
        {
            name: 'Build and test (Xcode)',
            run: [
                `xcodebuild clean build test \\`,
                `  -scheme "${scheme}" \\`,
                `  -destination 'platform=iOS Simulator,name=iPhone 15,OS=latest' \\`,
                `  CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO \\`,
                '  | xcpretty && exit "${PIPESTATUS[0]}"',
            ].join('\n'),
            env: appleApiEnv(),
        },
    ];
    return {
        name: 'iOS — Xcode Build & Test',
        runsOn: 'macos-latest',
        steps,
        env: appleApiEnv(),
    };
}
/**
 * Build a Fastlane TestFlight job that compiles a signed IPA and uploads it.
 * Requires MATCH_PASSWORD secret for code signing via Fastlane Match.
 */
export function buildFastlaneTestFlightJob(config) {
    const scheme = resolveScheme(config);
    const steps = [
        checkoutStep(),
        selectXcodeStep(),
        rubySetupStep(),
        installFastlaneStep(),
        {
            name: 'Build IPA',
            run: [
                `fastlane gym \\`,
                `  --scheme "${scheme}" \\`,
                `  --export_method app-store \\`,
                `  --output_directory ./build`,
            ].join('\n'),
            env: {
                MATCH_PASSWORD: '${{ secrets.MATCH_PASSWORD }}',
            },
        },
        {
            name: 'Upload to TestFlight',
            run: 'fastlane pilot upload --ipa ./build/*.ipa --skip_waiting_for_build_processing true',
            env: appleApiEnv(),
        },
    ];
    const fullEnv = {
        ...appleApiEnv(),
        MATCH_PASSWORD: '${{ secrets.MATCH_PASSWORD }}',
    };
    return {
        name: 'iOS — TestFlight Upload',
        runsOn: 'macos-latest',
        steps,
        env: fullEnv,
    };
}
/**
 * Build a production App Store submission job via Fastlane Deliver.
 * Runs only on main branch. Requires Apple API credentials and signing secrets.
 */
export function buildAppStoreDeployJob(config) {
    const scheme = resolveScheme(config);
    const steps = [
        checkoutStep(),
        selectXcodeStep(),
        rubySetupStep(),
        installFastlaneStep(),
        {
            name: 'Build IPA (production)',
            run: [
                `fastlane gym \\`,
                `  --scheme "${scheme}" \\`,
                `  --configuration Release \\`,
                `  --export_method app-store \\`,
                `  --output_directory ./build`,
            ].join('\n'),
            env: {
                MATCH_PASSWORD: '${{ secrets.MATCH_PASSWORD }}',
            },
        },
        {
            name: 'Submit to App Store',
            run: [
                'fastlane deliver \\',
                '  --ipa ./build/*.ipa \\',
                '  --submit_for_review false \\',
                '  --automatic_release false',
            ].join('\n'),
            env: appleApiEnv(),
        },
    ];
    const fullEnv = {
        ...appleApiEnv(),
        MATCH_PASSWORD: '${{ secrets.MATCH_PASSWORD }}',
    };
    return {
        name: 'iOS — App Store Submission',
        runsOn: 'macos-latest',
        steps,
        env: fullEnv,
    };
}
//# sourceMappingURL=ios-jobs.js.map