Skip to content

Commit

Permalink
bump to version 4.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Oct 9, 2020
1 parent 44aa2b1 commit 9a14a46
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
27 changes: 27 additions & 0 deletions database/migrations/2020_10_09_130043_bump_version040007.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use App\Models\Configs;
use Illuminate\Database\Migrations\Migration;

class BumpVersion040007 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Configs::where('key', 'version')->update(['value' => '040007']);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Configs::where('key', 'version')->update(['value' => '040006']);
}
}
45 changes: 19 additions & 26 deletions gen_release
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
$template = "<?php
use App\Configs;
use App\Models\Configs;
use Illuminate\Database\Migrations\Migration;
class BumpVersion%s extends Migration
Expand Down Expand Up @@ -41,13 +41,11 @@ class BumpVersion%s extends Migration
function get_version()
{
$str_CurrentVersion = @file_get_contents('version.md');
if (!$str_CurrentVersion)
{
if (!$str_CurrentVersion) {
throw new Exception("unable to find current version number in version.md\n");
}
$arr_CurrentVersion = array_map('intval', explode('.', $str_CurrentVersion));
if (count($arr_CurrentVersion) != 3)
{
if (count($arr_CurrentVersion) != 3) {
throw new Exception("invalid version number");
}

Expand All @@ -65,23 +63,21 @@ function get_version()
function new_version(array $curr_version, string $kind)
{
$new_version = $curr_version;
switch ($kind){
switch ($kind) {
case 'major':
if ($curr_version[1] == 99)
{
if ($curr_version[1] == 99) {
throw new Exception("Maybe it is time for a big change?");
}
$new_version[1] += 1;
$new_version[2] = 0;
break;
break;
case 'minor':
default:
if ($curr_version[2] == 99)
{
if ($curr_version[2] == 99) {
throw new Exception("Maybe it is time for a major release?");
}
$new_version[2] += 1;
break;
break;
}

return $new_version;
Expand All @@ -94,22 +90,22 @@ function new_version(array $curr_version, string $kind)
*/
function str_version(array $version)
{
return sprintf("%02d%02d%02d",$version[0], $version[1], $version[2]);
return sprintf("%02d%02d%02d", $version[0], $version[1], $version[2]);
}

/**
* Check if migration with same name already exists
*/
function does_migration_exists(string $version)
{
$name_candidate = 'bump_version'.$version;
$name_candidate = 'bump_version' . $version;
$migrations = array_slice(scandir('database/migrations'), 2);
foreach ($migrations as $migration) {
// given 2020_04_22_155712_bump_version040002.php we retrieve bump_version040002
$name = explode("_",$migration,5);
$name = substr($name[4],0,-4);
if($name == $name_candidate) {
throw new Exception('Migration '.$name_candidate.' already exsists!');
$name = explode("_", $migration, 5);
$name = substr($name[4], 0, -4);
if ($name == $name_candidate) {
throw new Exception('Migration ' . $name_candidate . ' already exsists!');
}
}
}
Expand All @@ -119,25 +115,22 @@ $kind = $argv[1] ?? 'minor';
try {
$cv = get_version();
$nv = new_version($cv, $kind);

$str_cv = str_version($cv);
$str_nv = str_version($nv);

does_migration_exists($str_nv);

$fileName = sprintf('database/migrations/%s_bump_version%s.php',date('Y_m_d_His'), $str_nv);
$fileName = sprintf('database/migrations/%s_bump_version%s.php', date('Y_m_d_His'), $str_nv);
$fileContent = sprintf($template, $str_nv, $str_nv, $str_cv);

file_put_contents($fileName, $fileContent);
echo "Migration generated!\n";

file_put_contents('version.md', implode('.',$nv));
file_put_contents('version.md', implode('.', $nv));
echo "version.md updated!\n";

exit;
} catch (Exception $e) {
exit("\e[0;31m" . $e->getMessage() . "\e[0m\n");
}
catch (Exception $e)
{
exit("\e[0;31m".$e->getMessage()."\e[0m\n");
}

6 changes: 4 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ formatting:
echo ""; \
fi

release_minor:
gen_minor:
php gen_release
git add database
git add version.md
git commit -m "bump to version $(shell cat version.md)"

release_minor:
git commit -S -m "bump to version $(shell cat version.md)"

release_major:
php gen_release major
Expand Down
2 changes: 1 addition & 1 deletion version.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.6
4.0.7

0 comments on commit 9a14a46

Please sign in to comment.