diff --git a/CODEOWNERS b/CODEOWNERS index 567e4dc..59ddc56 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -8,5 +8,5 @@ # https://help.github.com/en/articles/about-code-owners # -* @brettmc @bobstrecansky @pdelewski +* @brettmc @bobstrecansky # note that open-telemetry/php-approvers does not exist in this organization diff --git a/Makefile b/Makefile index 0778381..3c24724 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ ifneq ("$(wildcard .env)","") export $(.env) endif -PHP_VERSION ?= 7.4 +PHP_VERSION ?= 8.1 DC_RUN_PHP = docker compose run --rm php PSALM_THREADS ?= 1 diff --git a/README.md b/README.md index a927e15..eb6c658 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Options: - `--branch=` - github branch to tag from - `--dry-run` - do not make any changes - `--repo=` - choose a single upstream repo to run against (default: all) +- `--filter=` - filter repositories by prefix The script will then: * fetch `.gitsplit.yaml` from source repositories diff --git a/docker-compose.yaml b/docker-compose.yaml index 07cf4ce..8a71e4f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ version: '3.7' services: php: - image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-7.4} + image: ghcr.io/open-telemetry/opentelemetry-php/opentelemetry-php-base:${PHP_VERSION:-8.1} volumes: - ./:/usr/src/myapp user: "${PHP_USER}:root" diff --git a/src/Console/Command/Release/ReleaseCommand.php b/src/Console/Command/Release/ReleaseCommand.php index f4d61f6..320d7df 100644 --- a/src/Console/Command/Release/ReleaseCommand.php +++ b/src/Console/Command/Release/ReleaseCommand.php @@ -40,6 +40,7 @@ protected function configure(): void ->addOption('token', ['t'], InputOption::VALUE_OPTIONAL, 'github token') ->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'branch to tag off (default: main)') ->addOption('repo', ['r'], InputOption::VALUE_OPTIONAL, 'repo to handle (core, contrib)') + ->addOption('filter', null, InputOption::VALUE_OPTIONAL, 'filter by repository prefix') ->addOption('force', ['f'], InputOption::VALUE_NONE, 'force new releases even if no changes') ; } @@ -63,6 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->dry_run = $input->getOption('dry-run'); $this->force = $input->getOption('force'); $source = $input->getOption('repo'); + $filter = $input->getOption('filter'); if ($source && !array_key_exists($source, self::AVAILABLE_REPOS)) { $options = implode(',', array_keys(self::AVAILABLE_REPOS)); $this->output->writeln("Invalid source: {$source}. Options: {$options}"); @@ -75,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $repositories = []; try { - $found = $this->find_repositories(); + $found = $this->find_repositories($filter); } catch (\Exception $e) { $this->output->writeln("{$e->getCode()} {$e->getMessage()}"); @@ -104,18 +106,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int * @throws \Exception * @return array */ - private function find_repositories(): array + private function find_repositories(?string $filter): array { $repositories = []; foreach ($this->sources as $key => $repo) { $this->output->isVerbose() && $this->output->writeln("Fetching .gitsplit.yaml for {$key} ({$repo})"); - $repositories = array_merge($repositories, $this->get_gitsplit_repositories($repo)); + $repositories = array_merge($repositories, $this->get_gitsplit_repositories($repo, $filter)); } return $repositories; } - private function get_gitsplit_repositories(string $repo): array + private function get_gitsplit_repositories(string $repo, ?string $filter): array { $url = "https://raw.githubusercontent.com/{$repo}/main/.gitsplit.yml"; $response = $this->fetch($url); @@ -127,14 +129,24 @@ private function get_gitsplit_repositories(string $repo): array $repositories = []; $this->output->isVeryVerbose() && $this->output->writeln('[RESPONSE]' . json_encode($yaml['splits'])); foreach ($yaml['splits'] as $entry) { + $prefix = $entry['prefix']; + if ($filter && !str_contains($prefix, $filter)) { + $this->output->isVerbose() && $this->output->writeln(sprintf('[SKIP] %s does not match filter: %s', $prefix, $filter)); + + continue; + } $repository = new Repository(); $repository->upstream = new Project($repo); - $repository->upstream->path = $entry['prefix']; + $repository->upstream->path = $prefix; $target = $entry['target']; $repository->downstream = new Project(str_replace(['https://${GH_TOKEN}@github.com/', '.git'], ['',''], $target)); $repositories[] = $repository; } + if ($this->output->isVeryVerbose()) { + $this->output->writeln('[FOUND]' . json_encode($repositories)); + } + return $repositories; }