Skip to content

Commit

Permalink
chore(dev): improve component info command, upgrade to PHP 8.1 (#6174)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored May 5, 2023
1 parent e5b3db2 commit de72b94
Show file tree
Hide file tree
Showing 112 changed files with 1,114 additions and 1,190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@verbose
with:
php-version: "8.0"
php-version: "8.1"
- name: Extract phpDocumentor
id: extract
uses: shrink/actions-docker-extract@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
- name: Install Dependencies
run: composer global require "squizlabs/php_codesniffer:3.*"
- name: Run PHPCS Code Style Checker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
ini-values: memory_limit=2048M
- name: Install Dependencies
uses: nick-fields/retry@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@verbose
with:
php-version: '8.0'
php-version: '8.1'
extensions: grpc
- name: Run Package Test Suites
run: bash .github/run-package-tests.sh
Expand All @@ -88,7 +88,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@verbose
with:
php-version: "8.0"
php-version: "8.1"
- name: "Install dependencies"
run: composer --no-interaction --no-ansi --no-progress update -d dev
- name: Run Dev Unit Test Suite
Expand Down
6 changes: 3 additions & 3 deletions .kokoro/docs/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM gcr.io/gcp-runtimes/ubuntu_16_0_4
ENV PHP_DIR=/opt/php80
ENV PHP_VERSION=8.0.28
ENV PHP_SRC_DIR=/usr/local/src/php80-build
ENV PHP_VERSION=8.1.18
ENV PHP_SRC_DIR=/usr/local/src/php81-build
ENV PATH=${PATH}:/usr/local/bin:${PHP_DIR}/bin

RUN apt-get update && \
Expand Down Expand Up @@ -35,7 +35,7 @@ RUN apt-get update && \
# Remove old version of PHP
RUN apt purge -y php7.0-common

# Install PHP 8.0
# Install PHP 8.1
RUN ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a && \
mkdir -p ${PHP_DIR} ${PHP_SRC_DIR} ${PHP_DIR}/lib/conf.d && \
cd ${PHP_SRC_DIR} && \
Expand Down
4 changes: 2 additions & 2 deletions dev/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"type": "library",
"description": "Development commands for the google/cloud library",
"require": {
"php": ">=8.0",
"php": ">=8.1",
"vierbergenlars/php-semver": "^3.0",
"symfony/console": " ^3.0",
"symfony/console": " ^5.0",
"symfony/yaml": "^3.3||^6.0",
"symfony/process": "^6.0",
"google/cloud": "dev-parent",
Expand Down
78 changes: 18 additions & 60 deletions dev/src/Command/ComponentInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,23 @@
*/
class ComponentInfoCommand extends Command
{
private $googleapisDir = __DIR__ . '/../../../../../googleapis';
protected function configure()
{
$this->setName('component-info')
->setDescription('list info of a component or the whole library')
->addArgument('name', InputArgument::OPTIONAL, 'Component to check compliance for.')
->addArgument('name', InputArgument::OPTIONAL, 'Component to check compliance for.', '')
->addOption('csv', '', InputOption::VALUE_REQUIRED, 'export findings to csv.')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$components = [];
$components[] = [
'Component',
'Composer package',
'GitHub repo',
'PHP namespace',
'Protobuf package',
];
$verbose = $input->getOption('verbose');
if ($verbose) {
$components[0][] = 'Validation errors';
}
if ($componentName = rtrim($input->getArgument('name'), '/')) {
$components[] = $this->checkComponent(new Component($componentName), $verbose);
$components[] = $this->getComponentDetails(new Component($componentName), true);
} else {
foreach (Component::getComponents() as $component) {
$components[] = $this->checkComponent($component, $verbose);
$components[] = $this->getComponentDetails($component, $input->getOption('verbose'));
}
}

Expand All @@ -74,63 +62,33 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$table = new Table($output);
$table
->setHeaders(array_shift($components))
->setHeaders(array_keys($components[0]))
->setRows($components)
;
if ($componentName) {
$table->setVertical();
}
$table->render();
}

return 0;
}

private function checkComponent(Component $component, bool $verbose): array
private function getComponentDetails(Component $component, bool $verbose): array
{
$protobufPackage = '';
$githubRepo = $component->getRepoName();
$composerPackage = $component->getPackageName();
$phpNamespace = $component->getNamespaces()[0];
$componentName = $component->getName();
$validationErrors = [];
$expectedNamespace = '';
try {
$protobufPackage = $component->getProtoPackage($this->googleapisDir);
} catch (\Exception $e) {
$validationErrors[] = $e->getMessage();
}

if ($verbose && $protobufPackage) {
$namer = new NewComponent();
// Output validation errors
$expectedComposerPackage = $namer->composerPackage;
$expectedGithubRepo = $namer->githubRepo;
$expectedNamespace = $namer->phpNamespace;
if ($expectedGithubRepo !== $githubRepo) {
$validationErrors[] = "Github repo name $githubRepo doesn't match expected $expectedGithubRepo";
}
if ($expectedComposerPackage !== $composerPackage) {
$validationErrors[] = "Composer package name $composerPackage doesn't match expected $expectedComposerPackage";
}

$expectedComponentName = $namer->componentName;
if (strtolower($componentName) !== strtolower($expectedComponentName)) {
$validationErrors[] = "Component $componentName doesn't match expected $expectedComponentName";
}

$expectedNamespace = $namer->phpNamespace;
if (strtolower($expectedNamespace) !== strtolower($phpNamespace)) {
$validationErrors[] = "PHP namespace $phpNamespace doesn't match expected $expectedNamespace";
}
}

$info = [
$componentName,
$composerPackage,
$githubRepo,
$phpNamespace,
$protobufPackage,
'Component Name' => $component->getName(),
'Package Name' => $component->getPackageName(),
'Package Version' => $component->getLocalVersion(),
];

if ($verbose) {
$info[] = implode("\n", $validationErrors);
$info['Release Level'] = $component->getReleaseLevel();
$info['Php Namespace(s)'] = implode("\n", $component->getNamespaces());
$info['Github Repo'] = $component->getRepoName();
$info['Protobuf Package'] = $component->getProtoPackage();
$info['Service Address'] = $component->getServiceAddress();
$info['Description'] = $component->getDescription();
}
return $info;
}
Expand Down
17 changes: 3 additions & 14 deletions dev/src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getPath(): string
return $this->path;
}

public function getProtoPackage(string $googleapisDir): string
public function getProtoPackage(): string
{
$gapicClients = $this->getGapicClients();
$regex = '#\* GENERATED CODE WARNING
Expand All @@ -91,22 +91,11 @@ public function getProtoPackage(string $googleapisDir): string
foreach ($gapicClients as $gapicClient) {
$gapicClientContent = file_get_contents($gapicClient);
if (preg_match($regex, $gapicClientContent, $matches)) {
$proto = realpath($googleapisDir . '/' . $matches[1]);
if (!file_exists($proto)) {
$exception = new \Exception('Could not find protobuf file '. $matches[1]);
continue;
}
if (!preg_match('/^package ([\.\w]+);$/m', file_get_contents($proto), $matches)) {
$exception = new \Exception('Could not find proto package in file ' . $proto);
continue;
}
$packageParts = explode('.', $matches[1]);
$packageVersion = array_pop($packageParts);
return implode('.', $packageParts);
return $matches[1];
}
}

throw $exception ? $exception : new \Exception('No GAPIC Clients found in ' . $this->name);
return '';
}

public function getRepoName(): string
Expand Down
20 changes: 10 additions & 10 deletions dev/tests/fixtures/docfx/V1.AddProductToProductSetRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ items:
name: AddProductToProductSetRequest
friendlyApiName: 'Cloud Vision V1 Client'
id: AddProductToProductSetRequest
summary: |
summary: |-
Request message for the `AddProductToProductSet` method.
Generated from protobuf message <code>google.cloud.vision.v1.AddProductToProductSetRequest</code>
type: class
langs:
Expand Down Expand Up @@ -45,9 +45,9 @@ items:
uid: '\Google\Cloud\Vision\V1\AddProductToProductSetRequest::getName()'
name: getName
id: getName
summary: |
summary: |-
Required. The resource name for the ProductSet to modify.
Format is:
`projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`
parent: \Google\Cloud\Vision\V1\AddProductToProductSetRequest
Expand All @@ -62,9 +62,9 @@ items:
uid: '\Google\Cloud\Vision\V1\AddProductToProductSetRequest::setName()'
name: setName
id: setName
summary: |
summary: |-
Required. The resource name for the ProductSet to modify.
Format is:
`projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`
parent: \Google\Cloud\Vision\V1\AddProductToProductSetRequest
Expand All @@ -84,9 +84,9 @@ items:
uid: '\Google\Cloud\Vision\V1\AddProductToProductSetRequest::getProduct()'
name: getProduct
id: getProduct
summary: |
summary: |-
Required. The resource name for the Product to be added to this ProductSet.
Format is:
`projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`
parent: \Google\Cloud\Vision\V1\AddProductToProductSetRequest
Expand All @@ -101,9 +101,9 @@ items:
uid: '\Google\Cloud\Vision\V1\AddProductToProductSetRequest::setProduct()'
name: setProduct
id: setProduct
summary: |
summary: |-
Required. The resource name for the Product to be added to this ProductSet.
Format is:
`projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`
parent: \Google\Cloud\Vision\V1\AddProductToProductSetRequest
Expand Down
12 changes: 6 additions & 6 deletions dev/tests/fixtures/docfx/V1.AnnotateFileRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ items:
name: AnnotateFileRequest
friendlyApiName: 'Cloud Vision V1 Client'
id: AnnotateFileRequest
summary: |
summary: |-
A request to annotate one single file, e.g. a PDF, TIFF or GIF file.
Generated from protobuf message <code>google.cloud.vision.v1.AnnotateFileRequest</code>
type: class
langs:
Expand Down Expand Up @@ -186,9 +186,9 @@ items:
uid: '\Google\Cloud\Vision\V1\AnnotateFileRequest::getPages()'
name: getPages
id: getPages
summary: |
summary: |-
Pages of the file to perform image annotation.
Pages starts from 1, we assume the first page of the file is page 1.
At most 5 pages are supported per request. Pages can be negative.
Page 1 means the first page.
Expand All @@ -210,9 +210,9 @@ items:
uid: '\Google\Cloud\Vision\V1\AnnotateFileRequest::setPages()'
name: setPages
id: setPages
summary: |
summary: |-
Pages of the file to perform image annotation.
Pages starts from 1, we assume the first page of the file is page 1.
At most 5 pages are supported per request. Pages can be negative.
Page 1 means the first page.
Expand Down
12 changes: 6 additions & 6 deletions dev/tests/fixtures/docfx/V1.AnnotateFileResponse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ items:
name: AnnotateFileResponse
friendlyApiName: 'Cloud Vision V1 Client'
id: AnnotateFileResponse
summary: |
summary: |-
Response to a single file annotation request. A file may contain one or more
images, which individually have their own responses.
Generated from protobuf message <code>google.cloud.vision.v1.AnnotateFileResponse</code>
type: class
langs:
Expand Down Expand Up @@ -109,7 +109,7 @@ items:
uid: '\Google\Cloud\Vision\V1\AnnotateFileResponse::getResponses()'
name: getResponses
id: getResponses
summary: |
summary: |-
Individual responses to images found within the file. This field will be
empty if the `error` field is set.
parent: \Google\Cloud\Vision\V1\AnnotateFileResponse
Expand All @@ -124,7 +124,7 @@ items:
uid: '\Google\Cloud\Vision\V1\AnnotateFileResponse::setResponses()'
name: setResponses
id: setResponses
summary: |
summary: |-
Individual responses to images found within the file. This field will be
empty if the `error` field is set.
parent: \Google\Cloud\Vision\V1\AnnotateFileResponse
Expand Down Expand Up @@ -175,7 +175,7 @@ items:
uid: '\Google\Cloud\Vision\V1\AnnotateFileResponse::getError()'
name: getError
id: getError
summary: |
summary: |-
If set, represents the error message for the failed request. The
`responses` field will not be set in this case.
parent: \Google\Cloud\Vision\V1\AnnotateFileResponse
Expand Down Expand Up @@ -206,7 +206,7 @@ items:
uid: '\Google\Cloud\Vision\V1\AnnotateFileResponse::setError()'
name: setError
id: setError
summary: |
summary: |-
If set, represents the error message for the failed request. The
`responses` field will not be set in this case.
parent: \Google\Cloud\Vision\V1\AnnotateFileResponse
Expand Down
4 changes: 2 additions & 2 deletions dev/tests/fixtures/docfx/V1.AnnotateImageRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ items:
name: AnnotateImageRequest
friendlyApiName: 'Cloud Vision V1 Client'
id: AnnotateImageRequest
summary: |
summary: |-
Request for performing Google Cloud Vision API tasks over a user-provided
image, with user-requested features, and with context information.
Generated from protobuf message <code>google.cloud.vision.v1.AnnotateImageRequest</code>
type: class
langs:
Expand Down
Loading

0 comments on commit de72b94

Please sign in to comment.