Skip to content

Commit

Permalink
Strict mode for Dev Center generator
Browse files Browse the repository at this point in the history
Causes an exit(1) if warnings are emitted. Useful in tests or workflows.

GUS-W-14625693
  • Loading branch information
dzuelke committed Dec 7, 2023
1 parent 9aae9b5 commit 4a98181
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions support/devcenter/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

require('vendor/autoload.php');

$strict = false;

// these need updating from time to time to add new stacks and remove EOL ones
$stacks = [
1 => '20', // the offset we start with here is relevant for the numbering of footnotes
Expand All @@ -30,14 +32,17 @@
return $stacks;
};

$findseries = function(array $package) use($series) {
$findseries = function(array $package) use($series, $strict) {
if($package['require']) {
if(isset($package['require']['heroku-sys/php'])) {
return Composer\Semver\Semver::satisfiedBy($series, $package['require']['heroku-sys/php']);
}
}
// if there are no requirements specified for heroku-sys/php, this will match all PHP series (good luck with that, but rules are rules)
fprintf(STDERR, "WARNING: package %s (version %s) has no 'require' entry for 'heroku-sys/php' and may get resolved for any PHP series!\n", $package['name'], $package['version']);
if($strict) {
exit(1);
}
return $series;
};

Expand Down Expand Up @@ -84,7 +89,9 @@
}));
$client = new GuzzleHttp\Client(['handler' => $handlerStack, "timeout" => "2.0"]);

$sections = getopt('', ['runtimes', 'built-in-extensions', 'third-party-extensions', 'composers', 'webservers'], $restIndex);
$sections = getopt('', ['strict', 'runtimes', 'built-in-extensions', 'third-party-extensions', 'composers', 'webservers'], $restIndex);
$strict = isset($sections['strict']);
unset($sections['strict']);
$posArgs = array_slice($argv, $restIndex);

$repositories = [];
Expand Down Expand Up @@ -235,6 +242,9 @@
if($ignoredSeries = array_diff($detectedSeries, $series)) {
// a warning is appropriate here: there are available packages that are not whitelisted and thus will not show up in documentation
fprintf(STDERR, "WARNING: runtime series ignored in input due to missing whitelist entries: %s\n", implode(', ', $ignoredSeries));
if($strict) {
exit(1);
}
}
// if they're whitelisted, but missing... well...
if($missingSeries = array_diff($series, $detectedSeries)) {
Expand Down

0 comments on commit 4a98181

Please sign in to comment.