|
| 1 | +# Laravel Updater |
| 2 | + |
| 3 | +A Laravel package for syncing with upstream repositories (GitHub, GitLab, Bitbucket, etc.) with comprehensive testing and hook support. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🔄 **Sync with any Git repository** - GitHub, GitLab, Bitbucket, Azure DevOps, self-hosted |
| 8 | +- 🧪 **Built-in testing** - Validate configuration and connectivity before syncing |
| 9 | +- 🔀 **Multiple strategies** - Support for both merge and rebase strategies |
| 10 | +- 🪝 **Pre/Post hooks** - Run custom commands before and after sync |
| 11 | +- 🛡️ **Safe operations** - Dry-run mode and comprehensive error handling |
| 12 | +- ⚙️ **Flexible configuration** - Environment variables and command-line overrides |
| 13 | +- 🚀 **Production ready** - Timeout protection and proper error handling |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +```bash |
| 18 | +composer require laravelplus/laravel-updater |
| 19 | +``` |
| 20 | + |
| 21 | +## Configuration |
| 22 | + |
| 23 | +Publish the configuration file: |
| 24 | + |
| 25 | +```bash |
| 26 | +php artisan vendor:publish --provider="LaravelPlus\LaravelUpdater\LaravelUpdaterServiceProvider" --tag="config" |
| 27 | +``` |
| 28 | + |
| 29 | +This will create `config/upstream.php` with the following options: |
| 30 | + |
| 31 | +```php |
| 32 | +return [ |
| 33 | + 'upstream_url' => env('UPSTREAM_URL', 'https://github.com/laravel/vue-starter-kit.git'), |
| 34 | + 'upstream_branch' => env('UPSTREAM_BRANCH', 'main'), |
| 35 | + 'local_branch' => env('UPSTREAM_LOCAL_BRANCH', 'main'), |
| 36 | + 'strategy' => env('UPSTREAM_STRATEGY', 'merge'), |
| 37 | + 'git_binary' => env('GIT_BINARY', 'git'), |
| 38 | + 'working_dir' => base_path(), |
| 39 | + 'commit_message' => env('UPSTREAM_COMMIT_MESSAGE', 'chore(upstream): sync from upstream'), |
| 40 | + 'allow_unrelated_histories' => (bool) env('UPSTREAM_ALLOW_UNRELATED', true), |
| 41 | + |
| 42 | + 'pre_update' => [ |
| 43 | + // 'php artisan down', |
| 44 | + // 'php artisan cache:clear', |
| 45 | + ], |
| 46 | + |
| 47 | + 'post_update' => [ |
| 48 | + // 'composer install --no-interaction --prefer-dist --optimize-autoloader', |
| 49 | + // 'npm ci', |
| 50 | + // 'npm run build', |
| 51 | + // 'php artisan migrate --force', |
| 52 | + // 'php artisan up', |
| 53 | + ], |
| 54 | +]; |
| 55 | +``` |
| 56 | + |
| 57 | +## Environment Variables |
| 58 | + |
| 59 | +Add these to your `.env` file: |
| 60 | + |
| 61 | +```env |
| 62 | +UPSTREAM_URL=https://github.com/your-upstream/repo.git |
| 63 | +UPSTREAM_BRANCH=main |
| 64 | +UPSTREAM_LOCAL_BRANCH=main |
| 65 | +UPSTREAM_STRATEGY=merge |
| 66 | +UPSTREAM_COMMIT_MESSAGE="chore(upstream): sync from upstream" |
| 67 | +UPSTREAM_ALLOW_UNRELATED=true |
| 68 | +GIT_BINARY=git |
| 69 | +``` |
| 70 | + |
| 71 | +## Usage |
| 72 | + |
| 73 | +### Basic Sync |
| 74 | + |
| 75 | +```bash |
| 76 | +php artisan upstream:sync |
| 77 | +``` |
| 78 | + |
| 79 | +### Test Before Sync |
| 80 | + |
| 81 | +```bash |
| 82 | +php artisan upstream:sync --test |
| 83 | +``` |
| 84 | + |
| 85 | +### Dry Run (See What Would Happen) |
| 86 | + |
| 87 | +```bash |
| 88 | +php artisan upstream:sync --dry-run |
| 89 | +``` |
| 90 | + |
| 91 | +### Use Rebase Strategy |
| 92 | + |
| 93 | +```bash |
| 94 | +php artisan upstream:sync --strategy=rebase |
| 95 | +``` |
| 96 | + |
| 97 | +### Override Upstream URL |
| 98 | + |
| 99 | +```bash |
| 100 | +php artisan upstream:sync --upstream=https://github.com/other/repo.git |
| 101 | +``` |
| 102 | + |
| 103 | +### Skip Hooks |
| 104 | + |
| 105 | +```bash |
| 106 | +php artisan upstream:sync --no-pre --no-post |
| 107 | +``` |
| 108 | + |
| 109 | +### Custom Remote Name |
| 110 | + |
| 111 | +```bash |
| 112 | +php artisan upstream:sync --remote-name=upstream |
| 113 | +``` |
| 114 | + |
| 115 | +## Supported Platforms |
| 116 | + |
| 117 | +This package works with any Git-based repository hosting service: |
| 118 | + |
| 119 | +- **GitHub** - `https://github.com/user/repo.git` |
| 120 | +- **GitLab** - `https://gitlab.com/user/repo.git` |
| 121 | +- **Bitbucket** - `https://bitbucket.org/user/repo.git` |
| 122 | +- **Azure DevOps** - `https://dev.azure.com/org/project/_git/repo` |
| 123 | +- **Self-hosted Git** - Any Git server with HTTP/SSH access |
| 124 | +- **GitLab Self-hosted** - `https://your-gitlab.com/user/repo.git` |
| 125 | +- **Gitea/Gogs** - `https://your-gitea.com/user/repo.git` |
| 126 | + |
| 127 | +## Testing |
| 128 | + |
| 129 | +The package includes comprehensive testing functionality: |
| 130 | + |
| 131 | +- ✅ **Git Binary** - Verifies git is installed and accessible |
| 132 | +- ✅ **Working Directory** - Checks if the working directory exists and is writable |
| 133 | +- ✅ **Configuration** - Validates all required config values and strategy |
| 134 | +- ✅ **Remote Connectivity** - Tests if the upstream URL is reachable |
| 135 | +- ✅ **Branch Validation** - Verifies the upstream branch exists |
| 136 | +- ✅ **Local Repository** - Checks if current directory is a git repo |
| 137 | + |
| 138 | +## Hooks |
| 139 | + |
| 140 | +Configure pre and post-update hooks in your `config/upstream.php`: |
| 141 | + |
| 142 | +```php |
| 143 | +'pre_update' => [ |
| 144 | + 'php artisan down', |
| 145 | + 'php artisan cache:clear', |
| 146 | +], |
| 147 | + |
| 148 | +'post_update' => [ |
| 149 | + 'composer install --no-interaction --prefer-dist --optimize-autoloader', |
| 150 | + 'npm ci', |
| 151 | + 'npm run build', |
| 152 | + 'php artisan migrate --force', |
| 153 | + 'php artisan up', |
| 154 | +], |
| 155 | +``` |
| 156 | + |
| 157 | +## Authentication |
| 158 | + |
| 159 | +### HTTPS |
| 160 | +Uses your stored credentials or personal access tokens. |
| 161 | + |
| 162 | +### SSH (Recommended) |
| 163 | +Uses your SSH keys for authentication. Set up SSH keys for your Git hosting service. |
| 164 | + |
| 165 | +### Personal Access Tokens |
| 166 | +For CI/CD environments, use personal access tokens in your repository URL: |
| 167 | +``` |
| 168 | +https://username:token@github.com/user/repo.git |
| 169 | +``` |
| 170 | + |
| 171 | +## Command Options |
| 172 | + |
| 173 | +| Option | Description | |
| 174 | +|--------|-------------| |
| 175 | +| `--dry-run` | Show what would happen without executing | |
| 176 | +| `--test` | Test configuration and connectivity before sync | |
| 177 | +| `--no-pre` | Skip pre_update hooks | |
| 178 | +| `--no-post` | Skip post_update hooks | |
| 179 | +| `--strategy=` | Override strategy (merge\|rebase) | |
| 180 | +| `--upstream=` | Override upstream URL | |
| 181 | +| `--branch=` | Override upstream branch | |
| 182 | +| `--local=` | Override local branch | |
| 183 | +| `--remote-name=` | Remote name to use (default: upstream) | |
| 184 | + |
| 185 | +## Requirements |
| 186 | + |
| 187 | +- PHP 8.1+ |
| 188 | +- Laravel 10.0+ |
| 189 | +- Git installed and accessible |
| 190 | +- Valid Git repository |
| 191 | + |
| 192 | +## License |
| 193 | + |
| 194 | +This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
| 195 | + |
| 196 | +## Contributing |
| 197 | + |
| 198 | +Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details. |
| 199 | + |
| 200 | +## Changelog |
| 201 | + |
| 202 | +Please see [CHANGELOG.md](CHANGELOG.md) for more information on what has changed recently. |
| 203 | + |
| 204 | +## Credits |
| 205 | + |
| 206 | +- [LaravelPlus](https://github.com/laravelplus) |
| 207 | +- [All Contributors](../../contributors) |
| 208 | + |
| 209 | +## Support |
| 210 | + |
| 211 | +If you discover any issues, please use the [issue tracker](https://github.com/laravelplus/laravel-updater/issues) on GitHub. |
0 commit comments