### Build and Install Commands (Bash) Source: https://github.com/jbzoo/csv-blueprint/blob/master/CLAUDE.md Commands for building and installing project dependencies in development or production modes, and for creating a standalone PHAR executable. These commands are part of the project's Makefile. ```bash make build # Install dependencies in development mode make build-prod # Install dependencies in production mode make build-phar-file # Build standalone PHAR executable ``` -------------------------------- ### Install CSV Blueprint via Composer Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This snippet demonstrates installing the CSV Blueprint project using Composer. It includes creating the project, navigating into the directory, and then using the installed tool to validate a CSV file against a schema. The --no-dev flag is optional and excludes development dependencies. ```bash composer create-project --no-dev jbzoo/csv-blueprint cd ./csv-blueprint ./csv-blueprint validate-csv \ --csv=./tests/fixtures/demo.csv \ --schema=./tests/schemas/demo_invalid.yml ``` -------------------------------- ### CSV Blueprint YAML Syntax Example Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This YAML example illustrates a complete list of preset features available in CSV Blueprint. It demonstrates how to define schemas, use aliases for presets, specify filename patterns, structural rules, and configure columns with options like presets, rules, and aggregate rules. Dependencies include the YAML parser. ```yaml name: Complite list of preset features description: This schema contains all the features of the presets. presets: # The basepath for the preset is `.` (current directory of the current schema file). # Define alias "db" for schema in `./preset_database.yml`. db: preset_database.yml # Or `db: ./preset_database.yml`. It's up to you. # For example, you can use a relative path. users: ./../schema-examples/preset_users.yml # Or you can use an absolute path. # db: /full/path/preset_database.yml filename_pattern: { preset: users } # Take the filename pattern from the preset. structural_rules: { preset: users } # Take the global rules from the preset. csv: { preset: users } # Take the CSV settings from the preset. columns: # Use name of column from the preset. # "db" is alias. "id" is column `name` in `preset_database.yml`. - preset: 'db/id' # Use column index. "db" is alias. "0" is column index in `preset_database.yml`. - preset: 'db/0' - preset: 'db/0:' # Use column index and column name. It useful if column name is not unique. - preset: 'db/0:id' # Use only `rules` of "status" column from the preset. - name: My column rules: preset: 'db/status' # Override only `aggregate_rules` from the preset. # Use only `aggregate_rules` of "id" column from the preset. # We strictly take only the very first column (index = 0). - name: My column aggregate_rules: preset: 'db/0:id' # Combo!!! If you're a risk-taker or have a high level of inner zen. :) # Creating a column from three other columns. # In fact, it will merge all three at once with key replacement. - name: Crazy combo! description: > # Just a great advice. I like to take risks, too. Be careful. Use your power wisely. example: ~ # Ignore inherited "example" value. Set it `null`. preset: 'users/login' rules: preset: 'users/email' not_empty: true # Disable the rule from the preset. aggregate_rules: preset: 'db/0' ``` -------------------------------- ### Full Example Schema in YAML (with comments) Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This YAML snippet provides a comprehensive example of a CSV schema file for the CSV Blueprint tool, including comments to explain various sections and options. It demonstrates meta-information, preset inclusion, filename patterns, CSV formatting, and detailed column validation rules. ```yaml # It's a complete example of the CSV schema file in YAML format. # See copy of the file without comments here ./schema-examples/full_clean.yml # Just meta name: CSV Blueprint Schema Example # Name of a CSV file. Not used in the validation process. description: | # Any description of the CSV file. Not used in the validation process. This YAML file provides a detailed description and validation rules for CSV files to be processed by CSV Blueprint tool. It includes specifications for file name patterns, CSV formatting options, and extensive validation criteria for individual columns and their values, supporting a wide range of data validation rules from basic type checks to complex regex validations. This example serves as a comprehensive guide for creating robust CSV file validations. # Include another schema and define an alias for it. presets: my-preset: ./preset_users.yml # Define preset alias "my-preset". See README.md for details. ``` -------------------------------- ### Preset Inheritance Chain Example Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Illustrates the concept of creating a long chain of inheritance for presets, allowing `grandparent.yml` -> `parent.yml` -> `child.yml` -> `grandchild.yml`. This highlights the flexibility but warns against circular dependencies. ```Markdown - You can make the chain of inheritance infinitely long. I.e. make chains of the form `grant-parent.yml` -> `parent.yml` -> `child.yml` -> `grandchild.yml` -> etc. Of course if you like to take risks ;). - But be careful with circular dependencies. The tool will not be able to handle them, and it can be an infinite loop. ``` -------------------------------- ### Download and Run CSV Blueprint PHAR Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This snippet shows how to download the latest CSV Blueprint PHAR archive, make it executable, and then use it to validate a CSV file against a schema. It is a straightforward way to get started with the tool. ```bash wget https://github.com/jbzoo/csv-blueprint/releases/latest/download/csv-blueprint.phar chmod +x ./csv-blueprint.phar ./csv-blueprint.phar validate-csv \ --csv=./tests/fixtures/demo.csv \ --schema=./tests/schemas/demo_invalid.yml ``` -------------------------------- ### Build Project Dependencies and Docker Image Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md These shell commands are used to build the project's dependencies, including the benchmark tool, and optionally a Docker image for local testing. 'make build' installs PHP dependencies, 'make build-phar-file' creates a PHAR archive, and 'make docker-build' creates a Docker image tagged as 'jbzoo/csv-blueprint:local'. ```shell # Clone the latest version git clone git@github.com:jbzoo/csv-blueprint.git csv-blueprint cd csv-blueprint # Download dependencies and build the tool. make build # We need it to build benchmark tool. See `./tests/Benchmarks` folder. make build-phar-file # Optional. Only if you want to test it. make docker-build # Recommended. local tag is "jbzoo/csv-blueprint:local" ``` -------------------------------- ### YAML Schema for Usage of Presets Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This YAML demonstrates how to use presets defined in other schema files. By referencing presets, you can create a modular and maintainable schema structure, avoiding repetition and promoting consistency across different parts of your project's data validation. This example is a placeholder showing the intent of using presets. ```yaml # This is a placeholder for a schema that reuses other presets. # Actual content would define how to import and use the database and user presets. ``` -------------------------------- ### Example Schema Structure (YAML) Source: https://github.com/jbzoo/csv-blueprint/blob/master/CLAUDE.md A YAML configuration defining the structure and rules for validating a CSV file. It includes patterns for filenames, column definitions with cell and aggregate rules, and specific rule parameters like length and uniqueness. ```yaml filename_pattern: /pattern\.csv$/ columns: - name: "Column Name" rules: not_empty: true length_min: 1 length_max: 100 aggregate_rules: is_unique: true count_min: 1 ``` -------------------------------- ### Debug CSV Blueprint Schema with CLI Command Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This snippet shows how to use the `debug-schema` command from the CSV Blueprint CLI to inspect the generated schema from a YAML configuration file. This is useful for understanding how presets are applied and for troubleshooting schema-related issues. It requires the CSV Blueprint CLI to be installed and a schema file to be provided. ```shell ./csv-blueprint debug-schema -s ./your/schema.yml ``` -------------------------------- ### Example CSV Validation Schema in YAML Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This YAML snippet defines a schema for validating CSV files. It includes metadata like name and filename pattern, CSV specific settings like delimiter, and detailed column definitions with validation rules for 'id' and 'name' columns. ```yaml name: Simple CSV Schema filename_pattern: /my-favorite-csv-\d+\.csv$/i csv: delimiter: ';' columns: - name: id rules: not_empty: true is_int: true aggregate_rules: is_unique: true sorted: [ asc, numeric ] - name: name rules: length_min: 3 aggregate_rules: count: 10 ``` -------------------------------- ### Build and Test Project Locally Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This snippet provides commands to clone the repository, build the project, make local changes, and run code style checks and tests. It's essential for contributing to the project. ```sh # Fork the repo and build project git clone git@github.com:jbzoo/csv-blueprint.git ./jbzoo-csv-blueprint cd ./jbzoo-csv-blueprint make build # Make your local changes # Autofix code style make test-phpcsfixer-fix test-phpcs # Run all tests and check code style make test make codestyle # Create your pull request and check all tests in CI (Github Actions) # ??? # Profit! ``` -------------------------------- ### Demo and Validation Commands (Bash) Source: https://github.com/jbzoo/csv-blueprint/blob/master/CLAUDE.md Commands for running a demo of the CSV Blueprint tool, performing specific CSV validations against a schema, and creating a schema file from an existing CSV. These demonstrate the core functionality of the CLI. ```bash # Run demo validation make demo # Validate specific CSV with schema ./csv-blueprint validate:csv --csv=path/to/file.csv --schema=path/to/schema.yml # Create schema from existing CSV ./csv-blueprint create-schema --csv=path/to/file.csv ``` -------------------------------- ### Run CSV Blueprint with Docker Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This snippet demonstrates how to pull the CSV Blueprint Docker image and run it to validate CSV files against a schema. It shows how to mount the current directory into the container for file access and specifies input CSV and schema files. It also includes instructions for building the Docker image from source. ```shell docker pull jbzoo/csv-blueprint:latest docker run --rm \ --workdir=/parent-host \ -v $(pwd):/parent-host \ jbzoo/csv-blueprint:latest \ validate-csv \ --csv=./tests/fixtures/demo.csv \ --schema=./tests/schemas/demo_invalid.yml \ --ansi # OR build it from source. git clone git@github.com:jbzoo/csv-blueprint.git csv-blueprint cd csv-blueprint make docker-build # local tag is "jbzoo/csv-blueprint:local" ``` -------------------------------- ### Shortcut for CSV Benchmark Execution Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This 'make bench' command provides a convenient shortcut to execute the full benchmark process, including CSV file creation and running the benchmark, typically using Docker by default. The BENCH_COLS variable can be used to specify the number of columns, defaulting to 10 if not set. ```shell # It's a shortcut that combines CSV file creation and Docker run. # By default BENCH_COLS=10 make bench ``` -------------------------------- ### Build CSV Blueprint from Source Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This snippet details how to build the CSV Blueprint tool from its source code. It involves cloning the repository, navigating into the directory, running the build command, and then using the compiled executable to validate a CSV file against a schema. ```bash git clone git@github.com:jbzoo/csv-blueprint.git csv-blueprint cd csv-blueprint make build ./csv-blueprint validate-csv \ --csv=./tests/fixtures/demo.csv \ --schema=./tests/schemas/demo_invalid.yml ``` -------------------------------- ### Column Inheritance with Presets Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Demonstrates how columns can inherit validation rules by referencing predefined presets like 'my-preset/login' and 'my-preset/full_name'. This promotes reusability and consistency. ```YAML name: inherited_column_login preset: my-preset/login - name: inherited_column_full_name preset: my-preset/full_name ``` -------------------------------- ### Docker Commands (Bash) Source: https://github.com/jbzoo/csv-blueprint/blob/master/CLAUDE.md Commands for managing the Docker environment, including building the Docker image, running a demo within Docker, and accessing an interactive Docker session. These facilitate containerized development and execution. ```bash # Build: `make docker-build` # Run: `make docker-demo` # Interactive: `make docker-in` ``` -------------------------------- ### Benchmarking Commands (Bash) Source: https://github.com/jbzoo/csv-blueprint/blob/master/CLAUDE.md Commands for executing the benchmark suite, running benchmarks within a Docker container, and generating test CSV files for performance testing. These are used to measure and optimize the tool's performance. ```bash make bench # Run full benchmark suite make bench-docker # Run benchmarks in Docker make bench-create-csv # Generate test CSV files ``` -------------------------------- ### Testing Commands (Bash) Source: https://github.com/jbzoo/csv-blueprint/blob/master/CLAUDE.md Commands for running PHPUnit tests, including running specific test files and generating code coverage reports. These are essential for verifying code integrity and performance. ```bash # Run PHPUnit tests ./vendor/bin/phpunit # Run specific test ./vendor/bin/phpunit tests/SpecificTest.php # Run with coverage ./vendor/bin/phpunit --coverage-html build/coverage_html ``` -------------------------------- ### Run CSV Benchmark with PHAR or PHP Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md These commands execute the CSV benchmark using either a locally built PHAR file or directly with PHP. Both methods require the CSV file to be created first. The BENCH_COLS variable controls the number of columns for the generated CSV. ```shell # Create random CSV files with 5 columns (max: 20). BENCH_COLS=5 make bench-create-csv # Run the benchmark for the recent CSV file. BENCH_COLS=5 make bench-phar BENCH_COLS=5 make bench-php ``` -------------------------------- ### Run CSV Benchmark with Docker Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This command runs the CSV benchmark using Docker, which is the recommended method. It requires the Docker image to be built first. The BENCH_COLS environment variable can be set to specify the number of columns in the CSV file to be generated and tested. ```shell # Create random CSV files with 5 columns (max: 20). BENCH_COLS=5 make bench-create-csv # Run the benchmark for the recent CSV file. BENCH_COLS=5 make bench-docker # Recommended ``` -------------------------------- ### CSV Blueprint Create Schema Command Options Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Options for the 'create-schema' command, which analyzes CSV files to suggest a schema. It supports specifying CSV file paths, header presence, lines to read, syntax checking, and report formats. ```bash # Analyze CSV files in a specific path ./csv-blueprint create-schema -c "p/file.csv" # Analyze multiple CSV files using a wildcard ./csv-blueprint create-schema -c "p/*.csv" # Analyze CSV files recursively up to 10 levels deep ./csv-blueprint create-schema -c "p/**/*.csv" # Force presence of a header row ./csv-blueprint create-schema -H # Set number of lines to read for parameter detection ./csv-blueprint create-schema -L 50000 # Disable syntax check for the suggested schema ./csv-blueprint create-schema -C no # Set report output format to 'text' ./csv-blueprint create-schema -r text # Set report output format to 'github' ./csv-blueprint create-schema -r github # Dump schema after creation ./csv-blueprint create-schema --dump-schema # Enable debug mode for detailed process insights ./csv-blueprint create-schema --debug # Launch process in parallel mode (experimental, requires ext-parallel) ./csv-blueprint create-schema --parallel=yes ``` -------------------------------- ### CSV Blueprint CLI Global Options Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Global options that can be applied to most CSV Blueprint CLI commands. These control output verbosity, interaction, and display settings. ```bash # Silent mode: Do not output any message ./csv-blueprint --silent # Quiet mode: Only errors are displayed ./csv-blueprint -q # Display version ./csv-blueprint -V # Force ANSI output ./csv-blueprint --ansi # Disable ANSI output ./csv-blueprint --no-ansi # Do not ask any interactive question ./csv-blueprint -n # Increase verbosity (normal) ./csv-blueprint -v # Increase verbosity (more verbose) ./csv-blueprint -vv # Increase verbosity (debug) ./csv-blueprint -vvv ``` -------------------------------- ### Preset Validation Notes Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Provides important notes regarding preset validation, including self-validation of schemas with presets, the isolation of rule checking, and the regex pattern for aliases. ```Markdown - Schemas with presets validate themselves and if there are any obvious issues, you will see them when you try to use the schema. But logical conflicts between rules are not checked (It's almost impossible from a code perspective). As mentioned above, rules work in isolation and are not aware of each other. So the set of rules is your responsibility as always. - Alias in presets must match the regex pattern `/^[a-z0-9-_]+$/i`. Otherwise, it might break the syntax. ``` -------------------------------- ### YAML Schema for User Data Presets Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This YAML defines common presets for user data, including rules for login, password, full name, email, birthday, phone number, balance, and short description. It demonstrates various validation types such as `is_lowercase`, `is_password_safe_chars`, `date_format`, `phone`, and `precision`. This preset can be extended or reused in other schemas. ```yaml name: Common presets for user data description: > This schema contains common presets for user data. It can be used as a base for other schemas. filename_pattern: /users-.*\.csv$/i csv: delimiter: ';' columns: - name: login description: User's login name example: johndoe rules: not_empty: true is_trimmed: true is_lowercase: true is_slug: true length_min: 3 length_max: 20 is_alnum: true aggregate_rules: is_unique: true - name: password description: User's password example: '9RfzENKD' rules: not_empty: true is_trimmed: true is_password_safe_chars: true password_strength_min: 7 contains_none: [ "password", "123456", "qwerty", " " ] charset: UTF-8 length_min: 6 length_max: 20 - name: full_name description: User's full name example: 'John Doe Smith' rules: not_empty: true is_trimmed: true charset: UTF-8 contains: " " word_count_min: 2 word_count_max: 8 is_capitalize: true aggregate_rules: is_unique: true - name: email description: User's email address example: user@example.com rules: not_empty: true is_trimmed: true is_email: true is_lowercase: true aggregate_rules: is_unique: true - name: birthday description: Validates the user's birthday. example: '1990-01-01' rules: not_empty: true # The birthday field must not be empty. is_trimmed: true # Trims the value before validation. date_format: Y-m-d # Checks if the date matches the YYYY-MM-DD format. is_date: true # Validates if the value is a valid date. date_age_greater: 0 # Ensures the date is in the past. date_age_less: 150 # Ensures the user is not older than 150 years. date_max: now # Ensures the date is not in the future. - name: phone_number description: User's phone number in US example: '+1 650 253 00 00' rules: not_empty: true is_trimmed: true starts_with: '+1' phone: US - name: balance description: User's balance in USD example: '100.00' rules: not_empty: true is_trimmed: true is_float: true num_min: 0.00 num_max: 1000000000.00 # 1 billion is max amount in our system. precision: 2 - name: short_description description: A brief description of the item example: 'Lorem ipsum dolor sit amet' rules: not_empty: true contains: " " length_max: 255 is_trimmed: true ``` -------------------------------- ### CSV Blueprint Dump Schema Command Help Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Displays help information for the 'dump-schema' command. This command is used to output the internal representation of the schema. ```bash # Display help for dump-schema command ./csv-blueprint dump-schema --help ``` -------------------------------- ### Code Quality Tools (Bash) Source: https://github.com/jbzoo/csv-blueprint/blob/master/CLAUDE.md Commands to maintain code quality using static analysis tools like Psalm and Phan, and code style checkers/fixers like PHP CS Fixer. These commands help ensure code consistency and identify potential issues early. ```bash # Static analysis with Psalm ./vendor/bin/psalm # Code style check ./vendor/bin/php-cs-fixer fix --dry-run # Code style fix ./vendor/bin/php-cs-fixer fix # Phan static analysis ./vendor/bin/phan ``` -------------------------------- ### Preset Usage: Reusability and Standardization Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Explains how presets significantly enhance efficiency and reusability of schema definitions in CSV validation, ensuring consistency across files for fields like user IDs and email addresses. ```Markdown Presets significantly enhance the efficiency and reusability of schema definitions in CSV file validation by ensuring consistency across various files with common validation rules for fields like user IDs and email addresses. This uniformity maintains data integrity and simplifies maintenance by allowing centralized updates that automatically apply to all linked schemas. Moreover, presets support customization through field-specific rule overrides, facilitating both standardization and specific needs adaptation. ``` -------------------------------- ### Generate CSV Files with PHP Faker Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This script uses PHP Faker to generate initial CSV data. It serves as the foundation for creating larger benchmark files by producing the first 2000 lines. The script is part of the benchmark testing suite. ```php setDelimiter(","); $writer->setEnclosure("\""); $writer->setEscape("\\"); $writer->setEncoding("UTF-8"); $faker = Factory::create('en_US'); // Define headers based on expected columns $headers = ['id', 'bool_int', 'bool_str', 'number', 'float', 'date', 'datetime', 'domain', 'email', 'ip4', 'uuid', 'address', 'postcode', 'latitude', 'longitude', 'ip6', 'sentence_tiny', 'sentence_small', 'sentence_medium', 'sentence_huge']; $writer->insertOne($headers); // Generate data for 2000 lines for ($i = 1; $i <= 2000; $i++) { $rowData = [ $i, $faker->boolean(50) ? 1 : 0, $faker->boolean(50) ? 'true' : 'false', $faker->randomNumber(6), $faker->randomFloat(11, 100000, 1000000), $faker->date('Y-m-d'), $faker->dateTimeBetween('-30 years', 'now')->format('Y-m-d H:i:s'), $faker->domainName, $faker->email, $faker->ipv4, $faker->uuid, $faker->address, $faker->postcode, $faker->latitude, $faker->longitude, $faker->ipv6, $faker->realText(10), $faker->realText(30), $faker->realText(60), $faker->realText(200) ]; $writer->insertOne($rowData); } // Output the CSV content (e.g., to a file or stdout) // For actual file generation, you would redirect this output. // echo $writer->getContent(); // Example of writing to a file: // $outputFile = 'benchmark_test.csv'; // file_put_contents($outputFile, $writer->getContent()); // echo "Generated CSV file: " . $outputFile . "\n"; ``` -------------------------------- ### CSV Blueprint Debug Schema Command Options Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Provides detailed options for the 'debug-schema' command, which shows the internal schema representation. Options include specifying schema files, hiding defaults, disabling progress bars, muting errors, and selecting output modes. ```bash # Specify schema file (YAML) ./csv-blueprint debug-schema --schema "/full/path/name.yml" # Specify schema file (JSON) ./csv-blueprint debug-schema --schema "p/file.json" # Hide default values ./csv-blueprint debug-schema -d # Disable progress bar ./csv-blueprint debug-schema --no-progress # Mute all errors ./csv-blueprint debug-schema --mute-errors # Use StdOut for error messages ./csv-blueprint debug-schema --stdout-only # Non-zero exit code on any error message ./csv-blueprint debug-schema --non-zero-on-error # Show timestamp in messages ./csv-blueprint debug-schema --timestamp # Display timing and memory usage ./csv-blueprint debug-schema --profile # Set output mode to 'text' (default) ./csv-blueprint debug-schema --output-mode=text # Set output mode to 'cron' for crontab ./csv-blueprint debug-schema --output-mode=cron # Set output mode to 'logstash' for ELK integration ./csv-blueprint debug-schema --output-mode=logstash # Alias for --output-mode=cron (deprecated) ./csv-blueprint debug-schema --cron # Display help for debug-schema command ./csv-blueprint debug-schema -h ``` -------------------------------- ### Replicate CSV Content with Shell Script Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This shell script replicates the content of an existing CSV file multiple times to create larger benchmark files. It's a quick way to scale up the dataset for performance testing. ```shell #!/bin/bash # Define the input CSV file and the number of times to replicate INPUT_CSV="./tests/Benchmarks/benchmark_test.csv" REPLICATIONS=1000 # Check if the input file exists if [ ! -f "$INPUT_CSV" ]; then echo "Error: Input CSV file '$INPUT_CSV' not found." exit 1 fi # Get the header and the rest of the content separately HEADER=$(head -n 1 "$INPUT_CSV") CONTENT=$(tail -n +2 "$INPUT_CSV") # Create a new file for the replicated content OUTPUT_CSV="./tests/Benchmarks/large_benchmark.csv" # Write the header to the output file echo "$HEADER" > "$OUTPUT_CSV" # Append the content the specified number of times for ((i=0; i> "$OUTPUT_CSV" done echo "Successfully replicated '$INPUT_CSV' $REPLICATIONS times into '$OUTPUT_CSV'." ``` -------------------------------- ### Configure CSV Blueprint GitHub Action Workflow Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This YAML snippet configures a GitHub Actions workflow to use the CSV Blueprint action. It specifies inputs for CSV files, schema files, report format, and various other options like 'apply-all', 'quick', 'skip-schema', and 'extra' parameters for fine-grained control over the validation process. ```yaml - uses: jbzoo/csv-blueprint@master # See the specific version on releases page. `@master` is latest. with: # Specify the path(s) to the CSV files you want to validate. # This can include a direct path to a file or a directory to search with a maximum depth of 10 levels. # Examples: p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv csv: './tests/**/*.csv' # Specify the path(s) to the schema file(s), supporting YAML, JSON, or PHP formats. # Similar to CSV paths, you can direct to specific files or search directories with glob patterns. # Examples: p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml schema: './tests/**/*.yml' # Report format. Available options: text, table, github, gitlab, teamcity, junit. # Default value: 'table' report: 'table' # Apply all schemas (also without `filename_pattern`) to all CSV files found as global rules. # Available options: # auto: If no glob pattern (*) is used for --schema, the schema is applied to all found CSV files. # yes: Apply all schemas to all CSV files, Schemas without `filename_pattern` are applied as a global rule. # no: Apply only schemas with not empty `filename_pattern` and match the CSV files. # Default value: 'auto' apply-all: 'auto' # Quick mode. It will not validate all rows. It will stop after the first error. # Default value: 'no' quick: 'no' # Skip schema validation. If you are sure that the schema is correct, you can skip this check. # Default value: 'no' skip-schema: 'no' # Extra options for the CSV Blueprint. Only for debugging and profiling. # Available options: # Add flag `--parallel` if you want to validate CSV files in parallel. # Add flag `--dump-schema` if you want to see the final schema after all includes and inheritance. # Add flag `--debug` if you want to see more really deep details. # Add flag `--profile` if you want to see profiling info. Add details with `-vvv`. # Verbosity level: Available options: `-v`, `-vv`, `-vvv` # ANSI output. You can disable ANSI colors if you want with `--no-ansi`. # Default value: 'options: --ansi' # You can skip it. extra: 'options: --ansi' ``` -------------------------------- ### CSV Validation Command Help Message Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This section displays the detailed help message for the 'validate-csv' command. It outlines the command's purpose, usage, and all available options for configuring CSV file validation, including schema paths, error handling, and report generation. ```txt Description: Validate CSV file(s) by schema(s). Usage: validate-csv [options] validate:csv Options: -c, --csv=CSV Specify the path(s) to the CSV files you want to validate. This can include a direct path to a file or a directory to search with a maximum depth of 10 levels. Examples: p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv (multiple values allowed) -s, --schema=SCHEMA Specify the path(s) to the schema file(s), supporting YAML, JSON, or PHP formats. Similar to CSV paths, you can direct to specific files or search directories with glob patterns. Examples: p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml (multiple values allowed) -S, --skip-schema[=SKIP-SCHEMA] Skips schema validation for quicker checks when the schema's correctness is certain. Use any non-empty value or "yes" to activate [default: "no"] -a, --apply-all[=APPLY-ALL] Apply all schemas (also without `filename_pattern`) to all CSV files found as global rules. Available options: - auto: If no glob pattern (*) is used for --schema, the schema is applied to all found CSV files. - yes|y|1: Apply all schemas to all CSV files, Schemas without `filename_pattern` are applied as a global rule. - no|n|0: Apply only schemas with not empty `filename_pattern` and match the CSV files. Note. If specify the option `--apply-all` without value, it will be treated as "yes". [default: "auto"] -Q, --quick[=QUICK] Stops the validation process upon encountering the first error, accelerating the check but limiting error visibility. Returns a non-zero exit code if any error is detected. Enable by setting to any non-empty value or "yes". [default: "no"] -r, --report=REPORT Determines the report's output format. Available options: text, table, github, gitlab, teamcity, junit [default: "table"] --dump-schema Dumps the schema of the CSV file if you want to see the final schema after inheritance. --debug Intended solely for debugging and advanced profiling purposes. Activating this option provides detailed process insights, useful for troubleshooting and performance analysis. --parallel[=PARALLEL] EXPERIMENTAL! Launches the process in parallel mode (if possible). Works only with ext-parallel. You can specify the number of threads. If you do not specify a value, the number of threads will be equal to the number of CPU cores. By default, the process is launched in a single-threaded mode. [default: "1"] --no-progress Disable progress bar animation for logs. It will be used only for text output format. --mute-errors Mute any sort of errors. So exit code will be always "0" (if it's possible). It has major priority then --non-zero-on-error. It's on your own risk! --stdout-only For any errors messages application will use StdOut instead of StdErr. It's on your own risk! --non-zero-on-error None-zero exit code on any StdErr message. --timestamp Show timestamp at the beginning of each message.It will be used only for text output format. --profile Display timing and memory usage information. ``` -------------------------------- ### Filesystem Existence Checks Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Performs IO operations to check if a file or directory exists on the filesystem. These are explicit IO operations. ```yaml is_file_exists: true # Check if file exists on the filesystem (It's FS IO operation!). is_dir_exists: true # Check if directory exists on the filesystem (It's FS IO operation!). ``` -------------------------------- ### YAML Schema for Database Column Presets Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This YAML defines a set of reusable rules for database column data. It includes common validation checks like `not_empty`, `is_int`, `is_unique`, and `sorted` for an 'id' column, and `allow_values` for a 'status' column. This preset can be imported into other schemas to ensure consistency. ```yaml name: Presets for database columns description: This schema contains basic rules for database user data. columns: - name: id description: Unique identifier, usually used to denote a primary key in databases. example: 12345 extra: custom_key: custom value rules: not_empty: true is_trimmed: true is_int: true num_min: 1 aggregate_rules: is_unique: true sorted: [ asc, numeric ] - name: status description: Status in database example: active rules: not_empty: true allow_values: [ active, inactive, pending, deleted ] ``` -------------------------------- ### Interquartile Mean Rules Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Defines rules for the Interquartile Mean (IQM), a measure of central tendency based on the truncated mean of the interquartile range. It includes constraints for minimum, maximum, exact, and inequality values, noting its potential slowness. ```YAML interquartile_mean_min: 1.0 # x >= 1.0 interquartile_mean_greater: 2.0 # x > 2.0 interquartile_mean_not: 5.0 # x != 5.0 interquartile_mean: 7.0 # x == 7.0 interquartile_mean_less: 8.0 # x < 8.0 interquartile_mean_max: 9.0 # x <= 9.0 ``` -------------------------------- ### Extra Checks: Column Name Requirement Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Ensures that the `name` property is defined for each column. This check is applicable only when `csv.header` is set to `true`, guaranteeing header integrity. ```Markdown - Ensures that the `name` property is defined for each column, applicable only when `csv.header` is set to `true`, to guarantee header integrity. ``` -------------------------------- ### Extra Checks: Filename Pattern Validation Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Verifies that the CSV file's name adheres to a specified regular expression pattern, enforcing naming conventions. ```Markdown - The `filename_pattern` rule verifies that the file name adheres to the specified regex pattern, ensuring file naming conventions are followed. ``` -------------------------------- ### Basic Column Rule: Not Empty Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md A fundamental rule for a CSV column, ensuring that the specified column must not be empty. ```YAML name: another_column rules: not_empty: true ``` -------------------------------- ### Validate Hash Algorithms Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md This rule validates if a given string matches the format of a supported hash algorithm. It supports a wide array of hashing algorithms including MD5, SHA variants, CRC32, FNV, MurmurHash, xxHash, and more. The `hash` rule requires specifying the algorithm to be used for validation. ```yaml hash: set_algo # Example: "1234567890abcdef". ``` -------------------------------- ### Apply Aggregate Rules to Column Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md These rules apply data validation to an entire column rather than individual values. They include checking for unique values (`is_unique`), verifying sorting order (`sorted`), and setting constraints on the first numerical value (`first_num_*`) or the first/N-th string value (`first`, `first_not`). Presets can also be applied for complex rule sets. ```yaml aggregate_rules: preset: my-preset/login # Add preset aggregate rules for the column. See README.md for details. is_unique: true # All values in the column are unique. # Check if the column is sorted in a specific order. # - Direction: ["asc", "desc"]. # - Method: ["numeric", "string", "natural", "regular"]. # See: https://www.php.net/manual/en/function.sort.php sorted: [ asc, natural ] # Expected ascending order, natural sorting. # First number in the column. Expected value is float or integer. first_num_min: 1.0 # x >= 1.0 first_num_greater: 2.0 # x > 2.0 first_num_not: 5.0 # x != 5.0 first_num: 7.0 # x == 7.0 first_num_less: 8.0 # x < 8.0 first_num_max: 9.0 # x <= 9.0 first: Expected # First value in the column. Will be compared as strings. first_not: Not expected # Not allowed as the first value in the column. Will be compared as strings. # N-th value in the column. # The rule expects exactly two arguments: the first is the line number (without header), the second is the expected value. ``` -------------------------------- ### Midhinge Definitions and Usage in CSV Blueprint Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Specifies values for midhinge, which represents the average of the first and third quartiles. Different comparison operators (min, greater, not, less, max) can be applied. ```CSV Blueprint midhinge_min: 1.0 # x >= 1.0 midhinge_greater: 2.0 # x > 2.0 midhinge_not: 5.0 # x != 5.0 midhinge: 7.0 # x == 7.0 midhinge_less: 8.0 # x < 8.0 midhinge_max: 9.0 # x <= 9.0 ``` -------------------------------- ### Password Strength Validation Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Validates password strength based on minimum length, greater than a value, not equal to a value, equal to a value, less than a value, and maximum length. Also checks for safe character usage in passwords. ```yaml password_strength_min: 1 # x >= 1 password_strength_greater: 2 # x > 2 password_strength_not: 0 # x != 0 password_strength: 7 # x == 7 password_strength_less: 8 # x < 8 password_strength_max: 9 # x <= 9 is_password_safe_chars: true # Check that the cell value contains only safe characters for regular passwords. Allowed characters: a-z, A-Z, 0-9, !@#$%^&*()_+-=[]{};:'"|,.<>/?~. ``` -------------------------------- ### Coefficient of Variation Rules Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Defines rules for the Coefficient of Variation, a measure of dispersion. It specifies conditions like minimum, maximum, exact, and inequality constraints, often expressed as a percentage. ```YAML coef_of_var_min: 1.0 # x >= 1.0 coef_of_var_greater: 2.0 # x > 2.0 coef_of_var_not: 5.0 # x != 5.0 coef_of_var: 7.0 # x == 7.0 coef_of_var_less: 8.0 # x < 8.0 coef_of_var_max: 9.0 # x <= 9.0 ``` -------------------------------- ### Internet Protocol (IP) Address Validation Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Validates various formats and types of IP addresses, including IPv4, IPv6, private IPs, reserved IPs, and IP ranges. Also includes validation for MAC addresses, domain names, public domain suffixes, URLs, and email addresses. ```yaml is_ip: true # Both: IPv4 or IPv6. is_ip_v4: true # Only IPv4. Example: "127.0.0.1". is_ip_v6: true # Only IPv6. Example: "2001:0db8:85a3:08d3:1319:8a2e:0370:7334". is_ip_private: true # IPv4 has ranges: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. IPv6 has ranges starting with FD or FC. is_ip_reserved: true # IPv4 has ranges: 0.0.0.0/8, 169.254.0.0/16, 127.0.0.0/8 and 240.0.0.0/4. IPv6 has ranges: ::1/128, ::/128, ::ffff:0:0/96 and fe80::/10. ip_v4_range: [ '127.0.0.1-127.0.0.5', '127.0.0.0/21' ] # Check subnet mask or range for IPv4. Address must be in one of the ranges. is_mac_address: true # The input is a valid MAC address. Example: 00:00:5e:00:53:01 is_domain: true # Only domain name. Example: "example.com". is_public_domain_suffix: true # The input is a public ICANN domain suffix. Example: "com", "nom.br", "net" etc. is_url: true # Only URL format. Example: "https://example.com/page?query=string#anchor". is_email: true # Only email format. Example: "user@example.com". ``` -------------------------------- ### Extra Checks: Strict Column Order Source: https://github.com/jbzoo/csv-blueprint/blob/master/README.md Checks for the correct sequential order of columns as defined in the schema, ensuring structural consistency within the CSV file. ```Markdown - The `strict_column_order` rule checks for the correct sequential order of columns as defined in the schema, ensuring structural consistency. ```