Skip to content

Commit 844f09e

Browse files
committed
refactor
1 parent 648655d commit 844f09e

30 files changed

+7082
-950
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Try build docs
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "renovate/*"
8+
9+
jobs:
10+
build-try:
11+
name: Deploy docs
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.x"
22+
23+
- name: Install dependencies
24+
run: pip install -r docs/requirements.txt
25+
26+
- name: Build docs
27+
working-directory: docs/
28+
run: |
29+
mkdocs build --strict

.github/workflows/docs-build.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Publish docs
2+
3+
on:
4+
push:
5+
branches:
6+
- "[0-9]+.[0-9]+.x"
7+
release:
8+
types:
9+
- published
10+
11+
jobs:
12+
build:
13+
name: Deploy docs
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.x"
24+
25+
- name: Install dependencies
26+
run: pip install -r docs/requirements.txt
27+
28+
- name: Set up git author
29+
uses: oleksiyrudenko/gha-git-credentials@v2
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Find latest release
34+
id: latest_release
35+
uses: pozetroninc/github-action-get-latest-release@v0.8.0
36+
with:
37+
repository: ${{ github.repository }}
38+
excludes: draft,prerelease
39+
40+
- name: Normalize current versions
41+
id: current
42+
uses: actions/github-script@v7
43+
with:
44+
script: return context.ref.match(/([0-9]+\.[0-9]+)\.(x|[0-9]+)/i)[1];
45+
result-encoding: string
46+
47+
- name: Normalize latest versions
48+
id: latest
49+
uses: actions/github-script@v7
50+
with:
51+
script: return "${{steps.latest_release.outputs.release}}".match(/([0-9]+\.[0-9]+)\.[0-9]+/i)[1];
52+
result-encoding: string
53+
54+
- name: Setup deploy key
55+
env:
56+
DEPLOY_DOCS_KEY: ${{ secrets.DEPLOY_DOCS_KEY }}
57+
run: |
58+
# Setup SSH deploy key
59+
mkdir -p ~/.ssh
60+
echo "${DEPLOY_DOCS_KEY}" > ~/.ssh/id_rsa
61+
chmod 600 ~/.ssh/id_rsa
62+
ssh-keyscan -H github.com > ~/.ssh/known_hosts
63+
64+
- run: git remote add doc git@github.com:patchlevel/event-sourcing-bundle-docs.git
65+
- run: git fetch doc gh-pages --verbose
66+
67+
- run: |
68+
current_major=$(echo "$version_current" | cut -d '.' -f 1)
69+
current_minor=$(echo "$version_current" | cut -d '.' -f 2)
70+
71+
latest_major=$(echo "$version_latest" | cut -d '.' -f 1)
72+
latest_minor=$(echo "$version_latest" | cut -d '.' -f 2)
73+
74+
if [ "${{ steps.current.outputs.result }}" = "${{ steps.latest.outputs.result }}" ]
75+
then
76+
# Here we deploy a new latest version
77+
mike deploy latest --config-file docs/mkdocs.yml --title="${{ steps.current.outputs.result }} (latest)" --push --remote doc
78+
elif [ "$current_major" -lt "$latest_major" ] || \
79+
{ [ "$current_major" -eq "$latest_major" ] && [ "$current_minor" -lt "$latest_minor" ]; }
80+
then
81+
# Here we deploy a version that's not the latest one and smaller as the latest version
82+
mike deploy ${{ steps.current.outputs.result }} --config-file docs/mkdocs.yml --push --remote doc
83+
fi
84+
- run: |
85+
# Check if the "latest" alias exists
86+
HAS_LATEST=$(mike list --config-file docs/mkdocs.yml --rebase --remote doc | grep latest) || true
87+
88+
# If so then it is set as the default version (to enable the index redirect)
89+
if [ "${HAS_LATEST}" != "" ]
90+
then
91+
echo "Set latest as default"
92+
mike set-default latest --config-file docs/mkdocs.yml --remote doc
93+
fi

.github/workflows/docs-check.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
name: "Check Docs"
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- "[0-9]+.[0-9]+.x"
10+
11+
jobs:
12+
checkdocs:
13+
name: "Check Docs"
14+
15+
runs-on: ${{ matrix.operating-system }}
16+
17+
strategy:
18+
matrix:
19+
dependencies:
20+
- "locked"
21+
php-version:
22+
- "8.3"
23+
operating-system:
24+
- "ubuntu-latest"
25+
26+
steps:
27+
- name: "Checkout"
28+
uses: actions/checkout@v4
29+
30+
- name: "Install PHP"
31+
uses: "shivammathur/setup-php@2.31.1"
32+
with:
33+
coverage: none
34+
php-version: "${{ matrix.php-version }}"
35+
ini-values: memory_limit=-1, opcache.enable_cli=1
36+
extensions: pdo_sqlite
37+
38+
- uses: ramsey/composer-install@3.0.0
39+
with:
40+
dependency-versions: ${{ matrix.dependencies }}
41+
42+
- name: "extract php code"
43+
run: "bin/docs-extract-php-code"
44+
45+
- name: "lint php"
46+
run: "php -l docs_php/*.php"
47+
48+
- name: "docs code style"
49+
run: "vendor/bin/phpcbf docs_php --exclude=SlevomatCodingStandard.TypeHints.DeclareStrictTypes"

.github/workflows/psalm.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

Makefile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,11 @@ cs: vendor
1414

1515
.PHONY: phpstan
1616
phpstan: vendor ## run phpstan static code analyser
17-
vendor/bin/phpstan analyse
17+
php -d memory_limit=512M vendor/bin/phpstan analyse
1818

1919
.PHONY: phpstan-baseline
2020
phpstan-baseline: vendor ## run phpstan static code analyser
21-
vendor/bin/phpstan analyse --generate-baseline
22-
23-
.PHONY: psalm
24-
psalm: vendor ## run psalm static code analyser
25-
vendor/bin/psalm
26-
27-
.PHONY: psalm-baseline
28-
psalm-baseline: vendor ## run psalm static code analyser
29-
vendor/bin/psalm --update-baseline --set-baseline=baseline.xml
30-
21+
php -d memory_limit=512M vendor/bin/phpstan analyse --generate-baseline
3122

3223
.PHONY: phpunit
3324
phpunit: vendor ## run phpunit tests

baseline.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

bin/docs-extract-php-code

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use League\CommonMark\Environment\Environment;
5+
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
6+
use League\CommonMark\Node\Query;
7+
use League\CommonMark\Parser\MarkdownParser;
8+
use Wnx\CommonmarkMarkdownRenderer\MarkdownRendererExtension;
9+
10+
require __DIR__ . '/../vendor/autoload.php';
11+
12+
$environment = new Environment([]);
13+
$environment->addExtension(new MarkdownRendererExtension());
14+
15+
$parser = new MarkdownParser($environment);
16+
17+
$targetDir = __DIR__ . '/../docs_php';
18+
19+
if (file_exists($targetDir)) {
20+
exec('rm -rf ' . $targetDir);
21+
}
22+
23+
mkdir($targetDir);
24+
25+
$finder = new Symfony\Component\Finder\Finder();
26+
$finder->files()->in(__DIR__ . '/../docs/pages')->name('*.md');
27+
28+
foreach ($finder as $file) {
29+
$fileName = pathinfo($file->getBasename(), PATHINFO_FILENAME);
30+
31+
$content = file_get_contents($file->getPathname());
32+
$document = $parser->parse($content);
33+
34+
$result = (new Query())
35+
->where(Query::type(FencedCode::class))
36+
->findAll($document);
37+
38+
/**
39+
* @var FencedCode $node
40+
*/
41+
foreach ($result as $i => $node) {
42+
if ($node->getInfo() !== 'php') {
43+
continue;
44+
}
45+
46+
$source = sprintf('%s:%s', $file->getRealPath(), $node->getStartLine());
47+
48+
$code = "<?php\n// " . $source . "\n\n" . $node->getLiteral();
49+
50+
$targetPath = $targetDir . '/' . $fileName . '_' . $i . '.php';
51+
file_put_contents($targetPath, $code);
52+
}
53+
}

bin/docs-inject-php-code

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use League\CommonMark\Environment\Environment;
5+
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
6+
use League\CommonMark\Node\Query;
7+
use League\CommonMark\Parser\MarkdownParser;
8+
use Wnx\CommonmarkMarkdownRenderer\MarkdownRendererExtension;
9+
use Wnx\CommonmarkMarkdownRenderer\Renderer\MarkdownRenderer;
10+
11+
require __DIR__ . '/../vendor/autoload.php';
12+
13+
14+
15+
$environment = new Environment([]);
16+
$environment->addExtension(new MarkdownRendererExtension());
17+
18+
$parser = new MarkdownParser($environment);
19+
$markdownRenderer = new MarkdownRenderer($environment);
20+
21+
$targetDir = __DIR__ . '/../docs_php';
22+
23+
if (!file_exists($targetDir)) {
24+
exit(1);
25+
}
26+
27+
$finder = new Symfony\Component\Finder\Finder();
28+
$finder->files()->in(__DIR__ . '/../docs/pages')->name('*.md');
29+
30+
foreach ($finder as $file) {
31+
$fileName = pathinfo($file->getBasename(), PATHINFO_FILENAME);
32+
33+
$content = file_get_contents($file->getPathname());
34+
$document = $parser->parse($content);
35+
36+
$result = (new Query())
37+
->where(Query::type(FencedCode::class))
38+
->findAll($document);
39+
40+
/**
41+
* @var FencedCode $node
42+
*/
43+
foreach ($result as $i => $node) {
44+
if ($node->getInfo() !== 'php') {
45+
$node->setLiteral(trim($node->getLiteral()));
46+
continue;
47+
}
48+
49+
$targetPath = $targetDir . '/' . $fileName . '_' . $i . '.php';
50+
51+
if (!file_exists($targetPath)) {
52+
$node->setLiteral(trim($node->getLiteral()));
53+
continue;
54+
}
55+
56+
$code = file_get_contents($targetPath);
57+
58+
$lines = explode("\n", $code);
59+
array_splice($lines, 0, 2);
60+
$code = implode("\n", $lines);
61+
62+
$node->setLiteral(trim($code));
63+
}
64+
65+
file_put_contents($file->getPathname(), $markdownRenderer->renderDocument($document));
66+
}
67+
68+
if (file_exists($targetDir)) {
69+
exec('rm -rf ' . $targetDir);
70+
}

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@
2525
"require-dev": {
2626
"ext-pdo_sqlite": "*",
2727
"infection/infection": "^0.27.0",
28+
"league/commonmark": "^2.4",
2829
"patchlevel/coding-standard": "^1.3.0",
2930
"phpspec/prophecy-phpunit": "^2.1.0",
3031
"phpstan/phpstan": "^1.10.48",
3132
"phpunit/phpunit": "^10.5.2",
33+
"psalm/plugin-laravel": "^2.11",
3234
"roave/security-advisories": "dev-master",
3335
"symfony/var-dumper": "^6.4.0|^7.0.0",
34-
"vimeo/psalm": "^5.17.0"
36+
"vimeo/psalm": "^5.17.0",
37+
"wnx/commonmark-markdown-renderer": "^1.4",
38+
"larastan/larastan": "^v2.9.9",
39+
"laravel/framework": "^9.0|^10.0|^11.0"
3540
},
3641
"config": {
3742
"preferred-install": {

0 commit comments

Comments
 (0)