-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: improve build workflows #3262
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
Open
yenfryherrerafeliz
wants to merge
11
commits into
aws:master
Choose a base branch
from
yenfryherrerafeliz:build_workflow_improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4120d8c
chore: improve build workflows
yenfryherrerafeliz 96b01e9
Merge branch 'master' into build_workflow_improvements
yenfryherrerafeliz 24acbe5
chore: inline script execution
yenfryherrerafeliz c56e1d3
feat: service removal command
yenfryherrerafeliz b8591ee
chore: address feedback
yenfryherrerafeliz 1a9366f
chore: make command classes final
yenfryherrerafeliz 78fc99f
chore: address feedback
yenfryherrerafeliz f4b845a
chore: update to inline script
yenfryherrerafeliz ea050ac
chore: enhance runner to be class based
yenfryherrerafeliz 2fe2117
chore: merge master branch
yenfryherrerafeliz 28b9625
chore: address PR feedback
yenfryherrerafeliz 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 hidden or 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 hidden or 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,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__); | ||
| } | ||
| } |
This file contains hidden or 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,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; | ||
| } | ||
| } |
This file contains hidden or 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,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; | ||
| } | ||
| } |
This file contains hidden or 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,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 | ||
|
|
||
| $changelogBuilder->cleanNextReleaseFolder(); | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.