Skip to content

Open issues for missing config reference #141

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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/docs-configuration-reference.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Verify docs

on:
schedule:
- cron: '0 10 * * *'

jobs:
use:
name: Configuration reference
runs-on: Ubuntu-20.04
strategy:
fail-fast: false

steps:
- name: Set up PHP
uses: shivammathur/[email protected]
with:
php-version: 7.4
coverage: none

- name: Checkout code
uses: actions/checkout@v2

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-7.4-${{ hashFiles('composer.*') }}
restore-keys: |
composer-${{ runner.os }}-7.4-
composer-${{ runner.os }}-
composer-

- name: Checkout Symfony repo
run: composer create-project --stability dev symfony/website-skeleton .github/workflows/docs-configuration-reference/symfony

- name: Checkout Symfony Docs repo
run: git clone https://github.com/symfony/symfony-docs .github/workflows/docs-configuration-reference/docs

- name: Download dependencies
run: composer install --no-interaction --optimize-autoloader

- name: Verify docs
env:
GITHUB_TOKEN: ${{ secrets.CARSONPROD_GITHUB_TOKEN }}
run: |
CURRENT_DIR=$(pwd)
for item in "debug:DebugBundle" "framework:FrameworkBundle" "security:SecurityBundle" "twig:TwigBundle" "web_profiler:WebProfilerBundle"
do
FILE=$(echo $item | cut -d ":" -f1)
BUNDLE=$(echo $item | cut -d ":" -f2)
echo ::group::$BUNDLE

echo "Trying to find missing config keys"
cd .github/workflows/docs-configuration-reference
./run.php `pwd`/symfony `pwd`/docs/reference/configuration/$FILE.rst $BUNDLE > $CURRENT_DIR/output.txt

cd $CURRENT_DIR
cat output.txt

if [ -s ./output.txt ]; then
echo "Creating an issue"
echo -e "I found that there are some configuration missing for the $BUNDLE configuration reference page. This is a list of what is missing: \n\n\`\`\`" > issue.txt
cat ./output.txt >> issue.txt
echo -e "\n\`\`\`\n\nCould someone please add these?" >> issue.txt
bin/console app:issue:open symfony/symfony-docs "[$BUNDLE] Missing configuration reference" `pwd`/issue.txt
fi
echo ::endgroup::
done
51 changes: 51 additions & 0 deletions .github/workflows/docs-configuration-reference/run.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env php
<?php

if ($argc !== 4) {
echo "./run.php path-to-symfony path-to-docs-page FrameworkBundle \n";
exit(2);
}

// Input
$symfony = $argv[1];
$docPage = $argv[2];
$bundleName = $argv[3];
require $symfony.'/vendor/autoload.php';

$referenceContent = file_get_contents($docPage);
$process = new \Symfony\Component\Process\Process(['bin/console','config:dump-reference', $bundleName, '--format', 'yaml'], $symfony);
$process->run();
if (0 !== $process->getExitCode()) {
error_log("We could not get configuration reference\n");
error_log($process->getErrorOutput());
exit(3);
}
$output = $process->getOutput();
$config = \Symfony\Component\Yaml\Yaml::parse($output);

// always remove the first key
$config = $config[$key = array_key_first($config)];

$missingKeys = [];
parseConfigKeys($referenceContent, $config, $key, $missingKeys);

if (count($missingKeys) === 0) {
error_log("We found nothing\n");
}

foreach ($missingKeys as $key) {
echo '- '.$key.PHP_EOL;
}

exit(0);

function parseConfigKeys(string $doc, array $config, string $base, array &$missingKeys) {
foreach ($config as $key => $value) {
if (!is_numeric($key) && !str_contains($doc, $key)) {
$missingKeys[] = $base . '.' . $key;
}
if (is_array($value)) {
parseConfigKeys($doc, $value, $base . '.' . $key, $missingKeys);
}
}
}
62 changes: 62 additions & 0 deletions src/Command/OpenIssueCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Command;

use App\Api\Issue\IssueApi;
use App\Service\RepositoryProvider;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Open or update issues.
*
* @author Tobias Nyholm <[email protected]>
*/
class OpenIssueCommand extends Command
{
protected static $defaultName = 'app:issue:open';
private $issueApi;
private $repositoryProvider;

public function __construct(RepositoryProvider $repositoryProvider, IssueApi $issueApi)
{
parent::__construct();
$this->issueApi = $issueApi;
$this->repositoryProvider = $repositoryProvider;
}

protected function configure()
{
$this->addArgument('repository', InputArgument::REQUIRED, 'The full name to the repository, eg symfony/symfony-docs');
$this->addArgument('title', InputArgument::REQUIRED, 'The title of the issue');
$this->addArgument('file', InputArgument::REQUIRED, 'The path to the issue body text file');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var string $repositoryName */
$repositoryName = $input->getArgument('repository');
$repository = $this->repositoryProvider->getRepository($repositoryName);
if (null === $repository) {
$output->writeln('Repository not configured');

return 1;
}

/** @var string $title */
$title = $input->getArgument('title');
/** @var string $filePath */
$filePath = $input->getArgument('file');

$body = file_get_contents($filePath);
if (false === $body) {
return 1;
}

$this->issueApi->open($repository, $title, $body, ['help wanted']);

return 0;
}
}