Skip to content

Commit 62cbbf8

Browse files
authored
Add release tool (#216)
- Add release tool - Update .gitattributes
1 parent 6b1a0c0 commit 62cbbf8

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/.gitignore export-ignore
33
/.travis.yml export-ignore
44
/phpunit.xml export-ignore
5-
/src/Qcloud/Cos/Tests export-ignore
5+
/src/Qcloud/Cos/Tests export-ignore
6+
/bin export-ignore

bin/release

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* User: sy-records
5+
6+
* Usage: php bin/release or php bin/release version
7+
*/
8+
9+
require_once 'vendor/autoload.php';
10+
11+
use Qcloud\Cos\Client;
12+
use Qcloud\Cos\Service;
13+
use GuzzleHttp\Command\Guzzle\Description;
14+
15+
$class = new ReflectionClass(Client::class);
16+
$oldDocComment = $class->getDocComment();
17+
$clientFile = $class->getFileName();
18+
$clientFileContent = file_get_contents($class->getFileName());
19+
20+
$des = new Description(Service::getService());
21+
$operations = array_keys($des->getOperations());
22+
$docComment = "/**\n";
23+
foreach ($operations as $key => $operation) {
24+
$type = $arg = '';
25+
$model = $des->getOperation($operation)->getResponseModel();
26+
if ($des->hasModel($model)) {
27+
$type = $des->getModel($model)->getType();
28+
if (!empty($des->getOperation($operation)->getParams())) {
29+
$arg = ' (array $arg)';
30+
}
31+
}
32+
$docComment .= " * @method {$type} {$operation}{$arg}\n";
33+
}
34+
$docComment .= ' */';
35+
36+
$data = str_replace($oldDocComment, $docComment, $clientFileContent);
37+
$status = file_put_contents($clientFile, $data);
38+
39+
if ($status) {
40+
echo 'Regenerate docComment successfully.', PHP_EOL;
41+
}
42+
43+
if (isset($argv[1])) {
44+
$version = $argv[1];
45+
$versionContent = str_replace(Client::VERSION, $version, $data);
46+
$status = file_put_contents($clientFile, $versionContent);
47+
48+
if ($status) {
49+
echo 'Update version successfully.', PHP_EOL;
50+
}
51+
}

0 commit comments

Comments
 (0)