Skip to content

Commit

Permalink
Added composer.json to each example and make it standalone downloadab…
Browse files Browse the repository at this point in the history
…le project (#1440)

* Added composer.json to each example and make it standalone downloadable project

* Updated composer.lock

* Removed dependency added by mistake during development

* Fixed code higlight in docs

* Simplified reading composer.json content in examples

* Reduced example archive size and excluded .env/vendor from archives

* Fixed indention in test-suite.yml
  • Loading branch information
norberttech authored Feb 2, 2025
1 parent 12bf88e commit 464399b
Show file tree
Hide file tree
Showing 199 changed files with 1,301 additions and 114 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ jobs:
run: "composer test:adapter:xml"

- name: "Test - Examples"
if: ${{ matrix.php-version == '8.2' && matrix.dependencies == 'locked' }}
run: "composer test:examples"

- name: "Download artifact"
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build/flow.phar.asc
var
vendor
compose.yml
phpunit.xml
phpunit.xml
.env
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,30 @@
"php-http/curl-client": "^2.2",
"php-http/mock-client": "^1.5",
"ramsey/uuid": "^4.5",
"symfony/http-client": "^5.4.47 || ^6.4 || ^7.0",
"symfony/cache": "^6.2 || ^7.0",
"symfony/dotenv": "^6.2 || ^7.0",
"symfony/finder": "^6.3 || ^7.0",
"symfony/http-client": "^5.4.47 || ^6.4 || ^7.0",
"symfony/process": "^7.2",
"symfony/uid": "^6.3 || ^7.0"
},
"replace": {
"flow-php/array-dot": "self.version",
"flow-php/azure-sdk": "self.version",
"flow-php/doctrine-dbal-bulk": "self.version",
"flow-php/doctrine-dbal-bulk-tools": "self.version",
"flow-php/dremel": "self.version",
"flow-php/etl": "self.version",
"flow-php/cli": "self.version",
"flow-php/etl-adapter-avro": "self.version",
"flow-php/etl-adapter-chartjs": "self.version",
"flow-php/etl-adapter-csv": "self.version",
"flow-php/etl-adapter-dbal-tools": "self.version",
"flow-php/etl-adapter-doctrine": "self.version",
"flow-php/etl-adapter-elasticsearch": "self.version",
"flow-php/etl-adapter-filesystem": "self.version",
"flow-php/etl-adapter-google-sheet": "self.version",
"flow-php/etl-adapter-http": "self.version",
"flow-php/etl-adapter-json": "self.version",
"flow-php/etl-adapter-logger": "self.version",
"flow-php/etl-adapter-logger-tools": "self.version",
"flow-php/etl-adapter-meilisearch": "self.version",
"flow-php/etl-adapter-parquet": "self.version",
"flow-php/etl-adapter-text": "self.version",
Expand Down
63 changes: 62 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ output/*
!output/.gitkep
compose.yml
var
.env
.env
9 changes: 0 additions & 9 deletions examples/autoload.php

This file was deleted.

71 changes: 71 additions & 0 deletions examples/clean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';

use function Flow\Filesystem\DSL\{fstab, path, protocol};
use Flow\ETL\Dataset\Statistics\HighResolutionTime;
use Symfony\Component\Console\Input\{ArgvInput, InputDefinition, InputOption};
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;

if ($_ENV['FLOW_PHAR_APP'] ?? false) {
print PHP_EOL . 'This script cannot be run in PHAR, please use CLI approach.' . PHP_EOL;

exit(1);
}

if (false === \in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
print PHP_EOL . 'This script may only be invoked from a command line, got "' . PHP_SAPI . '"' . PHP_EOL;

exit(1);
}

\ini_set('memory_limit', -1);

$finder = new Finder();
$finder->in(__DIR__ . '/topics')
->files()
->name('*.php');

$output = new ConsoleOutput();
$intput = new ArgvInput(definition: new InputDefinition(
[
new InputOption(name: 'composer-update', shortcut: 'u', mode: InputOption::VALUE_NONE),
new InputOption(name: 'composer-archive', shortcut: 'a', mode: InputOption::VALUE_NONE),
]
));
$style = new SymfonyStyle($intput, $output);
$style->setDecorated(true);

$style->title('Cleaning Flow PHP Examples');

$fs = fstab()->for(protocol('file'));

foreach ($finder as $file) {

if ($file->getBasename() !== 'code.php') {
continue;
}

$start = HighResolutionTime::now();

$style->info("Removing vendor and code archive: {$file->getRelativePathname()}");

$vendorPath = path($file->getPath() . '/vendor');

if ($fs->status($vendorPath)?->isDirectory()) {
$fs->rm(path($file->getPath() . '/vendor'));
}

$archiveZip = path($file->getPath() . '/flow_php_example.zip');

if ($fs->status($archiveZip)?->isFile()) {
$fs->rm($archiveZip);
}
}

$style->success('Vendor adn archive folders remove from all examples');
69 changes: 60 additions & 9 deletions examples/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

require __DIR__ . '/../vendor/autoload.php';

use Flow\ETL\Dataset\Statistics\HighResolutionTime;
use Symfony\Component\Console\Input\{ArgvInput, InputDefinition, InputOption};
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;

if ($_ENV['FLOW_PHAR_APP'] ?? false) {
Expand All @@ -21,23 +25,70 @@

\ini_set('memory_limit', -1);

print "Running all available examples.\n";

$finder = new Finder();
$finder->in(__DIR__ . '/topics')
->files()
->name('*.php');

$output = new ConsoleOutput();
$intput = new ArgvInput(definition: new InputDefinition(
[
new InputOption(name: 'composer-update', shortcut: 'u', mode: InputOption::VALUE_NONE),
new InputOption(name: 'composer-archive', shortcut: 'a', mode: InputOption::VALUE_NONE),
]
));
$style = new SymfonyStyle($intput, $output);
$style->setDecorated(true);

$style->title('Running Flow PHP Examples');

foreach ($finder as $file) {
print "\nExample: {$file->getRelativePathname()}\n";

try {
if ($file->getBasename() === 'code.php') {
include $file->getRealPath();
}
} catch (Exception $e) {
print "Example failed: {$e->getMessage()}\n";
if ($file->getBasename() !== 'code.php') {
continue;
}

$start = HighResolutionTime::now();

$style->info("Running example: {$file->getRelativePathname()}");

$style->note(($intput->getOption('composer-update') ? 'Updating' : 'Installing') . ' composer dependencies');
$composerProcess = new Symfony\Component\Process\Process(['composer', $intput->getOption('composer-update') ? 'update' : 'install'], $file->getPath());
$composerProcess->run();
$style->info('Composer install finished');

if (!$composerProcess->isSuccessful()) {
$style->error("Composer install failed: {$file->getPath()}");
$style->error("Details: {$composerProcess->getErrorOutput()}");

exit(1);
}

$codeProcess = new Symfony\Component\Process\Process(['php', $file->getRealPath()]);
$codeProcess->run();

if (!$codeProcess->isSuccessful()) {
$style->error("Example failed: {$file->getPath()}");
$style->error("Details: {$codeProcess->getOutput()}");

exit(1);
}
$end = HighResolutionTime::now();

$style->success('Example finished in ' . $start->diff($end)->toSeconds() . ' seconds');

if ($intput->getOption('composer-archive')) {
$style->note('Generating composer archive');
$composerProcess = new Symfony\Component\Process\Process(['composer', 'archive', '--format', 'zip', '--file', 'flow_php_example'], $file->getPath());
$composerProcess->run();

if (!$composerProcess->isSuccessful()) {
$style->error("Composer archive failed: {$file->getPath()}");
$style->error("Details: {$composerProcess->getErrorOutput()}");

exit(1);
}

$style->info('Composer archive generated');
}
}
2 changes: 1 addition & 1 deletion examples/topics/aggregations/average/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use function Flow\ETL\DSL\{average, data_frame, from_rows, int_entry, ref, row, rows, to_stream};

require __DIR__ . '/../../../autoload.php';
require __DIR__ . '/vendor/autoload.php';

data_frame()
->from(from_rows(rows(
Expand Down
15 changes: 15 additions & 0 deletions examples/topics/aggregations/average/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "flow-php/examples",
"description": "Flow PHP - Examples",
"license": "MIT",
"type": "library",
"require": {
"flow-php/etl": "1.x-dev"
},
"archive": {
"exclude": [
".env",
"vendor"
]
}
}
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/topics/aggregations/first/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use function Flow\ETL\DSL\{data_frame, first, from_rows, int_entry, ref, row, rows, to_stream};

require __DIR__ . '/../../../autoload.php';
require __DIR__ . '/vendor/autoload.php';

data_frame()
->from(from_rows(rows(
Expand Down
15 changes: 15 additions & 0 deletions examples/topics/aggregations/first/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "flow-php/examples",
"description": "Flow PHP - Examples",
"license": "MIT",
"type": "library",
"require": {
"flow-php/etl": "1.x-dev"
},
"archive": {
"exclude": [
".env",
"vendor"
]
}
}
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/topics/aggregations/group_by/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use function Flow\ETL\DSL\{count, data_frame, from_array, ref, to_stream};

require __DIR__ . '/../../../autoload.php';
require __DIR__ . '/vendor/autoload.php';

data_frame()
->read(from_array([
Expand Down
15 changes: 15 additions & 0 deletions examples/topics/aggregations/group_by/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "flow-php/examples",
"description": "Flow PHP - Examples",
"license": "MIT",
"type": "library",
"require": {
"flow-php/etl": "1.x-dev"
},
"archive": {
"exclude": [
".env",
"vendor"
]
}
}
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/topics/aggregations/group_by_sum/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use function Flow\ETL\DSL\{data_frame, from_array, ref, sum, to_stream};

require __DIR__ . '/../../../autoload.php';
require __DIR__ . '/vendor/autoload.php';

data_frame()
->read(from_array([
Expand Down
Loading

0 comments on commit 464399b

Please sign in to comment.