CI/CD with Codemagic
Relevant source files
The following files were used as context for generating this wiki page:
MoodTune utilizes Codemagic as its primary Continuous Integration and Continuous Delivery (CI/CD) platform to automate the building, testing, and distribution of the Flutter mobile application. The pipeline is specifically configured to handle the complexities of a multi-flavor environment (Development, Staging, Production) and automated deployment to iOS TestFlight.
Sources: README.md:46, CLAUDE.md:144, codemagic.yaml:1-5
Workflow Architecture
The automation is defined in codemagic.yaml, focusing on the ios-testflight workflow. This workflow leverages a mac_mini_m2 instance to perform specialized macOS-based tasks such as iOS code signing and building the IPA (iOS App Store Package).
The diagram above illustrates the sequential execution of the iOS build and distribution pipeline.
Sources: codemagic.yaml:2-62
Environment Configuration
The pipeline requires specific environment variables and secret groups to communicate with external services like Supabase, Sentry, and the backend API.
Secret Groups and Variables
The configuration is split into functional groups to manage sensitive keys:
| Group | Required Variables | Description |
|---|---|---|
| Supabase | SUPABASE_URL, SUPABASE_ANON_KEY | Database and Auth credentials. |
| Sentry | SENTRY_DSN | Error monitoring and crash reporting. |
| MoodTune | API_BASE_URL, JAMENDO_CLIENT_ID | Backend services and music catalog access. |
Sources: codemagic.yaml:18-23, CLAUDE.md:133-142
iOS Signing Settings
Automated signing is configured for the app_store distribution type, targeting the bundle identifier com.jmagic.moodtune.
ios_signing:
distribution_type: app_store
bundle_identifier: com.jmagic.moodtune
Sources: codemagic.yaml:10-12
Build and Deployment Process
Build Orchestration
The pipeline executes a series of scripts to prepare the environment and build the application. A critical step involves determining the build number by querying App Store Connect to ensure versioning continuity.
This sequence details the interaction between the build server and App Store Connect for automated versioning.
Sources: codemagic.yaml:40-57
Implementation Details
The build command uses --dart-define to inject environment-specific variables at compile time. This ensures that the production flavor points to the correct production backend and Supabase instances.
flutter build ipa --release \
--flavor production \
--target lib/main_production.dart \
--build-name=$BUILD_NAME \
--build-number=$BUILD_NUMBER \
--dart-define=SUPABASE_URL=$SUPABASE_URL \
--dart-define=API_BASE_URL=$API_BASE_URL
Sources: codemagic.yaml:50-57, README.md:65-71
Automated Distribution
Once the build is successful, Codemagic automatically publishes the generated .ipa artifact to Apple TestFlight.
Distribution Targets
The workflow is configured to automatically submit the build to specific beta tester groups defined in App Store Connect:
- Beta Testers
- First batch
Sources: codemagic.yaml:63-68
Artifact Archiving
In addition to the binary distribution, the pipeline preserves logs for debugging:
build/ios/ipa/*.ipa: The final production binary./tmp/xcodebuild_logs/*.log: Detailed compilation and signing logs from Xcode.
Sources: codemagic.yaml:59-61
Integration with Testing
While the ios-testflight workflow focuses on distribution, the project utilizes very_good_analysis and very_good test for quality assurance. The pubspec.yaml includes dependencies for bloc_test and mocktail to support robust unit and widget testing, which are expected to be executed as part of the broader CI strategy.
Sources: pubspec.yaml:38-42, README.md:83-85, CLAUDE.md:21-27
The CI/CD implementation via Codemagic ensures that MoodTune maintains a high release velocity while ensuring that every production build is signed, versioned, and delivered to testers through an automated and repeatable process.