Adding --dry-run option to composer_vendor_push task and also making it possible to specify exact new version of a package
Publish PHP Package / docker (push) Successful in 7s
Details
Publish PHP Package / docker (push) Successful in 7s
Details
This commit is contained in:
parent
c703ffd95b
commit
c8a1167544
|
@ -23,27 +23,34 @@ task('composer', function(array $args) {
|
||||||
composer_run($args);
|
composer_run($args);
|
||||||
});
|
});
|
||||||
|
|
||||||
task('composer_vendor_push', function($args) {
|
task('composer_vendor_push', function(array $args) {
|
||||||
|
|
||||||
$usage = "Usage: ./gamectl composer_vendor_push <path/to/repo> <commit message> [^[^[^]]]\n";
|
$usage = "Usage: ./gamectl composer_vendor_push <path/to/repo> <commit message> [^[^[^]]]\n";
|
||||||
|
|
||||||
|
$dry_run = arg_opt($args, '--dry-run', false);
|
||||||
|
arg_opt_check_no_trailing($args);
|
||||||
|
|
||||||
if(count($args) < 2)
|
if(count($args) < 2)
|
||||||
throw new Exception($usage);
|
throw new Exception($usage);
|
||||||
|
|
||||||
|
$force_new_tag = '';
|
||||||
$up_mode = 1;
|
$up_mode = 1;
|
||||||
if(count($args) > 2)
|
if(count($args) > 2)
|
||||||
{
|
{
|
||||||
if($args[2] === '^')
|
$tmp_arg = array_pop($args);
|
||||||
|
|
||||||
|
if($tmp_arg === '^')
|
||||||
$up_mode = 1;
|
$up_mode = 1;
|
||||||
else if($args[2] === '^^')
|
else if($tmp_arg === '^^')
|
||||||
$up_mode = 2;
|
$up_mode = 2;
|
||||||
else if($args[2] === '^^^')
|
else if($tmp_arg === '^^^')
|
||||||
$up_mode = 3;
|
$up_mode = 3;
|
||||||
else
|
else
|
||||||
throw new Exception("Invalid up mode: {$args[2]} (supported ^, ^^ and ^^^)");
|
$force_new_tag = $tmp_arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relpath = $args[0];
|
$relpath = array_shift($args);
|
||||||
$commit_msg = $args[1];
|
$commit_msg = array_shift($args);
|
||||||
$repo = realpath("composer" .DIRECTORY_SEPARATOR. "vendor" .DIRECTORY_SEPARATOR. $relpath) ?: realpath($relpath);
|
$repo = realpath("composer" .DIRECTORY_SEPARATOR. "vendor" .DIRECTORY_SEPARATOR. $relpath) ?: realpath($relpath);
|
||||||
|
|
||||||
if(!$repo)
|
if(!$repo)
|
||||||
|
@ -66,13 +73,21 @@ task('composer_vendor_push', function($args) {
|
||||||
if($last_remote_tag === false)
|
if($last_remote_tag === false)
|
||||||
throw new Exception("Could not retrieve last remote tag");
|
throw new Exception("Could not retrieve last remote tag");
|
||||||
echo "The last remote Git tag: $last_remote_tag\n";
|
echo "The last remote Git tag: $last_remote_tag\n";
|
||||||
$last_remote_version = GitVersion::parse($last_remote_tag);
|
|
||||||
|
|
||||||
$last_remote_version->bump($up_mode);
|
if(empty($force_new_tag))
|
||||||
$new_tag = $last_remote_version->encode();
|
{
|
||||||
|
$last_remote_version = GitVersion::parse($last_remote_tag);
|
||||||
|
$last_remote_version->bump($up_mode);
|
||||||
|
$new_tag = $last_remote_version->encode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$new_tag = $force_new_tag;
|
||||||
|
|
||||||
|
echo "Commit message: {$commit_msg}\n";
|
||||||
echo "New version expected to be: {$new_tag}\n";
|
echo "New version expected to be: {$new_tag}\n";
|
||||||
|
|
||||||
are_you_sure();
|
if($dry_run === false)
|
||||||
|
are_you_sure();
|
||||||
|
|
||||||
$is_upm = file_exists("$repo/package.json");
|
$is_upm = file_exists("$repo/package.json");
|
||||||
if($is_upm)
|
if($is_upm)
|
||||||
|
@ -97,13 +112,22 @@ task('composer_vendor_push', function($args) {
|
||||||
$upm_new_version = ltrim($new_tag, 'v');
|
$upm_new_version = ltrim($new_tag, 'v');
|
||||||
echo "New package.json expected to be: {$upm_new_version}\n";
|
echo "New package.json expected to be: {$upm_new_version}\n";
|
||||||
|
|
||||||
are_you_sure();
|
if($dry_run === false)
|
||||||
|
{
|
||||||
|
are_you_sure();
|
||||||
|
|
||||||
$upm_info['version'] = $upm_new_version;
|
$upm_info['version'] = $upm_new_version;
|
||||||
upm_set_package_info($repo, $upm_info);
|
upm_set_package_info($repo, $upm_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($dry_run !== false)
|
||||||
|
{
|
||||||
|
echo "Dry run is done.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
git_do($repo, 'add .');
|
git_do($repo, 'add .');
|
||||||
git_do($repo, "commit -am \"$commit_msg\"", $commit_output);
|
git_do($repo, "commit -am \"$commit_msg\"", $commit_output);
|
||||||
$rev = git_rev_from_commit_message(trim($commit_output[0]));
|
$rev = git_rev_from_commit_message(trim($commit_output[0]));
|
||||||
|
@ -128,9 +152,14 @@ task('composer_vendor_push', function($args) {
|
||||||
$last_tag = _get_last_version_tag($tags);
|
$last_tag = _get_last_version_tag($tags);
|
||||||
echo "Last tag: $last_tag\n";
|
echo "Last tag: $last_tag\n";
|
||||||
|
|
||||||
$last_version = GitVersion::parse($last_tag);
|
if(empty($force_new_tag))
|
||||||
$last_version->bump($up_mode);
|
{
|
||||||
$new_tag = $last_version->encode();
|
$last_version = GitVersion::parse($last_tag);
|
||||||
|
$last_version->bump($up_mode);
|
||||||
|
$new_tag = $last_version->encode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$new_tag = $force_new_tag;
|
||||||
|
|
||||||
echo "New tag: $new_tag\n";
|
echo "New tag: $new_tag\n";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue