|
6 | 6 |
|
7 | 7 | use function Castor\PHPQa\php_cs_fixer;
|
8 | 8 | use function Castor\PHPQa\phpstan;
|
| 9 | +use function Castor\context; |
| 10 | +use function Castor\run; |
9 | 11 |
|
10 | 12 | #[AsTask('cs:check', namespace: 'qa', description: 'Check for coding standards without fixing them')]
|
11 | 13 | function qa_cs_check()
|
@@ -73,3 +75,82 @@ function debug_mapper(string $source, string $target, string $load = '')
|
73 | 75 |
|
74 | 76 | $command->run($input, \Castor\output());
|
75 | 77 | }
|
| 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