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

Add monitoring functionality to display code generation steps and progress #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
111 changes: 111 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Testing PHP Code Generator
on: [push, pull_request]

jobs:
tests:
strategy:
fail-fast: false
matrix:
php-version:
- "7.3"
- "7.4"
os: [ubuntu-latest]
experimental: [false]
include:
- php-version: "8.0"
os: ubuntu-latest
experimental: true
runs-on: ${{ matrix.os }}
name: PHP ${{ matrix.php-version }} Test on ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
steps:
- name: "Checkout"
uses: "actions/[email protected]"

- name: "Install PHP"
uses: "shivammathur/[email protected]"
with:
php-version: "${{ matrix.php-version }}"
coverage: xdebug

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: |
composer install --no-progress --prefer-dist --optimize-autoloader

- name: Run Tests
run: php vendor/bin/phpunit --coverage-text

coding-standard:
name: Coding Standard
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: PHP CodeSniffer
run: composer cs

static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Static Analysis using PHPStan
run: composer analyse
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ All notable changes to this project will be documented in this file, in reverse

### Added

* Nothing
* Monitoring functionality to display code generation steps and progress.

### Deprecated

* Nothing

### Removed

* Nothing
The following classes are removed (deprecated in 0.2.0).

* Class `\OpenCodeModeling\CodeGenerator\Config\ArrayConfig`
* Class `\OpenCodeModeling\CodeGenerator\Config\Component`
* Class `\OpenCodeModeling\CodeGenerator\Config\ComponentCollection`
* Class `\OpenCodeModeling\CodeGenerator\Config\ComponentList`

### Fixed

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"require": {
"php": "^7.3 || ^8.0",
"psr/log": "^1.1",
"symfony/console": "^4.4 || ^5.0 "
},
"require-dev": {
Expand Down
53 changes: 38 additions & 15 deletions docs/book/02-configuration.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
# Configuration

The code generator CLI can be started through the `bin/ocmcg` executable. This prints the available CLI commands.
The CLI command `ocmcg:workflow:run` executes the code generation depending on the configuration file. The default
The code generator is shipped with a CLI which executes the code generation depending on the configuration file. The default
configuration file name is `open-code-modeling.php.dist` which should be located in the root folder of the application
/ repository.

This file gets the variable `$workflowContext` provided to configure needed slot data for the code generation e. g.
paths or global data. You have to return an instance of a class which implements `OpenCodeModeling\CodeGenerator\Config\Config`
interface.

The following example add some slot data to the workflow context (`$workflowContext->put()`).
The following code shows a "Hello World!" example. It prepares the `WorkflowContext` object with the first part of the
greeting under slot name `part_one`. The workflow consists of two steps. Step *one* adds the second part of the greeting
to the given input from slot name `part_one`. The returned value is stored under the slot name `greeting`. Step *two*
prints the string of the input slot name `greeting`. It doesn't has an output slot name.

```
use OpenCodeModeling\CodeGenerator;

/** @var CodeGenerator\Workflow\WorkflowContext $workflowContext */
$workflowContext->put('xml_filename', 'data/domain.xml');

$config = new CodeGenerator\Config\ComponentList(
...[
new CodeGenerator\Config\ComponentConfig(
CodeGenerator\Transformator\StringToFile::workflowComponentDescription(
Inspectio\WorkflowConfigFactory::SLOT_GRAPHML_XML,
'xml_filename'
)
$workflowContext->put('part_one', 'Hello'); // init some data so it's available as an input slot name

$config = new CodeGenerator\Config\Workflow(
// step one
new CodeGenerator\Workflow\ComponentDescriptionWithSlot(
function(string $inputHello) {
return $inputHello . ' World!';
},
'greeting', // output slot name
'part_one' // input slot name
),
// step two
new CodeGenerator\Workflow\ComponentDescriptionWithInputSlotOnly(
function(string $greeting) {
echo $greeting;
},
'greeting', // input slot name
),
]
);

$config->addConsoleCommands(new Inspectio\Console\XmlGenerateAllCommand());

return $config;
```

## Register additional Symfony CLI commands

It is possible to add additional CLI commands to the code generator CLI. You can register additional Symfony CLI commands
by adding them to the `$config` object via `$config->addConsoleCommands(new AwesomeCliCommand())`.

## Register a monitor

A monitor can be used to display code generation steps and progress.

You can register a monitor instance of type `\OpenCodeModeling\CodeGenerator\Workflow\Monitoring\Monitoring` to the
`$config` object via `$config->setMonitor(new AwesomeMonitor())`. The Code Generator is shipped with a `Psr\Log\LoggerInterface`
monitor (`\OpenCodeModeling\CodeGenerator\Workflow\Monitoring\LoggerMonitor`).
30 changes: 29 additions & 1 deletion docs/book/03-cli.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# Code Generator CLI

TODO CLI call example
The code generator CLI can be started through the `bin/ocmcg` executable. This prints the registered CLI commands from
workflows, and the default available CLI commands. The CLI command `ocmcg:workflow:run` executes the code generation
depending on the configuration file. You can use the CLI option `-c` to specify a specific configuration file.

```
===========================================
Open Code Modeling - PHP Code Generator CLI
===========================================


Usage:
command [options] [arguments]

Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-c, --config=CONFIG Configuration file
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
help Displays help for a command
list Lists commands
ocmcg
ocmcg:workflow:run Executes workflow from configuration file to generate code
```
57 changes: 0 additions & 57 deletions src/Config/ArrayConfig.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Config/ComponentCollection.php

This file was deleted.

Loading