Skip to content

Commit 3197ea0

Browse files
committed
tag helper
1 parent 4e23332 commit 3197ea0

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Diff for: app/Commands/Tag.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Facades\Process;
7+
use LaravelZero\Framework\Commands\Command;
8+
9+
use function Laravel\Prompts\info;
10+
use function Laravel\Prompts\text;
11+
12+
class Tag extends Command
13+
{
14+
protected $signature = 'tag';
15+
16+
protected $description = 'Tag the current version';
17+
18+
public function handle(): void
19+
{
20+
$dirty = exec('git status --porcelain');
21+
22+
if ($dirty) {
23+
info('Working directory is not clean. Please commit your changes before tagging.');
24+
25+
return;
26+
}
27+
28+
$composer = File::json(base_path('composer.json'));
29+
30+
$version = $composer['version'];
31+
32+
$newVersion = text(label: 'Next version: ', default: $version);
33+
34+
$tag = "v{$newVersion}";
35+
36+
info("Tagging version {$tag}");
37+
38+
$composer['version'] = $newVersion;
39+
40+
File::put(base_path('composer.json'), json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
41+
42+
exec('git add composer.json');
43+
exec('git commit -m "Bump version to ' . $newVersion . '"');
44+
exec('git tag ' . $tag);
45+
}
46+
}

Diff for: config/commands.php

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use App\Commands\CompileBinaryCommand;
44
use App\Commands\ContextTypeScriptGeneratorCommand;
5+
use App\Commands\Tag;
56

67
return [
78

@@ -68,6 +69,7 @@
6869
LaravelZero\Framework\Commands\StubPublishCommand::class,
6970
CompileBinaryCommand::class,
7071
ContextTypeScriptGeneratorCommand::class,
72+
Tag::class,
7173
],
7274

7375
/*

0 commit comments

Comments
 (0)