Skip to content
Open
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ clean: clear-cache
rm -rf build/artifacts/*

clear-cache:
php build/aws-clear-cache.php
php build/WorkflowCommandRunner.php clear-cache

test:
AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar AWS_SESSION_TOKEN= \
Expand All @@ -33,10 +33,10 @@ test:

test-phar: package
[ -f build/artifacts/behat.phar ] || (cd build/artifacts && \
wget https://github.com/Behat/Behat/releases/download/v3.0.15/behat.phar)
wget https://github.com/Behat/Behat/releases/download/v3.13.0/behat.phar)
[ -f build/artifacts/phpunit.phar ] || (cd build/artifacts && \
wget https://phar.phpunit.de/phpunit.phar)
php -dopcache.enable_cli=1 build/phar-test-runner.php --format=progress
php -dopcache.enable_cli=1 build/WorkflowCommandRunner.php phar-test-runner --format=progress

coverage:
@AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar AWS_CSM_ENABLED=false \
Expand Down Expand Up @@ -78,7 +78,7 @@ smoke-noassumerole:

# Packages the phar and zip
package:
php build/packager.php $(SERVICE)
php build/WorkflowCommandRunner.php package$(if $(SERVICE), --service=$(SERVICE),)

api-get-phpdocumentor:
mkdir -p build/artifacts
Expand All @@ -89,19 +89,19 @@ api: api-get-phpdocumentor
[ -d build/artifacts/staging ] || make package
# Delete a previously built API build to avoid the prompt.
rm -rf build/artifacts/docs
php build/remove-method-annotations.php
php build/WorkflowCommandRunner.php remove-method-annotations
php build/artifacts/phpDocumentor.phar run --config build/docs/phpdoc.dist.xml
php build/normalize-docs-files.php
php build/WorkflowCommandRunner.php normalize-docs-files
make api-models
make redirect-map

api-models:
# Build custom docs
php build/docs.php $(if $(ISSUE_LOGGING_ENABLED),--issue-logging-enabled,)
php build/WorkflowCommandRunner.php docs $(if $(ISSUE_LOGGING_ENABLED),--issue-logging-enabled,)

redirect-map:
# Build redirect map
php build/build-redirect-map.php
php build/WorkflowCommandRunner.php build-redirect-map

api-show:
open build/artifacts/docs/index.html
Expand All @@ -110,23 +110,23 @@ api-package:
zip -r build/artifacts/aws-docs-api.zip build/artifacts/docs/build

api-manifest:
php build/build-manifest.php
php build/WorkflowCommandRunner.php build-manifest
make clear-cache

# Compiles JSON data files and prints the names of PHP data files created or
# updated.
compile-json:
php -dopcache.enable_cli=1 build/compile-json.php
php -dopcache.enable_cli=1 build/WorkflowCommandRunner.php compile-json
git diff --name-only | grep ^src/data/.*\.json\.php$ || true

annotate-clients: clean
php build/annotate-clients.php --all
php build/WorkflowCommandRunner.php annotate-clients --all

annotate-client-locator: clean
php build/annotate-client-locator.php
php build/WorkflowCommandRunner.php annotate-client-locator

build-manifest:
php build/build-manifest.php >/dev/null
php build/WorkflowCommandRunner.php build-manifest >/dev/null

build: | build-manifest compile-json annotate-clients annotate-client-locator

Expand Down Expand Up @@ -159,7 +159,7 @@ tag: check-tag
release: check-tag package
git push origin master
git push origin $(TAG)
php build/gh-release.php $(TAG)
php build/WorkflowCommandRunner.php gh-release --tag=$(TAG)

# Tags the repo and publishes a release.
full_release: tag release
Expand Down
80 changes: 80 additions & 0 deletions build/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace AwsBuild\Command;

abstract class AbstractCommand implements CommandInterface
{
protected bool $verbose = false;
private ?string $projectRoot;

public function __construct(?string $projectRoot = null)
{
$this->projectRoot = $projectRoot ?? dirname(__DIR__, 2);
}

public function execute(array $args): int
{
if (in_array('--help', $args, true) || in_array('-h', $args, true)) {
$name = $this->getName();
$this->output($name);
$this->output(str_repeat('-', strlen($name)));
$this->output($this->getDescription());
$this->output('');
$this->output('Usage:');
$this->output(' ' . $this->getUsage());
return 0;
}

if (in_array('--verbose', $args, true) || in_array('-v', $args, true)) {
$this->verbose = true;
}

return $this->doExecute($args);
}

abstract protected function doExecute(array $args): int;

protected function output(string $msg): void
{
fwrite(STDOUT, $msg . "\n");
}

protected function error(string $msg): void
{
fwrite(STDERR, "[ERROR] $msg\n");
}

protected function verbose(string $msg): void
{
if ($this->verbose) {
fwrite(STDOUT, $msg . "\n");
}
}

protected function parseOptions(array $args): array
{
$options = [];
foreach ($args as $arg) {
if (str_starts_with($arg, '--')) {
$arg = substr($arg, 2);
if (str_contains($arg, '=')) {
[$key, $value] = explode('=', $arg, 2);
$options[$key] = $value;
} else {
$options[$arg] = true;
}
}
}
return $options;
}

protected function getProjectRoot(): string
{
return $this->projectRoot;
}

protected static function getBuildDir(): string
{
return dirname(__DIR__);
}
}
54 changes: 54 additions & 0 deletions build/Command/AnnotateClientLocatorCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace AwsBuild\Command;

final class AnnotateClientLocatorCommand extends AbstractCommand
{
public function getName(): string
{
return 'annotate-client-locator';
}

public function getDescription(): string
{
return 'Updates @method annotations on the Aws\Sdk class.';
}

public function getUsage(): string
{
return 'php build/WorkflowCommandRunner.php annotate-client-locator';
}

protected function doExecute(array $args): int
{
$namespaces = array_map(function (array $manifest) {
return $manifest['namespace'];
}, array_values(\Aws\manifest()));

sort($namespaces);
$annotations = [];
foreach ($namespaces as $namespace) {
$mrClient = "\\Aws\\{$namespace}\\{$namespace}MultiRegionClient";
$mrClient = class_exists($mrClient) ? $mrClient : "\\Aws\\MultiRegionClient";

$annotations[] = " * @method \\Aws\\{$namespace}\\{$namespace}Client"
. " create{$namespace}(array \$args = [])";
$annotations[] = " * @method $mrClient"
. " createMultiRegion{$namespace}(array \$args = [])";
}

$previousAnnotationPattern = '/^\* @method'
. ' \\\\Aws\\\\(?:[a-zA-Z0-9\\\\]+)Client'
. ' create(?:[a-zA-Z0-9]+)\\(array \$args = \\[\\]\\)/';

$updater = new \ClassAnnotationUpdater(
new \ReflectionClass(\Aws\Sdk::class),
$annotations,
'',
$previousAnnotationPattern
);
$updater->update();

return 0;
}
}
83 changes: 83 additions & 0 deletions build/Command/AnnotateClientsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace AwsBuild\Command;

final class AnnotateClientsCommand extends AbstractCommand
{
public function getName(): string
{
return 'annotate-clients';
}

public function getDescription(): string
{
return 'Adds @method annotations to service client classes.';
}

public function getUsage(): string
{
return 'php build/WorkflowCommandRunner.php annotate-clients [--all] [--class=<FQCN>] [--tag=<git-tag>]';
}

protected function doExecute(array $args): int
{
$options = $this->parseOptions($args) + ['class' => [], 'tag' => []];

// make sure all options are arrays
array_walk($options, function (&$value) {
if (!is_array($value)) {
$value = [$value];
}
});

if (isset($options['all'])) {
$options['class'] = \Aws\flatmap(\Aws\manifest(), function (array $manifest) {
return $this->getClientClasses($manifest['namespace']);
});
}

foreach ($options['tag'] as $tag) {
if ('latest' === $tag) {
$tag = trim(`git tag | tail -n 1`);
}

exec("git diff-index --name-only --cached $tag", $files);
$alteredApiFiles = array_filter($files, function ($file) {
return preg_match('/api-2.json$/', $file);
});

$clientsWithChangedApis = \Aws\flatmap($alteredApiFiles, function ($file) {
$file = str_replace('src/data/', '', $file);
$endpoint = substr($file, 0, strpos($file, '/'));
return $this->getClientClasses(\Aws\manifest($endpoint)['namespace']);
});
$options['class'] = \Aws\flatmap(
[$options['class'], $clientsWithChangedApis],
function ($class) { return $class; }
);
}

foreach ($options['class'] as $classToUpdate) {
$annotator = new \ClientAnnotator($classToUpdate);

if (!$annotator->updateApiMethodAnnotations()) {
trigger_error(
"Unable to update annotations on $classToUpdate",
E_USER_WARNING
);
}
}

return 0;
}

private function getClientClasses(string $namespace): array
{
$clients = ["Aws\\{$namespace}\\{$namespace}Client"];
if (class_exists("Aws\\{$namespace}\\{$namespace}MultiRegionClient")) {
$clients[] = "Aws\\{$namespace}\\{$namespace}MultiRegionClient";
}

return $clients;
}
}
40 changes: 40 additions & 0 deletions build/Command/BuildChangelogCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace AwsBuild\Command;

use Aws\Build\Changelog\ChangelogBuilder;

final class BuildChangelogCommand extends AbstractCommand
{
public function getName(): string
{
return 'build-changelog';
}

public function getDescription(): string
{
return 'Builds CHANGELOG.md from next-release entries.';
}

public function getUsage(): string
{
return 'php build/WorkflowCommandRunner.php build-changelog [-v]';
}

protected function doExecute(array $args): int
{
$params = [];
$params['verbose'] = $this->verbose;
$params['base_dir'] = $this->getProjectRoot() . '/';

$changelogBuilder = new ChangelogBuilder($params);

$changelogBuilder->buildChangelog();

// Omit fixEndpointFile() call - method doesn't exist on ChangelogBuilder
Comment thread
yenfryherrerafeliz marked this conversation as resolved.

$changelogBuilder->cleanNextReleaseFolder();

return 0;
}
}
Loading