Skip to content

Commit f1e0e17

Browse files
author
ci-bot
committed
chore(doc): update doc build system
1 parent cf1f71b commit f1e0e17

File tree

3 files changed

+85
-30
lines changed

3 files changed

+85
-30
lines changed

.github/scripts/build-documentation.sh

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

.github/workflows/documentation.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ jobs:
4141
- name: Install dependencies
4242
run: poetry install
4343

44+
- name: setup
45+
uses: castor-php/[email protected]
46+
4447
- name: Setup Pages
4548
id: pages
4649
uses: actions/configure-pages@v4
4750

4851
- name: Build documentation
49-
run: ./.github/scripts/build-documentation.sh
52+
run: castor doc:build-github-pages
5053

5154
- name: Check
5255
run: ls ./.build

castor.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use function Castor\PHPQa\php_cs_fixer;
88
use function Castor\PHPQa\phpstan;
9+
use function Castor\context;
10+
use function Castor\run;
911

1012
#[AsTask('cs:check', namespace: 'qa', description: 'Check for coding standards without fixing them')]
1113
function qa_cs_check()
@@ -73,3 +75,82 @@ function debug_mapper(string $source, string $target, string $load = '')
7375

7476
$command->run($input, \Castor\output());
7577
}
78+
79+
#[AsTask('install', namespace: 'doc', description: 'Install tool for documentation (need poetry)')]
80+
function doc_install() {
81+
run('poetry install');
82+
}
83+
84+
#[AsTask('server', namespace: 'doc', description: 'Serve documentation')]
85+
function doc_serve()
86+
{
87+
run('poetry run mkdocs serve -a localhost:8000');
88+
}
89+
90+
#[AsTask('build-github-pages', namespace: 'doc', description: 'Serve documentation')]
91+
function doc_build_github_pages()
92+
{
93+
// clean .build directory
94+
run('rm -rf ./.build', context: context()->withAllowFailure());
95+
96+
// create .build directory
97+
@mkdir(__DIR__ . '/.build');
98+
run('git config user.name ci-bot');
99+
run('git config user.email [email protected]');
100+
run('git remote add gh-pages ./.build', context: context()->withAllowFailure());
101+
102+
$context = context()->withWorkingDirectory(__DIR__ . '/.build');
103+
104+
run('git init', context: $context);
105+
run('git checkout -b gh-pages', context: $context);
106+
run('git config receive.denyCurrentBranch ignore', context: $context);
107+
108+
// build documentation for main branch
109+
run('poetry run mike deploy --push --remote gh-pages dev');
110+
111+
// get the list of tags
112+
$tags = run('git tag --list', context: context()->withQuiet())->getOutput();
113+
$tags = array_filter(array_map('trim', explode("\n", $tags)));
114+
115+
$minVersion = '8.2.2';
116+
$latestVersion = $minVersion;
117+
$buildTags = [];
118+
119+
foreach ($tags as $tag) {
120+
if (!version_compare($tag, $minVersion, '>=')) {
121+
continue;
122+
}
123+
124+
// version is X.Y.Z we want the X.Y part
125+
$parts = explode('.', $tag);
126+
if (count($parts) !== 3) {
127+
continue;
128+
}
129+
130+
$majorMinor = $parts[0] . '.' . $parts[1];
131+
132+
// get only the last version for this major.minor
133+
if (isset($buildTags[$majorMinor]) && version_compare($tag, $buildTags[$majorMinor], '<=')) {
134+
continue;
135+
}
136+
137+
if (version_compare($tag, $latestVersion, '>')) {
138+
$latestVersion = $tag;
139+
}
140+
141+
$buildTags[$majorMinor] = $tag;
142+
}
143+
144+
foreach ($buildTags as $tag) {
145+
run('git checkout tags/' . $tag);
146+
147+
if ($tag === $latestVersion) {
148+
run('poetry run mike deploy --push --remote gh-pages ' . $tag . ' latest');
149+
run('poetry run mike set-default --ignore-remote-status --push latest');
150+
} else {
151+
run('poetry run mike deploy --push --remote gh-pages --update-aliases ' . $tag);
152+
}
153+
}
154+
155+
run('git reset --hard gh-pages', context: $context);
156+
}

0 commit comments

Comments
 (0)