Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial structure of docbook tool process #1

Merged
merged 25 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f46d16
Initial structure of docbook tool process
asgrim Jan 27, 2021
43fe6a9
Added a basic integration test to compare output of HTML
asgrim Jan 28, 2021
a4fa97d
Apply all possible CS excluding PHP 8 incorrect applications
asgrim Jan 28, 2021
15c4282
Made static analysis green too
asgrim Jan 28, 2021
e691a68
Allow writer choices to be specified by basic CLI options
asgrim Jan 28, 2021
9984c46
Fixed inline rendering of PlantUML diagrams
asgrim Jan 28, 2021
e184ecb
Extract front matter from files
asgrim Jan 28, 2021
287c886
Added another file to test MD is still rendered with no front matter
asgrim Jan 28, 2021
711b2ac
Use monolog for CLI logging
asgrim Jan 28, 2021
2d4a86e
Added ConfluenceWriter implementation
asgrim Jan 28, 2021
d1917e9
Specify if ENV vars are optional or not in README
asgrim Jan 28, 2021
cd52a36
Added GitHub Actions pipeline
asgrim Jan 28, 2021
c5284b2
Pipeline needs wkhtmltopdf installed too
asgrim Jan 28, 2021
ad05e1b
Check java/wkhtmltopdf is installed in composer install/update
asgrim Jan 28, 2021
b6e497e
Ensure pages are sorted deterministically
asgrim Jan 28, 2021
0a04490
Use format matching rather than exact matching to allow for variance …
asgrim Jan 28, 2021
0689c56
Removed todo for java check since was added to composer install script
asgrim Jan 28, 2021
8b15656
Since wkhtmltopdf is checked in composer.json, add it up front to GH …
asgrim Jan 28, 2021
3a60d7a
Defer PDF testing to a GH issue for future work
asgrim Jan 28, 2021
257f2fe
Use webmozart/assert for various assertions for runtime safety
asgrim Jan 28, 2021
292922c
Convert FormatAllThePages into an array_map-able API instead
asgrim Jan 28, 2021
16c289c
Added @throws annotations
asgrim Jan 28, 2021
d235587
Scope vendor require within IIFE main
asgrim Jan 28, 2021
dfe3a49
Extract generation of writers to a separate factory
asgrim Jan 28, 2021
6dc0907
Extract environment variable checking to be exceptional or optional
asgrim Jan 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Coding Standards"

on:
pull_request:
push:

jobs:
coding-standards:
name: "Coding Standards"

runs-on: ${{ matrix.operating-system }}

strategy:
matrix:
php-version:
- "8.0"
operating-system:
- "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install wkhtmltopdf"
run: "sudo apt-get install xvfb libfontconfig wkhtmltopdf"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"

- name: "Install locked dependencies"
run: "composer install --no-interaction --no-progress --no-suggest"

- name: "Run phpcs"
run: "vendor/bin/phpcs"
59 changes: 59 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "PHPUnit tests"

on:
pull_request:
push:

jobs:
tests:
name: "PHPUnit tests"

runs-on: ${{ matrix.operating-system }}

strategy:
matrix:
dependencies:
- "lowest"
- "highest"
- "locked"
php-version:
- "8.0"
operating-system:
- "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install wkhtmltopdf"
run: "sudo apt-get install xvfb libfontconfig wkhtmltopdf"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"

- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest"

- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --no-interaction --no-progress --no-suggest"

- name: "Install locked dependencies"
if: ${{ matrix.dependencies == 'locked' }}
run: "composer install --no-interaction --no-progress --no-suggest"

- name: "Run phpunit"
run: "xvfb-run -- vendor/bin/phpunit"
46 changes: 46 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Static Analysis"

on:
pull_request:
push:

jobs:
static-analysis:
name: "Static Analysis"

runs-on: ${{ matrix.operating-system }}

strategy:
matrix:
php-version:
- "8.0"
operating-system:
- "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install wkhtmltopdf"
run: "sudo apt-get install xvfb libfontconfig wkhtmltopdf"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: |
~/.composer/cache
vendor
key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"
restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}"

- name: "Install locked dependencies"
run: "composer install --no-interaction --no-progress --no-suggest"

- name: "Run psalm"
run: "vendor/bin/psalm"
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Alternate workflow example.
# This one is identical to the one in release-on-milestone.yml, with one change:
# the Release step uses the ORGANIZATION_ADMIN_TOKEN instead, to allow it to
# trigger a release workflow event. This is useful if you have other actions
# that intercept that event.

name: "Automatic Releases"

on:
milestone:
types:
- "closed"

jobs:
release:
name: "GIT tag, release & create merge-up PR"
runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Release"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:release"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}

- name: "Create Merge-Up Pull Request"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-merge-up-pull-request"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}

- name: "Create and/or Switch to new Release Branch"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}

- name: "Create new milestones"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-milestones"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/vendor/
.env
/build/
.phpunit.result.cache
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,34 @@ Static HTML and PDF generator tool for generating documentation from Markdown fi

## Usage

TBD
```bash
bin/docbook-tool [--html] [--pdf] [--confluence]
```

For example, this command would generate only the HTML documentation:

```bash
$ DOCBOOK_TOOL_CONTENT_PATH=/path/to/myproject/docs/book \
> DOCBOOK_TOOL_TEMPLATE_PATH=/path/to/myproject/docs/template \
> DOCBOOK_TOOL_OUTPUT_HTML_FILE=/path/to/myproject/build/docs.html \
> bin/docbook-tool --html
[2021-01-28T12:28:41.000628+00:00] cli.INFO: Writing HTML output to /path/to/myproject/build/docs.html [] []
$
```

## Environment variables

* `DOCBOOK_TOOL_CONTENT_PATH` - the path where your Markdown documentation is kept (Required)
* Example: `/path/to/myproject/docs/book`
* `DOCBOOK_TOOL_TEMPLATE_PATH` - the path to your Twig templates called `online.twig` and `pdf.twig` (Required)
* Example: `/path/to/myproject/docs/template`
* `DOCBOOK_TOOL_FEATURES_PATH` - the base path from where features are stored (Optional)
* Example: `/path/to/myproject/features`
* `DOCBOOK_TOOL_OUTPUT_HTML_FILE` - where to generate the HTML documentation (Required, if using `--html`)
* Example: `/path/to/myproject/build/docs/index.html`
* `DOCBOOK_TOOL_OUTPUT_PDF_PATH` - where to generate the PDF files, if used (Required, if using `--pdf`)
* Example: `/path/to/myproject/build/docs/pdf`
* `DOCBOOK_TOOL_CONFLUENCE_URL` - the base URL of confluence (`/rest/api/content` is appended to this, so don't include that) (Required, if using `--confluence`)
* Example: `https://confluence.mycompany.com`
* `DOCBOOK_TOOL_CONFLUENCE_AUTH_TOKEN` - the `Authorization` header value to use (Required, if using `--confluence` in a non-interactive terminal)
* Example: `Basic bXktdXNlcm5hbWU6bXktcGFzc3dvcmQ=`
48 changes: 45 additions & 3 deletions bin/docbook-tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,48 @@

namespace Roave\DocbookTool;

(static function (): void {
echo "Hi.\n";
})();
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Roave\DocbookTool\Formatter\AggregatePageFormatter;
use Roave\DocbookTool\Formatter\ExtractFrontMatter;
use Roave\DocbookTool\Formatter\InlineFeatureFile;
use Roave\DocbookTool\Formatter\MarkdownToHtml;
use Roave\DocbookTool\Formatter\RenderPlantUmlDiagramInline;
use Roave\DocbookTool\Writer\WriterFactory;
use Twig\Environment as Twig;
use Twig\Loader\FilesystemLoader;

use function array_map;
use function is_string;

(static function (array $arguments): void {
require_once __DIR__ . '/../vendor/autoload.php';

$contentPath = Environment::require('DOCBOOK_TOOL_CONTENT_PATH');
$templatePath = Environment::require('DOCBOOK_TOOL_TEMPLATE_PATH');
$featuresPath = Environment::optional('DOCBOOK_TOOL_FEATURES_PATH');

$twig = new Twig(new FilesystemLoader($templatePath));

$logger = new Logger('cli');
$logger->pushHandler(new StreamHandler('php://stdout'));

$outputWriters = (new WriterFactory($twig, $logger))($arguments);

$pageFormatters = [
new ExtractFrontMatter(),
new RenderPlantUmlDiagramInline(),
new MarkdownToHtml(),
];

if (is_string($featuresPath)) {
$pageFormatters[] = new InlineFeatureFile($featuresPath);
}

(new WriteAllTheOutputs($outputWriters))(
array_map(
[new AggregatePageFormatter($pageFormatters), '__invoke'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird - did it not work with just new AggregatePageFormatter() (considering it's already callable)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea, I didn't actually check 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting:

ERROR: MixedArgumentTypeCoercion - bin/docbook-tool.php:46:9 - Argument 1 of Roave\DocbookTool\WriteAllTheOutputs::__invoke expects array<array-key, Roave\DocbookTool\DocbookPage>, parent type array<array-key, mixed> provided (see https://psalm.dev/194)
        array_map(
            new AggregatePageFormatter($pageFormatters),
            (new RecursivelyLoadPagesFromPath())($contentPath)
        )


------------------------------
1 errors found
------------------------------

(new RecursivelyLoadPagesFromPath())($contentPath)
)
);
})($argv);
Binary file added bin/plantuml.jar
Binary file not shown.
24 changes: 22 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
"require": {
"php": "8.0.*",
"guzzlehttp/guzzle": "^7.2",
"guzzlehttp/psr7": "^1.7",
"michelf/php-markdown": "^1.9",
"monolog/monolog": "^2.2",
"psr/log": "^1.1",
"symfony/yaml": "^5.2",
"thecodingmachine/safe": "^1.3",
"twig/twig": "^3.2"
"twig/twig": "^3.2",
"webmozart/assert": "^1.9"
},
"require-dev": {
"doctrine/coding-standard": "^8.2",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.15.1",
"roave/security-advisories": "dev-latest",
"vimeo/psalm": "^4.4"
},
Expand All @@ -28,13 +35,26 @@
},
"autoload-dev": {
"psr-4": {
"Roave\\DocbookToolUnitTest\\": "test/unit"
"Roave\\DocbookToolIntegrationTest\\": "test/integration"
}
},
"suggest": {
"ext-posix": "Allows interactive entry of Confluence credentials"
},
"bin": [
"bin/docbook-tool"
],
"config": {
"sort-packages": true
},
"scripts": {
"post-install-cmd": [
"which java",
"which wkhtmltopdf"
],
"post-update-cmd": [
"which java",
"which wkhtmltopdf"
]
}
}
Loading