Skip to content

Commit

Permalink
Merge 837ae9f into ae5aa22
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Apr 9, 2024
2 parents ae5aa22 + 837ae9f commit 3563303
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ jobs:
- name: 🔥 Quick Benchmark 🔥
run: |
make build --no-print-directory
make bench-create-csv --no-print-directory
make build > /dev/null 2>&1
make bench-create-csv > /dev/null
make bench-docker-quick --no-print-directory
- name: Push Docker Image (master)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ build
vendor
phpunit.xml
/docker/preload.php
/docker/random_data.csv
*.cache
*.phar
.version
44 changes: 28 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,45 @@ RUN install-php-extensions opcache @composer

# Install application
# run `make build-version` before!
WORKDIR /app
ENV COMPOSER_ALLOW_SUPERUSER=1
COPY . /app
COPY --from=preparatory /tmp/.version /app/.version
RUN cd /app \
&& composer install --no-dev \
RUN composer install --no-dev \
--classmap-authoritative \
--no-progress \
--no-suggest \
--optimize-autoloader \
&& rm -rf /app/.git \
&& rm -rf ./.git \
&& composer clear-cache \
&& chmod +x /app/csv-blueprint
&& chmod +x ./csv-blueprint

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY ./docker/php.ini /usr/local/etc/php/conf.d/docker-z99-php.ini

# Prepare opcode caches
RUN php /app/docker/build-preloader.php \
&& php /app/docker/preload.php
# && echo "opcache.preload=/app/docker/preload.php" >> /usr/local/etc/php/conf.d/docker-z99-php.ini

# Test and warm up caches
RUN time /app/csv-blueprint validate:csv -h \
&& time /app/csv-blueprint validate:schema \
--schema=/app/schema-examples/*.yml \
--schema=/app/schema-examples/*.php \
--schema=/app/schema-examples/*.json -vvv \
&& du -sh /app/docker
# Quick test
RUN time ./csv-blueprint --version --ansi \
&& time ./csv-blueprint validate:csv --help --ansi

# Warm up caches
RUN time php /app/docker/build-preloader.php \
&& time php /app/docker/preload.php \
&& echo "opcache.preload=/app/docker/preload.php" >> /usr/local/etc/php/conf.d/docker-z99-php.ini
# && time /app/csv-blueprint validate:csv -h \
# && time /app/csv-blueprint validate:schema \
# --schema=/app/schema-examples/*.yml \
# --schema=/app/schema-examples/*.php \
# --schema=/app/schema-examples/*.json -vvv \
# && echo "Warm up is ready!" \

#RUN time php /app/docker/random-csv.php \
# && time /app/csv-blueprint validate:csv \
# --schema=/app/schema-examples/full.yml \
# --csv=/app/docker/random_data.csv \
# --apply-all=yes \
# --report=text --mute-errors > /dev/null \
# && echo "Tests are ready!" \
# && rm /app/docker/random_data.csv \
# && du -sh /app/docker

ENTRYPOINT ["/app/csv-blueprint"]
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ presets: # Include another schema and define an a
# This allows you to pre-validate the file name before processing its contents.
# Feel free to check parent directories as well.
# See: https://www.php.net/manual/en/reference.pcre.pattern.syntax.php
filename_pattern: /demo(-\d+)?\.csv$/i
filename_pattern: /\.csv$/i
# preset: my-preset # See README.md for details.

# Here are default values to parse CSV file.
Expand Down Expand Up @@ -519,12 +519,12 @@ columns:
# Validates whether the input is a country code in ISO 3166-1 standard.
# Available options: "alpha-2" (Ex: "US"), "alpha-3" (Ex: "USA"), "numeric" (Ex: "840").
# The rule uses data from iso-codes: https://salsa.debian.org/iso-codes-team/iso-codes.
is_country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"
country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"

# Validates whether the input is language code based on ISO 639.
# Available options: "alpha-2" (Ex: "en"), "alpha-3" (Ex: "eng").
# See: https://en.wikipedia.org/wiki/ISO_639.
is_language_code: alpha-2 # Examples: "en", "eng"
language_code: alpha-2 # Examples: "en", "eng"

# Filesystem (with IO!)
is_file_exists: true # Check if file exists on the filesystem (It's FS IO operation!).
Expand Down Expand Up @@ -908,9 +908,11 @@ columns:
rules:
not_empty: true

- name: third_column
rules:
not_empty: true
- name: inherited_column_login
preset: my-preset/login

- name: inherited_column_full_name
preset: my-preset/full_name
```
<!-- auto-update:/full-yml -->

Expand Down
21 changes: 9 additions & 12 deletions docker/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ opcache.enable_cli = 1
opcache.interned_strings_buffer = 32
opcache.max_accelerated_files = 10000
opcache.fast_shutdown = 1

; Save opcache data as files on disk
opcache.memory_consumption = 0
opcache.memory_consumption = 100
opcache.save_comments = 1
opcache.lockfile_path = /app/docker/opcache.lock
opcache.file_cache = /app/docker/
opcache.file_cache_only = 1
opcache.jit_buffer_size=100M
opcache.jit=1255

; Experimantal for really quick script start.
; Save opcache data as files on disk inside the Docker image
;opcache.lockfile_path = /app/docker/opcache.lock
;opcache.file_cache = /app/docker/
;opcache.file_cache_only = 1

; Enable aggressive opcache optimization
opcache.validate_timestamps = 0
Expand All @@ -35,12 +38,6 @@ opcache.validate_permission = 0
opcache.validate_root = 0
opcache.enable_file_override = 0


; JIT
opcache.jit_buffer_size=100M
opcache.jit=1205


; Base limits
max_execution_time=1200
max_input_time=60
Expand Down
42 changes: 42 additions & 0 deletions docker/random-csv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* JBZoo Toolbox - Csv-Blueprint.
*
* This file is part of the JBZoo Toolbox project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @see https://github.com/JBZoo/Csv-Blueprint
*/

declare(strict_types=1);

$rows = 1000;

$filePath = __DIR__ . '/random_data.csv';

$fileHandle = \fopen($filePath, 'w');

if ($fileHandle === false) {
exit('Error opening the file');
}

$columns = ['Column Name (header)', 'another_column', 'inherited_column_login', 'inherited_column_full_name'];
\fputcsv($fileHandle, $columns);

for ($i = 0; $i < $rows; $i++) {
$rowData = [];

for ($j = 0; $j < \count($columns); $j++) {
$rowData[] = \random_int(1, 10000);
}

\fputcsv($fileHandle, $rowData);
}

\fclose($fileHandle);

echo "CSV file created: {$filePath}.\n";
14 changes: 9 additions & 5 deletions schema-examples/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"my-preset" : ".\/preset_users.yml"
},

"filename_pattern" : "\/demo(-\\d+)?\\.csv$\/i",
"filename_pattern" : "\/\\.csv$\/i",

"csv" : {
"preset" : "my-preset",
Expand Down Expand Up @@ -148,8 +148,8 @@
"is_cardinal_direction" : true,
"is_usa_market_name" : true,

"is_country_code" : "alpha-2",
"is_language_code" : "alpha-2",
"country_code" : "alpha-2",
"language_code" : "alpha-2",

"is_file_exists" : true,
"is_dir_exists" : true,
Expand Down Expand Up @@ -429,8 +429,12 @@
"rules" : {"not_empty" : true}
},
{
"name" : "third_column",
"rules" : {"not_empty" : true}
"name" : "inherited_column_login",
"preset" : "my-preset\/login"
},
{
"name" : "inherited_column_full_name",
"preset" : "my-preset\/full_name"
}
]
}
14 changes: 9 additions & 5 deletions schema-examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'my-preset' => './preset_users.yml',
],

'filename_pattern' => '/demo(-\\d+)?\\.csv$/i',
'filename_pattern' => '/\\.csv$/i',

'csv' => [
'preset' => 'my-preset',
Expand Down Expand Up @@ -169,8 +169,8 @@
'is_cardinal_direction' => true,
'is_usa_market_name' => true,

'is_country_code' => 'alpha-2',
'is_language_code' => 'alpha-2',
'country_code' => 'alpha-2',
'language_code' => 'alpha-2',

'is_file_exists' => true,
'is_dir_exists' => true,
Expand Down Expand Up @@ -452,8 +452,12 @@
'rules' => ['not_empty' => true],
],
[
'name' => 'third_column',
'rules' => ['not_empty' => true],
'name' => 'inherited_column_login',
'preset' => 'my-preset/login',
],
[
'name' => 'inherited_column_full_name',
'preset' => 'my-preset/full_name',
],
],
];
14 changes: 8 additions & 6 deletions schema-examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ presets: # Include another schema and define an a
# This allows you to pre-validate the file name before processing its contents.
# Feel free to check parent directories as well.
# See: https://www.php.net/manual/en/reference.pcre.pattern.syntax.php
filename_pattern: /demo(-\d+)?\.csv$/i
filename_pattern: /\.csv$/i
# preset: my-preset # See README.md for details.

# Here are default values to parse CSV file.
Expand Down Expand Up @@ -230,12 +230,12 @@ columns:
# Validates whether the input is a country code in ISO 3166-1 standard.
# Available options: "alpha-2" (Ex: "US"), "alpha-3" (Ex: "USA"), "numeric" (Ex: "840").
# The rule uses data from iso-codes: https://salsa.debian.org/iso-codes-team/iso-codes.
is_country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"
country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"

# Validates whether the input is language code based on ISO 639.
# Available options: "alpha-2" (Ex: "en"), "alpha-3" (Ex: "eng").
# See: https://en.wikipedia.org/wiki/ISO_639.
is_language_code: alpha-2 # Examples: "en", "eng"
language_code: alpha-2 # Examples: "en", "eng"

# Filesystem (with IO!)
is_file_exists: true # Check if file exists on the filesystem (It's FS IO operation!).
Expand Down Expand Up @@ -619,6 +619,8 @@ columns:
rules:
not_empty: true

- name: third_column
rules:
not_empty: true
- name: inherited_column_login
preset: my-preset/login

- name: inherited_column_full_name
preset: my-preset/full_name
14 changes: 8 additions & 6 deletions schema-examples/full_clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ description: |
presets:
my-preset: ./preset_users.yml

filename_pattern: '/demo(-\d+)?\.csv$/i'
filename_pattern: /\.csv$/i

csv:
preset: my-preset
Expand Down Expand Up @@ -162,8 +162,8 @@ columns:
is_geohash: true
is_cardinal_direction: true
is_usa_market_name: true
is_country_code: alpha-2
is_language_code: alpha-2
country_code: alpha-2
language_code: alpha-2

is_file_exists: true
is_dir_exists: true
Expand Down Expand Up @@ -442,6 +442,8 @@ columns:
rules:
not_empty: true

- name: third_column
rules:
not_empty: true
- name: inherited_column_login
preset: my-preset/login

- name: inherited_column_full_name
preset: my-preset/full_name
7 changes: 7 additions & 0 deletions src/Commands/AbstractValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ protected function findFiles(string $option, bool $throwException = true): array
$patterns = $this->getOptArray($option);
$filenames = \array_values(Utils::findFiles($patterns));

// Hackish. Clear cache for schema files because we have aggressive opcode caching.
if ($option === 'schema') {
foreach ($filenames as $filename) {
\opcache_invalidate((string)$filename->getRealPath(), true);
}
}

if ($throwException && \count($filenames) === 0) {
throw new Exception('File(s) not found: ' . Utils::printList($patterns));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Respect\Validation\Rules\CountryCode as RespectCountryCode;
use Respect\Validation\Validator;

class IsCountryCode extends AbstractCellRule
class CountryCode extends AbstractCellRule
{
public function getHelpMeta(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Respect\Validation\Rules\LanguageCode as RespectLanguageCode;
use Respect\Validation\Validator;

class IsLanguageCode extends AbstractCellRule
class LanguageCode extends AbstractCellRule
{
public function getHelpMeta(): array
{
Expand Down
Loading

0 comments on commit 3563303

Please sign in to comment.