Skip to content

Commit 0637f94

Browse files
committed
chore(ci): add repo:complaince check to release PRs
1 parent fa6785d commit 0637f94

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

.github/workflows/release-checks.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,21 @@ jobs:
133133
if: github.event.pull_request.user.login == 'release-please[bot]'
134134
with:
135135
next-release-label-check: true
136+
137+
# Ensure all repos are in compliance
138+
repo-compliance-check:
139+
name: Repo Compliance Check
140+
runs-on: ubuntu-latest
141+
# if: github.event.pull_request.user.login == 'release-please[bot]'
142+
steps:
143+
- uses: actions/checkout@v6
144+
with:
145+
fetch-depth: 0
146+
- name: "Install PHP"
147+
uses: shivammathur/setup-php@v2
148+
with:
149+
php-version: "8.1"
150+
- name: "Install dependencies"
151+
run: composer install -d dev
152+
- name: "Verify the subrepos exist for new components"
153+
run: ./dev/google-cloud repo:compliance --format=ci

dev/src/Command/RepoComplianceCommand.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Symfony\Component\Console\Output\OutputInterface;
3030
use Symfony\Component\Console\Question\ConfirmationQuestion;
3131
use GuzzleHttp\Client;
32+
use InvalidArgumentException;
3233

3334
/**
3435
* List repo details
@@ -49,6 +50,7 @@ protected function configure()
4950
->addOption('page', 'p', InputOption::VALUE_REQUIRED, 'page to start from', '1')
5051
->addOption('results-per-page', 'r', InputOption::VALUE_REQUIRED, 'results to display per page (0 for all)', '10')
5152
->addOption('new-packagist-token', '', InputOption::VALUE_REQUIRED, 'update the packagist token')
53+
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'can be "ci" or "table"', 'table')
5254
;
5355
}
5456

@@ -72,6 +74,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
7274
}
7375
$page = (int) $input->getOption('page');
7476
$resultsPerPage = (int) $input->getOption('results-per-page');
77+
$format = $input->getOption('format');
78+
if (!in_array($format, ['ci', 'table'])) {
79+
throw new InvalidArgumentException('Invalid format "' . $format . '", must be "table" or "ci"');
80+
}
7581
$components = $componentName ? [new Component($componentName)] : Component::getComponents();
7682

7783
if (!$input->getOption('token')) {
@@ -81,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8187
if ($i < (($page-1) * $resultsPerPage)) {
8288
continue;
8389
}
84-
if (0 !== $resultsPerPage && $i >= ($page * $resultsPerPage)) {
90+
if ($format == 'table' && 0 !== $resultsPerPage && $i >= ($page * $resultsPerPage)) {
8591
$table->render();
8692
if (!$this->getHelper('question')->ask($input, $output, $nextPageQuestion)) {
8793
return 0;
@@ -135,17 +141,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
135141
}
136142
}
137143

144+
if ($format == 'ci' ) {
145+
$output->writeln($component->getName() . ': ' . $details['compliant']);
146+
if (!$isCompliant) {
147+
return 1;
148+
}
149+
}
150+
138151
if (!$isCompliant) {
139152
$details['compliant'] .= PHP_EOL . implode("\n", array_map(
140153
fn ($k, $v) => $k . ': ' . (is_null($v) ? '???' : var_export($v, true)),
141154
array_keys($compliance),
142155
array_values($compliance)
143156
));
144157
}
145-
146158
$table->addRow($details);
147159
}
148-
$table->render();
160+
if ($format == 'table') {
161+
$table->render();
162+
}
149163

150164
return 0;
151165
}

0 commit comments

Comments
 (0)