|
| 1 | +# GitHub Actions Workflow Optimization Guide |
| 2 | + |
| 3 | +## Current Issue |
| 4 | +The `generate-xcode-project` workflow is taking approximately 20 minutes to complete, with the majority of time (18 minutes) spent on the "Install bootstrap mint" step. |
| 5 | + |
| 6 | +## Implemented Optimizations |
| 7 | + |
| 8 | +### 1. Direct Mint Binary Caching |
| 9 | +Instead of using the `setup-mint` action, we now: |
| 10 | +- Cache the mint binary directly at `/usr/local/bin/mint` |
| 11 | +- Install mint via Homebrew only if not cached |
| 12 | +- This avoids potential overhead from the setup action |
| 13 | + |
| 14 | +### 2. Improved Mint Packages Caching |
| 15 | +- Cache the `~/.mint` directory separately |
| 16 | +- Use content-based cache keys with `hashFiles('**/Mintfile')` |
| 17 | +- Added version suffix (`-v2`) to cache key for cache busting when needed |
| 18 | + |
| 19 | +### 3. Timeout Protection |
| 20 | +- Added `timeout-minutes: 10` to the mint bootstrap step |
| 21 | +- Prevents the job from hanging indefinitely |
| 22 | + |
| 23 | +### 4. Using `--link` Flag |
| 24 | +- Added `--link` flag to `mint bootstrap` command |
| 25 | +- Creates symlinks instead of copying binaries, which is faster |
| 26 | + |
| 27 | +## Additional Optimization Strategies |
| 28 | + |
| 29 | +### 1. Pre-built Docker Image |
| 30 | +Consider creating a custom Docker image with mint and dependencies pre-installed: |
| 31 | +```yaml |
| 32 | +runs-on: ubuntu-latest |
| 33 | +container: |
| 34 | + image: your-org/ios-build-image:latest |
| 35 | +``` |
| 36 | +
|
| 37 | +### 2. Self-hosted Runners |
| 38 | +For frequently run workflows, consider using self-hosted runners with pre-installed dependencies. |
| 39 | +
|
| 40 | +### 3. Parallel Installation |
| 41 | +If you have multiple independent dependencies, install them in parallel: |
| 42 | +```yaml |
| 43 | +- name: Install dependencies |
| 44 | + run: | |
| 45 | + mint install realm/SwiftLint@0.53.0 & |
| 46 | + mint install yonaskolb/xcodegen@2.38.0 & |
| 47 | + mint install bloomberg/xcdiff@0.11.0 & |
| 48 | + wait |
| 49 | +``` |
| 50 | +
|
| 51 | +### 4. Conditional Execution |
| 52 | +Only run the workflow when necessary: |
| 53 | +```yaml |
| 54 | +on: |
| 55 | + push: |
| 56 | + paths: |
| 57 | + - '**/*.swift' |
| 58 | + - '**/project.yml' |
| 59 | + - '**/Mintfile' |
| 60 | +``` |
| 61 | +
|
| 62 | +### 5. Cache Warming |
| 63 | +Create a scheduled workflow to warm caches: |
| 64 | +```yaml |
| 65 | +on: |
| 66 | + schedule: |
| 67 | + - cron: '0 0 * * 0' # Weekly |
| 68 | +``` |
| 69 | +
|
| 70 | +## Monitoring Performance |
| 71 | +
|
| 72 | +Add timing information to track improvements: |
| 73 | +```yaml |
| 74 | +- name: Bootstrap mint packages |
| 75 | + run: | |
| 76 | + echo "::group::Mint Bootstrap Timing" |
| 77 | + time mint bootstrap --link |
| 78 | + echo "::endgroup::" |
| 79 | +``` |
| 80 | +
|
| 81 | +## Expected Results |
| 82 | +With these optimizations, the workflow should complete in: |
| 83 | +- First run: ~5-10 minutes (building caches) |
| 84 | +- Subsequent runs: ~2-3 minutes (using caches) |
| 85 | +
|
| 86 | +## Troubleshooting |
| 87 | +
|
| 88 | +### Cache Misses |
| 89 | +If caches are frequently missing: |
| 90 | +1. Check cache key stability |
| 91 | +2. Verify runner OS consistency |
| 92 | +3. Monitor cache size limits (10GB per repository) |
| 93 | +
|
| 94 | +### Slow Network |
| 95 | +If downloads are slow: |
| 96 | +1. Consider using GitHub's package registry |
| 97 | +2. Use a CDN for binary distribution |
| 98 | +3. Implement retry logic with exponential backoff |
0 commit comments