Skip to content

Commit 05b0441

Browse files
author
nejc
committed
first commit
0 parents  commit 05b0441

File tree

6 files changed

+654
-0
lines changed

6 files changed

+654
-0
lines changed

README.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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.

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "laravelplus/laravel-updater",
3+
"description": "A Laravel package for syncing with upstream repositories (GitHub, GitLab, Bitbucket, etc.)",
4+
"keywords": ["laravel", "upstream", "sync", "git", "github", "gitlab", "bitbucket"],
5+
"license": "MIT",
6+
"type": "library",
7+
"require": {
8+
"php": "^8.1",
9+
"illuminate/console": "^10.0|^11.0",
10+
"illuminate/support": "^10.0|^11.0",
11+
"symfony/process": "^6.0|^7.0"
12+
},
13+
"require-dev": {
14+
"phpunit/phpunit": "^10.0",
15+
"orchestra/testbench": "^8.0|^9.0"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"LaravelPlus\\LaravelUpdater\\": "src/"
20+
}
21+
},
22+
"autoload-dev": {
23+
"psr-4": {
24+
"LaravelPlus\\LaravelUpdater\\Tests\\": "tests/"
25+
}
26+
},
27+
"extra": {
28+
"laravel": {
29+
"providers": [
30+
"LaravelPlus\\LaravelUpdater\\LaravelUpdaterServiceProvider"
31+
]
32+
}
33+
},
34+
"minimum-stability": "stable",
35+
"prefer-stable": true
36+
}

src/Config/upstream.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Upstream Repository Settings
10+
|--------------------------------------------------------------------------
11+
*/
12+
'upstream_url' => env('UPSTREAM_URL', 'https://github.com/laravel/vue-starter-kit.git'),
13+
'upstream_branch' => env('UPSTREAM_BRANCH', 'main'),
14+
'local_branch' => env('UPSTREAM_LOCAL_BRANCH', 'main'),
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Strategy: merge | rebase
19+
|--------------------------------------------------------------------------
20+
*/
21+
'strategy' => env('UPSTREAM_STRATEGY', 'merge'),
22+
23+
/*
24+
|--------------------------------------------------------------------------
25+
| Git Options
26+
|--------------------------------------------------------------------------
27+
*/
28+
'git_binary' => env('GIT_BINARY', 'git'),
29+
'working_dir' => base_path(),
30+
'commit_message' => env('UPSTREAM_COMMIT_MESSAGE', 'chore(upstream): sync from upstream'),
31+
'allow_unrelated_histories' => (bool) env('UPSTREAM_ALLOW_UNRELATED', true),
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Hooks (arrays of shell commands executed in project root)
36+
|--------------------------------------------------------------------------
37+
*/
38+
'pre_update' => [
39+
// 'php artisan down',
40+
// 'php artisan cache:clear',
41+
],
42+
43+
'post_update' => [
44+
// 'composer install --no-interaction --prefer-dist --optimize-autoloader',
45+
// 'npm ci',
46+
// 'npm run build',
47+
// 'php artisan migrate --force',
48+
// 'php artisan up',
49+
],
50+
];

0 commit comments

Comments
 (0)