-
Notifications
You must be signed in to change notification settings - Fork 31
Add github workflow to verify docs #103
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Verify docs | ||
|
||
on: | ||
schedule: | ||
- cron: '58 6 * * *' | ||
|
||
jobs: | ||
use: | ||
name: Invalid use statements | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
|
||
steps: | ||
- name: Set up PHP | ||
uses: shivammathur/setup-php@2.7.0 | ||
with: | ||
php-version: 7.4 | ||
coverage: none | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Checkout Symfony repo | ||
run: git clone https://github.com/symfony/symfony .github/workflows/docs-invalid-use/symfony | ||
|
||
- name: Checkout Symfony Docs repo | ||
run: git clone https://github.com/symfony/symfony-docs .github/workflows/docs-invalid-use/docs | ||
|
||
- 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: Download dependencies | ||
run: | | ||
composer install --no-interaction --optimize-autoloader | ||
cd .github/workflows/docs-invalid-use | ||
composer update --prefer-stable --no-interaction --optimize-autoloader | ||
cd symfony | ||
composer update --prefer-stable --no-interaction --optimize-autoloader | ||
|
||
- name: Verify docs | ||
run: | | ||
cd .github/workflows/docs-invalid-use | ||
./run.php `pwd`/docs `pwd`/symfony > output.txt | ||
cat output.txt | ||
|
||
- name: Open issue | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.CARSONPROD_GITHUB_TOKEN }} | ||
run: | | ||
if [ ! -s .github/workflows/docs-invalid-use/output.txt ]; then | ||
echo "No issues to report" | ||
exit 0 | ||
fi | ||
|
||
echo -e "I've found some pages that have invalid class references. This is a list of use statements that I couldn't find the correct class to: \n\n\`\`\`" > issue.txt | ||
cat .github/workflows/docs-invalid-use/output.txt >> issue.txt | ||
echo -e "\n\`\`\`\n\nCould someone please verify these?" >> issue.txt | ||
bin/console app:issue:open symfony/symfony-docs "Invalid use statements" `pwd`/issue.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "tobias/docs-checker", | ||
"type": "project", | ||
"authors": [ | ||
{ | ||
"name": "Nyholm", | ||
"email": "tobias.nyholm@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"symfony/filesystem": "^5.1", | ||
"symfony/finder": "^5.1", | ||
"symfony/phpunit-bridge": "^5.1", | ||
"phpunit/phpunit": "^9.4", | ||
"defuse/php-encryption": "^2.2", | ||
"sensiolabs/ansi-to-html": "^1.2", | ||
"twig/twig": "^3.0", | ||
"symfony/mercure": "^0.4.0", | ||
"lcobucci/jwt": "^3.3", | ||
"symfony/psr-http-message-bridge": "^2.0", | ||
"ramsey/uuid": "^4.1", | ||
"twig/cssinliner-extra": "^3.0" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
if ($argc !== 3) { | ||
echo "./docs-invalid-use.php path-to-docs path-to-symfony\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo |
||
exit(1); | ||
} | ||
|
||
// Input | ||
$docs = $argv[1]; | ||
$symfony = $argv[2]; | ||
|
||
$autoload = [ | ||
__DIR__.'/vendor/autoload.php', | ||
$symfony.'/vendor/autoload.php', | ||
]; | ||
|
||
foreach ($autoload as $autoloadPHP) { | ||
if (!file_exists($autoloadPHP)) { | ||
echo "File $autoloadPHP does not exist.\nMake sure to run 'composer update'\n"; | ||
exit(1); | ||
} | ||
require $autoloadPHP; | ||
} | ||
|
||
use Symfony\Component\Finder\Finder; | ||
$finder = new Finder(); | ||
$finder->in($docs)->name('*.rst'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to include rst.inc files too |
||
|
||
$blocklist = getBlocklist(); | ||
$count = 0; | ||
foreach ($finder as $file) { | ||
$contents = $file->getContents(); | ||
$matches = []; | ||
if (preg_match_all('|^ +use (.*\\\.*); *?$|im', $contents, $matches)) { | ||
foreach ($matches[1] as $class) { | ||
if (substr($class, 0, 3) === 'App' || substr($class, 0, 4) === 'Acme') { | ||
continue; | ||
} | ||
|
||
if (false !== $pos = strpos($class, ' as ')) { | ||
$class = substr($class, 0, $pos); | ||
} | ||
|
||
if (false !== $pos = strpos($class, 'function ')) { | ||
continue; | ||
} | ||
|
||
if (in_array($class, $blocklist)) { | ||
continue; | ||
} | ||
|
||
$explode = explode('\\', $class); | ||
if (count($explode) === 3 && $explode[0] === 'Symfony' && $explode[1] === 'Component') { | ||
continue; | ||
} | ||
|
||
if (!class_exists($class) && !interface_exists($class) && !trait_exists($class)) { | ||
$count++; | ||
echo $file->getRelativePath().'/'.$file->getFilename(). ' - '.$class. PHP_EOL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ($count === 0) { | ||
error_log("We found nothing\n"); | ||
} | ||
|
||
exit(0); | ||
|
||
function getBlocklist(): array | ||
{ | ||
return [ | ||
'Doctrine\ORM\Mapping', | ||
'Symfony\Component\Validator\Constraints', | ||
'Simplex\StringResponseListener', | ||
'Calendar\Model\LeapYear', | ||
'Symfony\Component\Security\Core\Validator\Constraints', | ||
'Simplex\Framework', | ||
'Calendar\Controller\LeapYearController', | ||
'ApiPlatform\Core\Annotation\ApiResource', | ||
'Other\Qux', | ||
'Doctrine\Bundle\FixturesBundle\Fixture', | ||
'Vendor\DependencyClass', | ||
'Example\Namespace\YourAwesomeCoolClass', | ||
'Your\Transport\YourTransportFactory', | ||
]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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 <tobias.nyholm@gmail.com> | ||
*/ | ||
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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be added as a secret