-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dev): add release-info command #6363
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3db66d
feat(dev): add release-info command
bshaffer 16f1d18
Update dev/src/Command/ReleaseInfoCommand.php
bshaffer 971bba1
Apply suggestions from code review
bshaffer 845d7cf
fix test
bshaffer 3dedeba
add release-info to README
bshaffer f222482
fix readme style
bshaffer 453df78
move string to constant
bshaffer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
# Google Cloud PHP Development Scripts | ||
|
||
The `dev` component features helpful development tools for the following: | ||
- Generating new libraries (`google-cloud add-component`) | ||
- Listing component information (`google-cloud component-info`) | ||
- Generating DocFX documentation (`google-cloud docfx`) | ||
- Splitting the monorepo into sub repositories for releases (`google-cloud split`) | ||
- Testing commands (`sh/static-analysis`) | ||
|
||
Run `dev/google-cloud` for a list of all available commands. | ||
The `dev` component features helpful development tools. Run `dev/google-cloud` | ||
for a list of all available commands: | ||
|
||
| Command | Description | | ||
| ---------------- | ---------------------------------------------------------------- | | ||
| `add-component` | Generate a new library | | ||
| `component-info` | List component information | | ||
| `docfx` | Generate DocFX YAML | | ||
| `release-info` | List components and versions for a monorepo release | | ||
| `split` | Split `google-cloud-php` into sub repositories and tag a release | | ||
|
||
|
||
Additionally, there are scripts in the `sh` directory which are used in our CI: | ||
|
||
| Command | Description | | ||
| ------------------- | --------------------------- | | ||
| `sh/static-analysis`| Run phpstan static ananlysis| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Copyright 2023 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Dev\Command; | ||
|
||
use Google\Cloud\Dev\Component; | ||
use Google\Cloud\Dev\GitHub; | ||
use Google\Cloud\Dev\ReleaseNotes; | ||
use Google\Cloud\Dev\RunShell; | ||
use GuzzleHttp\Client; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* List release details | ||
* @internal | ||
*/ | ||
class ReleaseInfoCommand extends Command | ||
{ | ||
private Client $httpClient; | ||
|
||
private const REPO_ID = 'googleapis/google-cloud-php'; | ||
|
||
/** | ||
* @param Client $httpClient specify the HTTP client, useful for testing | ||
*/ | ||
public function __construct(Client $httpClient = null) | ||
{ | ||
$this->httpClient = $httpClient ?: new Client(); | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('release-info') | ||
->setDescription('list information for a google-cloud-php release') | ||
->addArgument('tag', InputArgument::REQUIRED, 'The git tag of the release (e.g. v0.200.0)') | ||
->addOption('token', 't', InputOption::VALUE_REQUIRED, 'Github token to use for authentication', '') | ||
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'output format, can be "json" or "shell"', 'shell') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$github = new Github( | ||
new RunShell(), | ||
$this->httpClient, | ||
$input->getOption('token') | ||
); | ||
|
||
$changelog = $github->getChangelog( | ||
self::REPO_ID, | ||
$tag = $input->getArgument('tag') | ||
); | ||
|
||
$releaseNotes = new ReleaseNotes($changelog); | ||
|
||
$releases = []; | ||
foreach (Component::getComponents() as $component) { | ||
if ($version = $releaseNotes->getVersion($component->getId())) { | ||
$releases[] = [ | ||
'component' => $component->getName(), | ||
'id' => $component->getId(), | ||
'version' => $version, | ||
]; | ||
} | ||
} | ||
|
||
switch ($input->getOption('format')) { | ||
case 'shell': | ||
(new Table($output)) | ||
->setHeaders(['component', 'id', 'version']) | ||
->setRows($releases) | ||
->render(); | ||
break; | ||
case 'json': | ||
$releases = ['version' => $tag, 'releases' => $releases]; | ||
$output->writeln(json_encode($releases, JSON_PRETTY_PRINT)); | ||
break; | ||
default: | ||
throw new \InvalidArgumentException('invalid format'); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
use Google\Cloud\Dev\Command\DocFxCommand; | ||
use Google\Cloud\Dev\DocFx\Node\ClassNode; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\Yaml\Yaml; | ||
use SimpleXMLElement; | ||
|
@@ -200,9 +199,7 @@ private function assertFileEqualsWithDiff(string $left, string $right, bool $upd | |
private static function getCommandTester(): CommandTester | ||
{ | ||
if (!isset(self::$commandTester)) { | ||
$application = new Application(); | ||
$application->add(new DocFxCommand()); | ||
self::$commandTester = new CommandTester($application->get('docfx')); | ||
self::$commandTester = new CommandTester(new DocFxCommand()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
return self::$commandTester; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Dev\Tests\Unit\Command; | ||
|
||
use Google\Cloud\Dev\Command\ReleaseInfoCommand; | ||
use Google\Cloud\Dev\Composer; | ||
use GuzzleHttp\Client; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
/** | ||
* @group dev | ||
*/ | ||
class ReleaseInfoCommandTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
private static array $mockResponse = [ | ||
'body' => '<details><summary>google\/cloud-billing-budgets: 1.2.0<\/summary>' . | ||
'### Features\r\n\r\n* Add resource_ancestors field to support filtering by folders & organizations ' . | ||
'([#6320](https:\/\/github.com\/googleapis\/google-cloud-php\/issues\/6320))<\/details>' . | ||
'<details><summary>google\/cloud-build: 0.7.2<\/summary><\/details>' . | ||
'\r\n\r\n---\r\nThis PR was generated with Release Please.', | ||
]; | ||
|
||
public function testReleaseInfo() | ||
{ | ||
$tag = 'v0.1000.0'; | ||
$body = $this->prophesize(StreamInterface::class); | ||
$body->__toString() | ||
->shouldBeCalledOnce() | ||
->willReturn(json_encode(self::$mockResponse)); | ||
$response = $this->prophesize(ResponseInterface::class); | ||
$response->getBody() | ||
->shouldBeCalledOnce() | ||
->willReturn($body->reveal()); | ||
$http = $this->prophesize(Client::class); | ||
$http->get( | ||
'https://api.github.com/repos/googleapis/google-cloud-php/releases/tags/' . $tag, | ||
['auth' => [null, null]] | ||
) | ||
->shouldBeCalledOnce() | ||
->willReturn($response->reveal()); | ||
|
||
$commandTester = new CommandTester(new ReleaseInfoCommand($http->reveal())); | ||
$commandTester->execute(['tag' => $tag, '--format' => 'json']); | ||
|
||
$display = $commandTester->getDisplay(); | ||
$json = json_decode($display, true); | ||
|
||
$this->assertArrayHasKey('version', $json); | ||
$this->assertEquals($tag, $json['version']); | ||
$this->assertArrayHasKey('releases', $json); | ||
$this->assertCount(2, $json['releases']); | ||
$this->assertEquals([ | ||
'component' => 'BillingBudgets', | ||
'id' => 'cloud-billing-budgets', | ||
'version' => '1.2.0' | ||
], $json['releases'][0]); | ||
$this->assertEquals([ | ||
'component' => 'Build', | ||
'id' => 'cloud-build', | ||
'version' => '0.7.2' | ||
], $json['releases'][1]); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just cleaning up / simplifying these tests, as we can just create the
CommandTester
directly when we don't need to test things like Question Helpers (e.g.$this->getHelper('question')
)TLDR: it's cleanup that is unrelated to the
release-info
command