Skip to content

Commit 284f348

Browse files
authored
feat(dev): skip option for repo:compliance, skip repo check for Gax (googleapis#9288)
feat(dev): add skip option to compliance check, and skip repo check for Gax
1 parent 85ac41b commit 284f348

2 files changed

Lines changed: 38 additions & 16 deletions

File tree

.github/workflows/release-checks.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,9 @@ jobs:
129129
env:
130130
GH_TOKEN: ${{ secrets.SPLIT_TOKEN }}
131131
PG_TOKEN: ${{ secrets.PACKAGIST_SAFE_TOKEN }}
132-
run: ./dev/google-cloud repo:compliance --format=ci -t $GH_TOKEN -p $PG_TOKEN
132+
run: |
133+
./dev/google-cloud repo:compliance \
134+
--format=ci \
135+
-t $GH_TOKEN \
136+
-p $PG_TOKEN \
137+
--skip Gax:repo # Skip repo check for Gax because issues are enabled

dev/src/Command/RepoComplianceCommand.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,27 @@ protected function configure()
4949
->addOption(
5050
'component',
5151
'c',
52-
InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY,
52+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
5353
'If specified, display repo info for this component only'
5454
)
5555
->addOption('token', 't', InputOption::VALUE_REQUIRED, 'Github token to use for authentication')
5656
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'can be "ci" or "table"', 'table')
5757
->addOption('packagist-token', 'p', InputOption::VALUE_REQUIRED, 'Packagist token for the webhook')
58+
->addOption(
59+
'skip',
60+
null,
61+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
62+
'key:value pair of component to compliance type to skip. Compliance types are ' .
63+
'repo, packagist, webhook, and teams. For example: "--skip Gax:teams,repo --skip Bigtable:teams"'
64+
)
5865
;
5966
}
6067

6168
protected function execute(InputInterface $input, OutputInterface $output)
6269
{
6370
// Create github client wrapper
6471
$http = new Client();
65-
$this->github = new GitHub(new RunShell(), $http, $input->getOption('token'), $output);
72+
$this->github = new GitHub(new RunShell(), $http, (string) $input->getOption('token'), $output);
6673
$this->packagist = new Packagist($http, self::PACKAGIST_USERNAME, $input->getOption('packagist-token') ?? '');
6774

6875
$format = $input->getOption('format');
@@ -82,6 +89,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
8289
];
8390
(clone $table)->setHeaders($headers)->render();
8491

92+
// Allow skipping checks via --skip option
93+
$skips = array_reduce($input->getOption('skip'), function ($list, $pair) {
94+
[$key, $val] = explode(':', $pair);
95+
$list[$key] = explode(',', $val);
96+
return $list;
97+
});
98+
8599
$components = $input->getOption('component')
86100
? array_map(fn ($c) => new Component($c), $input->getOption('component'))
87101
: Component::getComponents();
@@ -95,37 +109,40 @@ protected function execute(InputInterface $input, OutputInterface $output)
95109
do {
96110
$refreshDetails = false;
97111
if (!$details = $this->getRepoDetails($component)) {
98-
$settingsCheck = $packagistCheck = $webhookCheck = $teamCheck = false;
112+
$repoCheck = $packagistCheck = $webhookCheck = $teamsCheck = false;
99113
$details = array_fill(0, count($headers) - 1, '**REPO NOT FOUND**');
100114
$details[0] = str_replace('googleapis/', '', $component->getRepoName());
101115
continue;
102116
}
103-
$settingsCheck = $packagistCheck = $webhookCheck = $teamCheck = true;
104-
if (!$this->checkSettingsCompliance($details)) {
105-
$settingsCheck = false;
117+
[$repoCheck, $packagistCheck, $webhookCheck, $teamsCheck] = array_map(
118+
fn($type) => in_array($type, $skips[$component->getName()] ?? []) ? 'skipped' : true,
119+
['repo', 'packagist', 'webhook', 'teams']
120+
);
121+
if ($repoCheck !== 'skipped' && !$this->checkSettingsCompliance($details)) {
122+
$repoCheck = false;
106123
$refreshDetails |= $this->askFixSettingsCompliance($input, $output, $details);
107124
}
108-
if (!$this->checkWebhookCompliance($details)) {
125+
if ($webhookCheck !== 'skipped' && !$this->checkWebhookCompliance($details)) {
109126
$webhookCheck = $this->github->token ? ($isNewComponent ? 'skipped' : false) : null;
110127
$refreshDetails |= $this->askFixWebhookCompliance($input, $output, $details);
111128
}
112-
if (!$this->checkPackagistCompliance($details)) {
129+
if ($packagistCheck !== 'skipped' && !$this->checkPackagistCompliance($details)) {
113130
// New components don't have packagist config, so bypass for CI.
114131
$packagistCheck = $isNewComponent ? 'skipped' : false;
115132
$refreshDetails |= $this->askFixPackagistCompliance($input, $output, $details);
116133
$details['packagist_config'] ??= '**PACKAGE NOT FOUND**';
117134
}
118-
if (!$this->checkTeamCompliance($details)) {
119-
$teamCheck = $this->github->token ? false : null;
135+
if ($teamsCheck !== 'skipped' && !$this->checkTeamCompliance($details)) {
136+
$teamsCheck = $this->github->token ? false : null;
120137
$refreshDetails |= $this->askFixTeamCompliance($input, $output, $component->getRepoName());
121138
}
122139
} while ($refreshDetails);
123140

124141
$details['compliant'] = implode("\n", [
125-
sprintf('%s Issues, Projects, Wiki, Pages, and Discussion are disabled', $emoji($settingsCheck)),
126-
sprintf('%s Packagist webhook is configured', $emoji($webhookCheck)),
127-
sprintf('%s Packagist maintainer is "google-cloud"', $emoji($packagistCheck)),
128-
sprintf('%s Github teams permissions are configured correctly', $emoji($teamCheck)),
142+
sprintf('%s [repo] Issues, Projects, Wiki, Pages, and Discussion are disabled', $emoji($repoCheck)),
143+
sprintf('%s [webhook] Packagist webhook is configured', $emoji($webhookCheck)),
144+
sprintf('%s [packagist] Packagist maintainer is "google-cloud"', $emoji($packagistCheck)),
145+
sprintf('%s [teams] Github teams permissions are configured correctly', $emoji($teamsCheck)),
129146
'',
130147
]);
131148
if ($format == 'ci') {
@@ -134,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
134151
$componentTable = (clone $table);
135152
$componentTable->addRow($details)->render();
136153

137-
if (!($settingsCheck && $webhookCheck && $packagistCheck && $teamCheck)) {
154+
if (!($repoCheck && $webhookCheck && $packagistCheck && $teamsCheck)) {
138155
$failed[] = $componentTable;
139156
}
140157
}

0 commit comments

Comments
 (0)