|
| 1 | +# Contributing to Flutter Workmanager |
| 2 | + |
| 3 | +Thank you for your interest in contributing to Flutter Workmanager! This guide will help you get started. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | +- Flutter SDK (latest stable version) |
| 9 | +- Android Studio / Xcode for platform-specific development |
| 10 | +- Melos for monorepo management |
| 11 | + |
| 12 | +### Getting Started |
| 13 | + |
| 14 | +1. Fork and clone the repository |
| 15 | +2. Install melos globally: `dart pub global activate melos` |
| 16 | +3. Bootstrap the workspace: `melos bootstrap` |
| 17 | +4. Run tests: `melos run test` |
| 18 | + |
| 19 | +## Project Structure |
| 20 | + |
| 21 | +This is a federated plugin with the following packages: |
| 22 | +- `workmanager/` - Main plugin package |
| 23 | +- `workmanager_android/` - Android implementation |
| 24 | +- `workmanager_apple/` - iOS/macOS implementation |
| 25 | +- `workmanager_platform_interface/` - Shared interface |
| 26 | +- `example/` - Demo application |
| 27 | + |
| 28 | +## Development Workflow |
| 29 | + |
| 30 | +### Making Changes |
| 31 | + |
| 32 | +1. Create a feature branch: `git checkout -b feature/your-feature` |
| 33 | +2. Make your changes |
| 34 | +3. Run formatting: `melos run format` |
| 35 | +4. Run analysis: `melos run analyze` |
| 36 | +5. Run tests: `melos run test` |
| 37 | +6. Test on example app: `cd example && flutter run` |
| 38 | + |
| 39 | +### Code Generation |
| 40 | + |
| 41 | +If you modify the Pigeon API definition in `workmanager_platform_interface/pigeons/workmanager_api.dart`: |
| 42 | + |
| 43 | +```bash |
| 44 | +# Regenerate Pigeon files |
| 45 | +melos run generate:pigeon |
| 46 | +``` |
| 47 | + |
| 48 | +**Important**: Never manually edit generated `*.g.*` files. |
| 49 | + |
| 50 | +### Code Formatting |
| 51 | + |
| 52 | +The project uses specific formatting rules: |
| 53 | + |
| 54 | +- **Dart**: Use `dart format` (configured to exclude generated files) |
| 55 | +- **Kotlin**: Use `ktlint -F .` in root folder |
| 56 | +- **Swift**: Use SwiftLint for formatting |
| 57 | + |
| 58 | +Generated files are automatically excluded from formatting checks. |
| 59 | + |
| 60 | +## Testing |
| 61 | + |
| 62 | +### Running Tests |
| 63 | + |
| 64 | +```bash |
| 65 | +# All tests |
| 66 | +melos run test |
| 67 | + |
| 68 | +# Specific package tests |
| 69 | +cd workmanager_android && flutter test |
| 70 | +cd workmanager_apple && flutter test |
| 71 | + |
| 72 | +# Native tests |
| 73 | +cd example/android && ./gradlew :workmanager_android:test |
| 74 | +cd example/ios && xcodebuild test -workspace Runner.xcworkspace -scheme Runner |
| 75 | +``` |
| 76 | + |
| 77 | +### Integration Tests |
| 78 | + |
| 79 | +```bash |
| 80 | +# iOS integration tests |
| 81 | +melos run test:drive_ios |
| 82 | + |
| 83 | +# Android integration tests |
| 84 | +melos run test:drive_android |
| 85 | +``` |
| 86 | + |
| 87 | +### Example App Testing |
| 88 | + |
| 89 | +Always build the example app before completing your changes: |
| 90 | + |
| 91 | +```bash |
| 92 | +cd example |
| 93 | +flutter build apk --debug |
| 94 | +flutter build ios --debug --no-codesign |
| 95 | +``` |
| 96 | + |
| 97 | +## Platform-Specific Guidelines |
| 98 | + |
| 99 | +### Android |
| 100 | +- Follow Android WorkManager best practices |
| 101 | +- Test on various Android API levels |
| 102 | +- Ensure background task constraints work properly |
| 103 | + |
| 104 | +### iOS |
| 105 | +- Test both Background Fetch and BGTaskScheduler APIs |
| 106 | +- Verify 30-second execution limits are respected |
| 107 | +- Test on physical devices (background tasks don't work in simulator) |
| 108 | + |
| 109 | +## Publishing (Maintainers Only) |
| 110 | + |
| 111 | +### Pre-publish Checklist |
| 112 | + |
| 113 | +Before publishing any package, run the dry-run validation: |
| 114 | + |
| 115 | +```bash |
| 116 | +# Validate all packages are ready for publishing |
| 117 | +melos run publish:dry-run |
| 118 | + |
| 119 | +# Or for individual packages: |
| 120 | +cd workmanager && dart pub publish --dry-run |
| 121 | +cd workmanager_android && dart pub publish --dry-run |
| 122 | +cd workmanager_apple && dart pub publish --dry-run |
| 123 | +cd workmanager_platform_interface && dart pub publish --dry-run |
| 124 | +``` |
| 125 | + |
| 126 | +This validates that: |
| 127 | +- All dependencies are correctly specified |
| 128 | +- No uncommitted changes exist |
| 129 | +- Package follows pub.dev guidelines |
| 130 | +- All required files are included |
| 131 | + |
| 132 | +### Version Management |
| 133 | + |
| 134 | +Use melos for coordinated version bumps: |
| 135 | + |
| 136 | +```bash |
| 137 | +# Bump versions across related packages |
| 138 | +melos version |
| 139 | +``` |
| 140 | + |
| 141 | +### Publishing Process |
| 142 | + |
| 143 | +1. Ensure all tests pass: `melos run test` |
| 144 | +2. Run dry-run validation: `melos run publish:dry-run` |
| 145 | +3. Update CHANGELOGs for all modified packages |
| 146 | +4. Create release PR with version bumps |
| 147 | +5. After merge, tag release: `git tag v0.x.x` |
| 148 | +6. Publish packages: `melos publish --no-dry-run` |
| 149 | + |
| 150 | +## Documentation |
| 151 | + |
| 152 | +### Updating Documentation |
| 153 | + |
| 154 | +- **API docs**: Documented inline in Dart code |
| 155 | +- **User guides**: Located in `docs/` directory using docs.page |
| 156 | +- **Setup guides**: Integrated into quickstart documentation |
| 157 | + |
| 158 | +### Documentation Structure |
| 159 | + |
| 160 | +- `docs/index.mdx` - Overview and features |
| 161 | +- `docs/quickstart.mdx` - Installation and basic setup |
| 162 | +- `docs/customization.mdx` - Advanced configuration |
| 163 | +- `docs/debugging.mdx` - Troubleshooting guide |
| 164 | + |
| 165 | +### Testing Documentation |
| 166 | + |
| 167 | +Test documentation changes locally: |
| 168 | +1. Push changes to a branch |
| 169 | +2. View at: `https://docs.page/fluttercommunity/flutter_workmanager~your-branch` |
| 170 | + |
| 171 | +## GitHub Actions |
| 172 | + |
| 173 | +The project uses several CI workflows: |
| 174 | + |
| 175 | +- **Format** (`.github/workflows/format.yml`): Code formatting checks |
| 176 | +- **Analysis** (`.github/workflows/analysis.yml`): Package analysis and dry-run validation |
| 177 | +- **Test** (`.github/workflows/test.yml`): Unit tests, native tests, integration tests |
| 178 | + |
| 179 | +All checks must pass before merging PRs. |
| 180 | + |
| 181 | +## Common Issues |
| 182 | + |
| 183 | +### Generated Files |
| 184 | + |
| 185 | +If you see formatting or analysis errors in generated files: |
| 186 | +- Never manually edit `*.g.*` files |
| 187 | +- Use `melos run generate:pigeon` to regenerate |
| 188 | +- Generated files are excluded from formatting by design |
| 189 | + |
| 190 | +### CI Failures |
| 191 | + |
| 192 | +**Package analysis failures**: Usually caused by uncommitted changes or missing dependencies |
| 193 | +**Format failures**: Run `melos run format` locally first |
| 194 | +**Test failures**: Ensure all tests pass locally with `melos run test` |
| 195 | + |
| 196 | +## Getting Help |
| 197 | + |
| 198 | +- **Bug reports**: [GitHub Issues](https://github.com/fluttercommunity/flutter_workmanager/issues) |
| 199 | +- **Questions**: [GitHub Discussions](https://github.com/fluttercommunity/flutter_workmanager/discussions) |
| 200 | +- **Documentation**: [docs.page](https://docs.page/fluttercommunity/flutter_workmanager) |
| 201 | + |
| 202 | +## Code of Conduct |
| 203 | + |
| 204 | +This project follows the [Flutter Community Code of Conduct](https://github.com/fluttercommunity/community/blob/main/CODE_OF_CONDUCT.md). |
| 205 | + |
| 206 | +## License |
| 207 | + |
| 208 | +By contributing to Flutter Workmanager, you agree that your contributions will be licensed under the [MIT License](LICENSE). |
0 commit comments