From 8057449276ffcf9fa4971fcc990583349fecd5b3 Mon Sep 17 00:00:00 2001 From: Ariyutta Date: Fri, 4 Sep 2026 00:34:47 +0700 Subject: [PATCH] Penambahan Tagging Auto Command --- app/Console/Commands/ReleaseCommand.php | 92 +++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 app/Console/Commands/ReleaseCommand.php diff --git a/app/Console/Commands/ReleaseCommand.php b/app/Console/Commands/ReleaseCommand.php new file mode 100644 index 00000000..9aed4c1a --- /dev/null +++ b/app/Console/Commands/ReleaseCommand.php @@ -0,0 +1,92 @@ + trim(Process::path(base_path())->run(array_merge(['git'], $args))->output()); + + $branch = $git(['rev-parse', '--abbrev-ref', 'HEAD']); + if ($branch !== 'main') { + $this->error("Harus dijalankan dari branch 'main' (sekarang di '{$branch}')."); + $this->line('Jalankan: git checkout main && git pull origin main'); + + return self::FAILURE; + } + + if ($git(['status', '--porcelain']) !== '') { + $this->error('Ada perubahan yang belum di-commit. Bereskan dulu sebelum tagging.'); + + return self::FAILURE; + } + + $this->info('Mengambil update terbaru dari origin/main...'); + Process::path(base_path())->run(['git', 'fetch', 'origin', 'main', '--tags']); + + if ($git(['rev-parse', 'HEAD']) !== $git(['rev-parse', 'origin/main'])) { + $this->error('Branch main lokal belum sinkron dengan origin/main.'); + $this->line('Jalankan: git pull origin main'); + + return self::FAILURE; + } + + $latest = collect(explode("\n", $git(['tag', '--list', 'v*', '--sort=-v:refname']))) + ->map(fn ($t) => trim($t))->filter()->first(); + + if (! $latest) { + $new = 'v0.1.0'; + } else { + [$major, $minor, $patch] = array_pad(explode('.', ltrim($latest, 'v')), 3, '0'); + $new = sprintf('v%d.%d.%d', (int) $major, (int) $minor, ((int) $patch) + 1); + } + + $this->line('Tag terakhir : '.($latest ?: 'tidak ada')); + $this->line("Tag baru : {$new}"); + + if (! $this->option('yes') && ! $this->confirm("Buat dan push tag '{$new}'?", false)) { + $this->line('Dibatalkan.'); + + return self::SUCCESS; + } + + $message = $this->argument('message') ?: "Rilis {$new}"; + + $tag = Process::path(base_path())->run(['git', 'tag', '-a', $new, '-m', $message]); + if (! $tag->successful()) { + $this->error('Gagal membuat tag: '.trim($tag->errorOutput())); + + return self::FAILURE; + } + + $push = Process::path(base_path())->run(['git', 'push', 'origin', $new]); + if (! $push->successful()) { + $this->error('Gagal push tag: '.trim($push->errorOutput())); + + return self::FAILURE; + } + + $this->info("Selesai. Tag {$new} sudah dibuat dan dikirim ke origin."); + + $repo = preg_replace('/\.git$/', '', $git(['remote', 'get-url', 'origin'])); + if ($latest && $repo) { + $this->newLine(); + $this->line('Lihat file yang berubah di rilis ini:'); + $this->line("{$repo}/compare/{$latest}...{$new}"); + } + + return self::SUCCESS; + } +} -- 2.52.0