This document provides comprehensive information about the synchronization capabilities built into the KMP Multi-Module Project Generator. These tools help maintain consistency with the upstream template repository while allowing for project-specific customizations.
The project includes a robust synchronization system that allows you to:
- Keep up with template improvements without losing your customizations
- Automatically sync selected directories on a regular schedule
- Apply syncs manually when needed
- Preview changes before applying them
The sync-dirs.sh script is a powerful utility that synchronizes directories and files from the
upstream repository while preserving your local customizations.
-
Comprehensive Sync Coverage: Syncs the following components:
- Applications: cmp-android, cmp-desktop, cmp-ios, cmp-web
- Build System: build-logic
- Tools: fastlane, scripts
- Configuration: config, .github, .run
- Core Files: Gemfile, Gemfile.lock, ci-prepush scripts
-
Safety System:
- Automatic backup of existing files before modification
- Comprehensive error detection and recovery
- Progress indication during sync operations
- Detailed logs of all operations
-
Customization Control:
- Preserve specific files and directories from being overwritten
- Support for exclusions at both directory and root levels
- Project-specific modifications are maintained
-
Advanced Options:
- Dry-run mode to preview changes without applying them
- Force mode for non-interactive operation in automation
- Branch creation for review before merging
# Basic sync
./sync-dirs.sh
# Dry run to preview changes
./sync-dirs.sh --dry-run
# Force sync without prompts
./sync-dirs.sh --force
# Both dry run and force mode
./sync-dirs.sh --dry-run --force| Option | Description |
|---|---|
-h, --help |
Display help information and exit |
--dry-run |
Show what would be done without making changes |
-f, --force |
Skip confirmation prompts and proceed automatically |
The repository includes an enhanced GitHub workflow (sync-dirs.yml) that automates the
synchronization process in CI/CD environments.
- Scheduled Execution: Runs automatically every Monday at midnight UTC
- Manual Triggering: Can be triggered manually from GitHub Actions UI
- Pull Request Generation: Creates detailed pull requests for review
- Change Logging: Includes comprehensive change logs
- Safety Measures: Handles all sync components safely
- Git History: Maintains proper git history
To use the GitHub workflow effectively, you need to configure the proper permissions:
- Go to your repository's Settings
- Navigate to Actions > General in the left sidebar
- Scroll down to Workflow permissions
- Enable the following permissions:
- ✅ Select "Read and write permissions"
- ✅ Check "Allow GitHub Actions to create and approve pull requests"
- Click "Save" to apply the changes
To use the sync-dirs.yml workflow, you'll need to create a Personal Access Token (PAT) with the
required scopes and save it as a secret.
- Log in to your GitHub account
- Go to Developer Settings > Personal Access Tokens
- Click Generate new token (classic) or select Fine-grained tokens
- Fill in the following details:
- Note: Add a meaningful name like
Sync Workflow Token - Expiration: Choose an appropriate expiration period
- Scopes:
- ✅
repo– Full control of private repositories - ✅
workflow– To manage and trigger workflows - ✅
write:packages– To publish and write packages (if applicable)
- ✅
- Click Generate token
- Copy the token immediately and save it securely
- Navigate to the repository where the workflow resides
- Go to Settings > Secrets and variables > Actions
- Click New repository secret
- Enter the name
PAT_TOKENand paste the token as the value - Click Add secret
- Navigate to the organization settings
- Go to Settings > Secrets and variables > Actions
- Click New organization secret
- Enter the name
PAT_TOKENand paste the token as the value - Choose the repositories where this secret will be available
- Click Add secret
The sync script supports two types of exclusions:
- Directory-level exclusions: Files and directories within specific project directories
- Root-level exclusions: Files in the root of the project
Exclusions are defined in the EXCLUSIONS associative array:
declare -A EXCLUSIONS=(
["cmp-android"]="src/main/res:dir dependencies:dir src/main/ic_launcher-playstore.png:file google-services.json:file"
["cmp-web"]="src/jsMain/resources:dir src/wasmJsMain/resources:dir"
["cmp-desktop"]="icons:dir"
["cmp-ios"]="iosApp/Assets.xcassets:dir"
["root"]="secrets.env:file"
)The sync process uses a dedicated branching strategy:
- A new branch is created based on your main development branch
- A temporary branch is created from the upstream repository
- Changes are synchronized from the temporary branch to the sync branch
- The temporary branch is deleted after the sync
- The sync branch can be pushed for review and merged
- Regular Syncs: Schedule automated syncs weekly to stay current with upstream changes
- Review Changes: Always review generated PRs carefully before merging
- Backup First: Use
--dry-runto preview changes before actual sync operations - Conflict Resolution: Handle merge conflicts promptly to prevent drift
- Version Control: Maintain clean git history during syncs