-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7ebc6e
commit b69e7ba
Showing
5 changed files
with
584 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,47 @@ | ||
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions | ||
|
||
name: "Check Docs" | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- "[0-9]+.[0-9]+.x" | ||
- "renovate/*" | ||
|
||
jobs: | ||
checkdocs: | ||
name: "Check Docs" | ||
|
||
runs-on: ${{ matrix.operating-system }} | ||
|
||
strategy: | ||
matrix: | ||
dependencies: | ||
- "locked" | ||
php-version: | ||
- "8.3" | ||
operating-system: | ||
- "ubuntu-latest" | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v4 | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/[email protected]" | ||
with: | ||
coverage: "pcov" | ||
php-version: "${{ matrix.php-version }}" | ||
ini-values: memory_limit=-1 | ||
extensions: pdo_sqlite | ||
|
||
- uses: ramsey/[email protected] | ||
with: | ||
dependency-versions: ${{ matrix.dependencies }} | ||
|
||
- name: "extract php code" | ||
run: "bin/extract-php-code-from-docs" | ||
|
||
- name: "lint php" | ||
run: "php -l docs_php/*.php" |
This file contains 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 |
---|---|---|
|
@@ -8,4 +8,5 @@ infection.log | |
.phpbench/ | ||
infection.html | ||
*.sqlite3 | ||
.deptrac.cache | ||
.deptrac.cache | ||
docs_php/ |
This file contains 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,59 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use League\CommonMark\Environment\Environment; | ||
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; | ||
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode; | ||
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension; | ||
use League\CommonMark\Node\Query; | ||
use League\CommonMark\Parser\MarkdownParser; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
|
||
$environment = new Environment([]); | ||
$environment->addExtension(new CommonMarkCoreExtension()); | ||
$environment->addExtension(new GithubFlavoredMarkdownExtension()); | ||
|
||
$parser = new MarkdownParser($environment); | ||
|
||
$path = __DIR__ . '/../docs/pages/subscription.md'; | ||
$targetDir = __DIR__ . '/../docs_php'; | ||
|
||
if (file_exists($targetDir)) { | ||
exec('rm -rf ' . $targetDir); | ||
} | ||
|
||
mkdir($targetDir); | ||
|
||
$finder = new Symfony\Component\Finder\Finder(); | ||
$finder->files()->in(__DIR__ . '/../docs/pages')->name('*.md'); | ||
|
||
foreach ($finder as $file) { | ||
$fileName = pathinfo($file->getBasename(), PATHINFO_FILENAME); | ||
|
||
$content = file_get_contents($file->getPathname()); | ||
$document = $parser->parse($content); | ||
|
||
$result = (new Query()) | ||
->where(Query::type(FencedCode::class)) | ||
->findAll($document); | ||
|
||
/** | ||
* @var FencedCode $node | ||
*/ | ||
foreach ($result as $node) { | ||
if ($node->getInfo() !== 'php') { | ||
continue; | ||
} | ||
|
||
$source = sprintf('%s:%s', $file->getRealPath(), $node->getStartLine()); | ||
|
||
$code = "<?php // " . $source . " \n\n" . $node->getLiteral() . "\n"; | ||
|
||
$targetPath = $targetDir . '/' . $fileName . '_' . $node->getStartLine() . '.php'; | ||
file_put_contents($targetPath, $code); | ||
|
||
$node->setLiteral($source); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.