Skip to content

Commit

Permalink
Merge pull request #26 from gregurcom/618-project-settings-yaml
Browse files Browse the repository at this point in the history
#618 project settings yaml
  • Loading branch information
ygerasimov authored Apr 10, 2024
2 parents 0d6bd07 + 91f2467 commit e910df7
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 1.37

* Update project from YAML file

### 0.1.28
* Added the diffy screenshot:create-baseline command
* Added the diffy screenshot:set-baseline command
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Great for building integrations for your CI/CD tools. Allows scription taking sc
Download latest release from [https://github.com/DiffyWebsite/diffy-cli/releases](https://github.com/DiffyWebsite/diffy-cli/releases) page. Download just `diffy.phar` file. No need for all the source code. You can copy file to your executables so it is available everywhere.

```shell script
chmod a+x diffy.phar
cp diffy.phar /usr/local/bin/diffy
wget -O /usr/local/bin/diffy https://github.com/diffywebsite/diffy-cli/releases/latest/download/diffy.phar
chmod a+x /usr/local/bin/diffy
```

### Installion with Composer
Expand Down Expand Up @@ -97,7 +97,7 @@ If you want to update your config (For example, from CICD)
```shell script
diffy project:update PROJECT_ID ./examples/diffy_update_project.json
```
See the ./examples/diffy_update_project.json file for a valid config file.
See the ./examples/diffy_update_project.json or ./examples/diffy-project-projectID-demo-test-project.yaml file for a valid config file.

For multiple projects
```shell script
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.33
0.1.37
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"consolidation/robo": "^4",
"diffywebsite/diffy-php": "^1",
"guzzlehttp/guzzle": "^7",
"n98/junit-xml": "^1.1"
"n98/junit-xml": "^1.1",
"symfony/yaml": "^6.4"
},
"require-dev": {
"g1a/composer-test-scenarios": "^2",
Expand Down
3 changes: 3 additions & 0 deletions custom-vs-baseline.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CUSTOM_URL="https://diffy.website"
CUSTOM_SCREENSHOT_ID=$(diffy screenshot:create 22119 custom --envUrl=${MULTIDEV_SITE_URL})
diffy diff:create 22119 ${CUSTOM_SCREENSHOT_ID} 520974
49 changes: 49 additions & 0 deletions examples/diffy-project-projectID-demo-test-project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
basic:
name: 'Desk'
environments:
production: 'https://wordpress.diffy.website'
staging: 'http://stage.wordpress.diffy.website'
development: ''
breakpoints:
- 640
- 1024
- 1200
pages:
- /
- /2019/01
- /sample-page
- /2019/03/12/hello-world
- /category/uncategorized
- /2019/03/01/delectus-quia-esse-aut
monitoring:
days: { }
type: ''
advanced:
mask: ''
remove: ''
isolate: ''
delay: 10
scroll: false
headers:
- { header: user-agent, value: Googlebot-Image/1.0 }
cookies: ''
custom_js: ''
custom_css: ''
mock_content: ''
login:
type: ''
click_element: false
click_element_selector: ''
login_url: ''
username: ''
password: ''
username_selector: ''
password_selector: ''
submit_selector: ''
after_login_selector: ''
performance:
workers_production: 30
workers_nonproduction: 10
workers_production_delay: 0
workers_nonproduction_delay: 0
stabilize: false
24 changes: 16 additions & 8 deletions src/Commands/ProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Diffy\Screenshot;
use DiffyCli\Config;
use GuzzleHttp\Exception\InvalidArgumentException;
use GuzzleHttp\Utils;
use Robo\Tasks;
use Symfony\Component\Console\Style\SymfonyStyle;

use function GuzzleHttp\json_decode;
use Symfony\Component\Yaml\Yaml;

class ProjectCommand extends Tasks
{
Expand Down Expand Up @@ -41,7 +41,11 @@ private function isValidJsonConfig(string $configurationPath): array
}

try {
return json_decode($configuration, true);
if (str_ends_with($configurationPath, '.yaml')) {
return Yaml::parse($configuration, true);
}

return Utils::jsonDecode($configuration, true);
} catch (InvalidArgumentException $exception) {
$this->getIO()->writeln('<error>Configuration is not valid JSON<error>');

Expand Down Expand Up @@ -171,21 +175,25 @@ public function createCompare(
}

/**
* Update single project configuration
* Update single project configuration from YAML file
*
* @command project:update
*
* @param int $projectId Id of the project.
* @param string $configurationPath Path to the json config file.
* @param string $configurationPath Path to the YAML config file.
*
* @usage project:update 342 ./examples/diffy_update_project.json
* Updates given project ID with the diffy config.
* @usage project:update 342 ./examples/diffy_update_project.yaml
* Configuration can be downloaded from Project's settings page.
*
* @throws InvalidArgumentException
*/
public function updateProject(int $projectId, string $configurationPath)
{
Project::update($projectId, $this->isValidJsonConfig($configurationPath));
if (str_ends_with($configurationPath, '.yaml')) {
Project::updateYaml($projectId, $this->isValidJsonConfig($configurationPath));
} else {
Project::update($projectId, $this->isValidJsonConfig($configurationPath));
}

$this->getIO()->writeln('Project <info>' . $projectId . '</info> updated.');
}
Expand Down

0 comments on commit e910df7

Please sign in to comment.