Skip to content

Commit 40b6f59

Browse files
committed
Merge branch '2.x' into 3.x
* 2.x: Use the PHP doc builder instead of Sphinx in CI
2 parents 5318cca + 226b73c commit 40b6f59

File tree

9 files changed

+2064
-454
lines changed

9 files changed

+2064
-454
lines changed

.gitattributes

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/doc/** export-ignore
2-
/extra/** export-ignore
3-
/tests export-ignore
1+
/doc/ export-ignore
2+
/extra/ export-ignore
3+
/tests/ export-ignore
44
/phpunit.xml.dist export-ignore

.github/workflows/documentation.yml

+22-21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
push:
66
branches:
7+
- '2.x'
78
- '3.x'
89

910
permissions:
@@ -19,32 +20,32 @@ jobs:
1920
- name: "Checkout code"
2021
uses: actions/checkout@v2
2122

22-
- name: "Set up Python 3.7"
23-
uses: actions/setup-python@v1
23+
- name: "Set-up PHP"
24+
uses: shivammathur/setup-php@v2
2425
with:
25-
python-version: '3.7' # Semantic version range syntax or exact version of a Python version
26+
php-version: 8.1
27+
coverage: none
28+
tools: "composer:v2"
2629

27-
- name: "Display Python version"
28-
run: python -c "import sys; print(sys.version)"
30+
- name: Get composer cache directory
31+
id: composercache
32+
working-directory: doc/_build
33+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
2934

30-
- name: "Install Sphinx dependencies"
31-
run: sudo apt-get install python-dev build-essential
32-
33-
- name: "Cache pip"
35+
- name: Cache dependencies
3436
uses: actions/cache@v2
3537
with:
36-
path: ~/.cache/pip
37-
key: ${{ runner.os }}-pip-${{ hashFiles('_build/.requirements.txt') }}
38-
restore-keys: |
39-
${{ runner.os }}-pip-
40-
41-
- name: "Install Sphinx + requirements via pip"
42-
working-directory: "doc"
43-
run: pip install -r _build/.requirements.txt
44-
45-
- name: "Build documentation"
46-
working-directory: "doc"
47-
run: make -C _build SPHINXOPTS="-nqW -j auto" html
38+
path: ${{ steps.composercache.outputs.dir }}
39+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
40+
restore-keys: ${{ runner.os }}-composer-
41+
42+
- name: "Install dependencies"
43+
working-directory: doc/_build
44+
run: composer install --prefer-dist --no-progress
45+
46+
- name: "Build the docs"
47+
working-directory: doc/_build
48+
run: php build.php --disable-cache
4849

4950
doctor-rst:
5051
name: "DOCtor-RST"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/doc/_build/vendor
2+
/doc/_build/output
13
/composer.lock
24
/phpunit.xml
35
/vendor

doc/_build/.requirements.txt

-6
This file was deleted.

doc/_build/Makefile

-153
This file was deleted.

doc/_build/build.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__.'/vendor/autoload.php';
5+
6+
use Symfony\Component\Console\Application;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Console\Style\SymfonyStyle;
11+
use SymfonyDocsBuilder\BuildConfig;
12+
use SymfonyDocsBuilder\DocBuilder;
13+
14+
(new Application('Twig docs Builder', '1.0'))
15+
->register('build-docs')
16+
->addOption('disable-cache', null, InputOption::VALUE_NONE, 'Use this option to force a full regeneration of all doc contents')
17+
->setCode(function (InputInterface $input, OutputInterface $output) {
18+
$io = new SymfonyStyle($input, $output);
19+
$io->text('Building all Twig docs...');
20+
21+
$outputDir = __DIR__.'/output';
22+
$buildConfig = (new BuildConfig())
23+
->setContentDir(__DIR__.'/..')
24+
->setOutputDir($outputDir)
25+
->setImagesDir(__DIR__.'/output/_images')
26+
->setImagesPublicPrefix('_images')
27+
->setTheme('rtd')
28+
;
29+
30+
$buildConfig->setExcludedPaths(['vendor/']);
31+
$buildConfig->disableJsonFileGeneration();
32+
$buildConfig->disableBuildCache();
33+
34+
$result = (new DocBuilder())->build($buildConfig);
35+
36+
if ($result->isSuccessful()) {
37+
// fix assets URLs to make them absolute (otherwise, they don't work in subdirectories)
38+
foreach (glob($outputDir.'/**/*.html') as $htmlFilePath) {
39+
$htmlContents = file_get_contents($htmlFilePath);
40+
file_put_contents($htmlFilePath, str_replace('href="assets/', 'href="/assets/', $htmlContents));
41+
}
42+
43+
$io->success(sprintf('The Twig docs were successfully built at %s', realpath($outputDir)));
44+
} else {
45+
$io->error(sprintf("There were some errors while building the docs:\n\n%s\n", $result->getErrorTrace()));
46+
$io->newLine();
47+
$io->comment('Tip: you can add the -v, -vv or -vvv flags to this command to get debug information.');
48+
49+
return 1;
50+
}
51+
52+
return 0;
53+
})
54+
->getApplication()
55+
->setDefaultCommand('build-docs', true)
56+
->run();

doc/_build/composer.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"minimum-stability": "dev",
3+
"prefer-stable": true,
4+
"config": {
5+
"platform": {
6+
"php": "8.1.0"
7+
},
8+
"preferred-install": {
9+
"*": "dist"
10+
},
11+
"sort-packages": true
12+
},
13+
"require": {
14+
"php": ">=8.1",
15+
"symfony/console": "^5.4",
16+
"symfony/process": "^5.4",
17+
"symfony-tools/docs-builder": "^0.18"
18+
}
19+
}

0 commit comments

Comments
 (0)