---
# [샘플] iOS 전체 빌드 파이프라인
# Build → Archive → Export → TestFlight 업로드 → 배포

property:
  workspace: /path/to/project
  scheme: Runner
  configuration: Release
  version: 1.0.0
  exportOptionsPath: <!property.workspace>/ios/ExportOptions.plist
  archivePath: <!property.workspace>/build/Runner.xcarchive
  exportPath: <!property.workspace>/build/export
  ipaPath: <!property.exportPath>/Runner.ipa
  apiKeyPath: <!property.workspace>/api_key.json
  appID: com.example.app

pipeline:
  id: main
  workflow:
  - exe: build-ios
  - exe-handle:
      id: archive-ios
      on-success:
      - exe: export-ios
      - exe: upload-testflight
      - exe: check-testflight
      - exe: distribute-testflight
      - exe: notify-success
      on-fail:
      - exe: notify-fail

commands:
# xcodebuild build (시뮬레이터 테스트용)
- command: BuildiOS
  id: build-ios
  param:
    # xcworkspaceFilePath 우선, 없으면 xcodeProjectFilePath 사용
    scheme: <!property.scheme>
    configuration: <!property.configuration>
    xcworkspaceFilePath: <!property.workspace>/ios/Runner.xcworkspace
    destination: "generic/platform=iOS Simulator"

# xcodebuild archive
- command: ArchiveiOS
  id: archive-ios
  param:
    scheme: <!property.scheme>
    configuration: <!property.configuration>
    xcworkspaceFilePath: <!property.workspace>/ios/Runner.xcworkspace
    archivePath: <!property.archivePath>

# .xcarchive → .ipa export
- command: ExportiOS
  id: export-ios
  param:
    archivePath: <!property.archivePath>
    exportOptionPlistPath: <!property.exportOptionsPath>
    exportPath: <!property.exportPath>

# TestFlight 업로드 (notarytool)
- command: TestflightUpload
  id: upload-testflight
  param:
    apiKeyPath: <!property.apiKeyPath>
    ipaPath: <!property.ipaPath>

# TestFlight 상태 확인
- command: TestflightStatusCheck
  id: check-testflight
  param:
    appID: <!property.appID>
    apiKeyPath: <!property.apiKeyPath>
    version: <!property.version>
    buildNumber: "1"

# 테스터 그룹에 배포
- command: TestflightDistribute
  id: distribute-testflight
  param:
    apiKeyPath: <!property.apiKeyPath>
    appID: <!property.appID>
    message: " 새 빌드 출시"
    testers: "Internal Testers"

- command: MattermostBuild
  id: notify-success
  param:
    url: https://mattermost.example.com/api/v4/posts
    token: your-mattermost-token
    channelId: your-channel-id
    appName: MyApp
    type: ios
    color: 45C45E
    version: <!property.version>
    downloadURL: https://testflight.apple.com/join/xxxxxx

- command: Mattermost
  id: notify-fail
  param:
    url: https://mattermost.example.com/api/v4/posts
    token: your-mattermost-token
    channelId: your-channel-id
    message: "❌ iOS 빌드 실패 - v<!property.version>"

# CodeSign - 앱 코드 서명
- command: CodeSign
  id: code-sign
  param:
    appPath: <!property.archivePath>/Products/Applications/Runner.app
    certificationName: "iPhone Developer: your@email.com (ABC1234567)"
    entitlementPath: <!property.workspace>/ios/Runner/Runner_Entitlements.plist

# CodeSignVerify - 서명 확인
- command: CodeSignVerify
  id: code-sign-verify
  param:
    appPath: <!property.archivePath>/Products/Applications/Runner.app

# ProductBuild - 앱 패키징
- command: ProductBuild
  id: product-build
  param:
    appPath: <!property.archivePath>/Products/Applications/Runner.app
    identifier: com.example.app
    installCertificationName: "Apple Distribution: your@email.com (ABC1234567)"
    unsignedResultPath: <!property.exportPath>/Runner_unsigned.ipa
    signedResultPath: <!property.ipaPath>

# Notarize - 앱	notarization
- command: Notarize
  id: notarize
  param:
    macPassword: your-mac-password
    bundleName: Runner.app
    teamId: ABC1234567
    appleAccount: your@email.com
    applePassword: "@keychain:app-specific-password"
    resultPath: <!property.exportPath>/notarized
