Skip to content

Commit

Permalink
Merge db657c2 into 1baf221
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Mar 14, 2024
2 parents 1baf221 + db657c2 commit 05b3721
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Also see demo in the [GitHub Actions](https://github.com/JBZoo/Csv-Blueprint/act
### As GitHub Action

```yml
- uses: jbzoo/csv-blueprint # See the specific version on releases page
- uses: jbzoo/csv-blueprint@master # See the specific version on releases page
with:
# Path(s) to validate. You can specify path in which CSV files will be searched. Feel free to use glob pattrens. Usage examples: /full/path/file.csv, p/file.csv, p/*.csv, p/**/*.csv, p/**/name-*.csv, **/*.csv, etc.
# Required: true
Expand Down Expand Up @@ -330,8 +330,8 @@ columns:
max_word_count: 5 # Integer only. Max count of words in the string Example: "Hello World! 123" - 2 words only (123 is not a word)
at_least_contains: [ a, b ] # At least one of the string must be in the CSV value. Case-sensitive.
all_must_contain: [ a, b, c ] # All the strings must be part of a CSV value. Case-sensitive.
str_ends_with: " suffix" # Case-sensitive. Example: "Hello World suffix"
str_starts_with: "prefix " # Case-sensitive. Example: "prefix Hello World"
str_ends_with: " suffix" # Case-sensitive. Example: "Hello World suffix"

# Decimal and integer numbers
min: 10 # Can be integer or float, negative and positive
Expand Down Expand Up @@ -380,7 +380,7 @@ Batch processing
Validation
* [x] ~~`filename_pattern` validation with regex (like "all files in the folder should be in the format `/^[\d]{4}-[\d]{2}-[\d]{2}\.csv$/`").~~
* [ ] Flag to ignore file name pattern. It's useful when you have a lot of files and you don't want to validate the file name.
* [ ] Keyword for null value. Configurable. By default, it's an empty string. But you can use `null`, `nil`, `none`, `empty`, etc.
* [ ] Keyword for null value. Configurable. By default, it's an empty string. But you can use `null`, `nil`, `none`, `empty`, etc. Overridable on the column level.
* [ ] Agregate rules (like "at least one of the fields should be not empty" or "all values must be unique").
* [ ] Handle empty files and files with only a header row, or only with one line of data. One column wthout header is also possible.
* [ ] Using multiple schemas for one csv file.
Expand Down Expand Up @@ -409,6 +409,8 @@ Mock data generation
* [ ] Use [Faker](https://github.com/FakerPHP/Faker) for random data generation.

Reporting
* [ ] Fix auto width of tables in Githu terminal.
* [ ]
* [ ] More report formats (like JSON, XML, etc). Any ideas?
* [ ] Gitlab and JUnit reports must be as one structure. It's not so easy to implement. But it's a good idea.
* [ ] Merge reports from multiple CSV files into one report. It's useful when you have a lot of files and you want to see all errors in one place. Especially for GitLab and JUnit reports.
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ inputs:
runs:
using: 'docker'
image: 'docker://jbzoo/csv-blueprint'
env:
GITHUB_ACTIONS: 'true'
args:
- validate:csv
- '--csv'
Expand Down
2 changes: 1 addition & 1 deletion schema-examples/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"max_word_count" : 5,
"at_least_contains" : ["a", "b"],
"all_must_contain" : ["a", "b", "c"],
"str_ends_with" : " suffix",
"str_starts_with" : "prefix ",
"str_ends_with" : " suffix",
"min" : 10,
"max" : 100.5,
"precision" : 3,
Expand Down
2 changes: 1 addition & 1 deletion schema-examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
'max_word_count' => 5,
'at_least_contains' => ['a', 'b'],
'all_must_contain' => ['a', 'b', 'c'],
'str_ends_with' => ' suffix',
'str_starts_with' => 'prefix ',
'str_ends_with' => ' suffix',
'min' => 10,
'max' => 100.5,
'precision' => 3,
Expand Down
2 changes: 1 addition & 1 deletion schema-examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ columns:
max_word_count: 5 # Integer only. Max count of words in the string Example: "Hello World! 123" - 2 words only (123 is not a word)
at_least_contains: [ a, b ] # At least one of the string must be in the CSV value. Case-sensitive.
all_must_contain: [ a, b, c ] # All the strings must be part of a CSV value. Case-sensitive.
str_ends_with: " suffix" # Case-sensitive. Example: "Hello World suffix"
str_starts_with: "prefix " # Case-sensitive. Example: "prefix Hello World"
str_ends_with: " suffix" # Case-sensitive. Example: "Hello World suffix"

# Decimal and integer numbers
min: 10 # Can be integer or float, negative and positive
Expand Down
11 changes: 11 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace JBZoo\CsvBlueprint;

use JBZoo\Utils\Env;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

Expand Down Expand Up @@ -103,4 +104,14 @@ public static function cutPath(string $fullpath): string

return \str_replace($pwd, '.', $fullpath);
}

public static function isDocker(): bool
{
return \file_exists('/app/csv-blueprint');
}

public static function isGithubActions(): bool
{
return self::isDocker() && Env::bool('GITHUB_ACTIONS');
}
}
23 changes: 19 additions & 4 deletions src/Validators/ErrorSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use JBZoo\CIReportConverter\Converters\JUnitConverter;
use JBZoo\CIReportConverter\Converters\TeamCityTestsConverter;
use JBZoo\CIReportConverter\Formats\Source\SourceSuite;
use JBZoo\CsvBlueprint\Utils;
use JBZoo\Utils\Cli;
use JBZoo\Utils\Env;
use JBZoo\Utils\Vars;
Expand Down Expand Up @@ -199,14 +200,14 @@ private static function getTableSize(): array
'line' => 10,
'column' => 20,
'rule' => 20,
'min' => 90,
'min' => 120,
'max' => 150,
'reserve' => 5, // So that the table does not rest on the very edge of the terminal. Just in case.
'reserve' => 3, // So that the table does not rest on the very edge of the terminal. Just in case.
];

// Fallback to 80 if the terminal width cannot be determined.
// env.COLUMNS_TEST usually not defined so we use it only for testing purposes.
$maxAutoDetected = Env::int('COLUMNS_TEST', Cli::getNumberOfColumns());
// env.COLUMNS_TEST usually not defined, so we use it only for testing purposes.
$maxAutoDetected = self::autoDetectTerminalWidth();

$maxWindowWidth = Vars::limit(
$maxAutoDetected,
Expand All @@ -221,4 +222,18 @@ private static function getTableSize(): array

return $floatingSizes;
}

private static function autoDetectTerminalWidth(): int
{
$maxAutoDetected = Env::int('COLUMNS_TEST', Cli::getNumberOfColumns());
if (Utils::isDocker()) {
$maxAutoDetected = 120;
}

if (Utils::isGithubActions()) {
$maxAutoDetected = 200; // GitHub Actions has a wide terminal
}

return $maxAutoDetected;
}
}
2 changes: 1 addition & 1 deletion tests/Blueprint/GithubActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testGitHubActionsReadMe(): void

$expectedMessage = [
'```yml',
'- uses: jbzoo/csv-blueprint # See the specific version on releases page',
'- uses: jbzoo/csv-blueprint@master # See the specific version on releases page',
' with:',
];

Expand Down

0 comments on commit 05b3721

Please sign in to comment.