> ## Documentation Index
> Fetch the complete documentation index at: https://docs.remind.tools/llms.txt
> Use this file to discover all available pages before exploring further.

# Codemagic

> Multi-platform build automation with Codemagic

# Codemagic Configuration

Complete guide for setting up and managing Codemagic CI/CD for Remind Tools.

## Overview

Codemagic handles:

* iOS builds and TestFlight deployment
* Android builds and Play Store deployment
* Web builds and hosting
* Desktop builds (macOS, Windows, Linux)

## Configuration

### codemagic.yaml

```yaml theme={null}
workflows:
  production:
    name: Production Build
    max_build_duration: 60
    environment:
      flutter: 3.19.0
      xcode: latest
      cocoapods: default
      groups:
        - production_credentials
      vars:
        APP_STORE_CONNECT_KEY_IDENTIFIER: $APP_STORE_KEY_ID
        APP_STORE_CONNECT_ISSUER_ID: $APP_STORE_ISSUER_ID
        BUNDLE_ID: "tools.remind.trips"
    
    triggering:
      events:
        - tag
      tag_patterns:
        - pattern: 'v*'
          include: true
    
    scripts:
      - name: Install dependencies
        script: |
          melos bootstrap
      
      - name: Run tests
        script: |
          melos test
      
      - name: Build iOS
        script: |
          cd apps/trips_app
          flutter build ipa --release
      
      - name: Build Android
        script: |
          cd apps/trips_app
          flutter build appbundle --release
    
    artifacts:
      - build/ios/ipa/*.ipa
      - build/app/outputs/bundle/release/*.aab
    
    publishing:
      app_store_connect:
        api_key: $APP_STORE_CONNECT_PRIVATE_KEY
        key_id: $APP_STORE_CONNECT_KEY_IDENTIFIER
        issuer_id: $APP_STORE_CONNECT_ISSUER_ID
      
      google_play:
        credentials: $GOOGLE_PLAY_CREDENTIALS
        track: internal
```

## Environment Variables

### Required Secrets

<Tabs>
  <Tab title="iOS">
    ```bash theme={null}
    APP_STORE_CONNECT_PRIVATE_KEY
    APP_STORE_CONNECT_KEY_IDENTIFIER
    APP_STORE_CONNECT_ISSUER_ID
    CERTIFICATE_PRIVATE_KEY
    PROVISIONING_PROFILE
    ```
  </Tab>

  <Tab title="Android">
    ```bash theme={null}
    GOOGLE_PLAY_CREDENTIALS
    ANDROID_KEYSTORE
    ANDROID_KEYSTORE_PASSWORD
    ANDROID_KEY_ALIAS
    ANDROID_KEY_PASSWORD
    ```
  </Tab>

  <Tab title="General">
    ```bash theme={null}
    SUPABASE_URL
    SUPABASE_ANON_KEY
    MAPBOX_ACCESS_TOKEN
    GEMINI_API_KEY
    SENTRY_DSN
    ```
  </Tab>
</Tabs>

## Build Workflows

### Production Workflow

<Steps>
  <Step title="Trigger">
    Push tag matching `v*` pattern
  </Step>

  <Step title="Environment Setup">
    Configure Flutter, Xcode, and dependencies
  </Step>

  <Step title="Testing">
    Run full test suite
  </Step>

  <Step title="Build">
    Create release builds for all platforms
  </Step>

  <Step title="Sign">
    Code sign iOS and Android builds
  </Step>

  <Step title="Deploy">
    Upload to stores
  </Step>
</Steps>

### Staging Workflow

```yaml theme={null}
staging:
  name: Staging Build
  triggering:
    events:
      - push
    branch_patterns:
      - pattern: 'develop'
  
  scripts:
    - name: Build with staging config
      script: |
        flutter build apk \
          --dart-define=ENVIRONMENT=staging
```

## Platform-Specific Configuration

### iOS Setup

<Info>
  Codemagic automatically manages certificates and provisioning profiles.
</Info>

#### Automatic Code Signing

```yaml theme={null}
ios_signing:
  distribution_type: app_store
  bundle_identifier: tools.remind.trips
```

#### Manual Code Signing

```yaml theme={null}
scripts:
  - name: Set up code signing
    script: |
      keychain initialize
      app-store-connect fetch-signing-files \
        "$BUNDLE_ID" \
        --type IOS_APP_STORE \
        --create
      keychain add-certificates
      xcode-project use-profiles
```

### Android Setup

#### Keystore Configuration

```yaml theme={null}
scripts:
  - name: Set up keystore
    script: |
      echo $ANDROID_KEYSTORE | base64 --decode > keystore.jks
      cat >> "$CM_BUILD_DIR/android/key.properties" <<EOF
      storePassword=$ANDROID_KEYSTORE_PASSWORD
      keyPassword=$ANDROID_KEY_PASSWORD
      keyAlias=$ANDROID_KEY_ALIAS
      storeFile=$CM_BUILD_DIR/keystore.jks
      EOF
```

### Web Deployment

```yaml theme={null}
web_publishing:
  firebase_hosting:
    project_id: remind-tools
    site: trips-app
    token: $FIREBASE_TOKEN
```

## Build Optimization

### Caching

```yaml theme={null}
cache:
  cache_paths:
    - $HOME/.pub-cache
    - $HOME/Library/Caches/CocoaPods
    - $FLUTTER_ROOT/.pub-cache
```

### Parallel Builds

```yaml theme={null}
workflows:
  parallel_builds:
    scripts:
      - name: Build apps in parallel
        script: |
          (
            cd apps/trips_app && flutter build apk &
            cd apps/money_app && flutter build apk &
            wait
          )
```

## Monitoring

### Build Notifications

<CardGroup cols={2}>
  <Card title="Email" icon="envelope">
    Automatic on failure
  </Card>

  <Card title="Slack" icon="slack">
    ```yaml theme={null}
    publishing:
      slack:
        channel: '#builds'
        notify_on_build_start: true
    ```
  </Card>
</CardGroup>

### Build Metrics

* Average build time: \~15 minutes
* Success rate: 95%+
* Cost per build: \$0.50

## Troubleshooting

| Issue                | Solution                      |
| -------------------- | ----------------------------- |
| iOS signing failed   | Regenerate certificates       |
| Android build failed | Check keystore validity       |
| Timeout              | Increase max\_build\_duration |
| Out of memory        | Use larger instance           |

## Best Practices

1. **Use build groups** for environment variables
2. **Cache dependencies** to speed up builds
3. **Run tests early** to fail fast
4. **Use webhooks** for deployment tracking
5. **Monitor build times** and optimize
6. **Keep artifacts** for debugging
