Skip to content

Commit e910df7

Browse files
authored
Merge pull request #26 from gregurcom/618-project-settings-yaml
#618 project settings yaml
2 parents 0d6bd07 + 91f2467 commit e910df7

7 files changed

Lines changed: 78 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 1.37
4+
5+
* Update project from YAML file
6+
37
### 0.1.28
48
* Added the diffy screenshot:create-baseline command
59
* Added the diffy screenshot:set-baseline command

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Great for building integrations for your CI/CD tools. Allows scription taking sc
1414
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.
1515

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

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

102102
For multiple projects
103103
```shell script

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.33
1+
0.1.37

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"consolidation/robo": "^4",
2121
"diffywebsite/diffy-php": "^1",
2222
"guzzlehttp/guzzle": "^7",
23-
"n98/junit-xml": "^1.1"
23+
"n98/junit-xml": "^1.1",
24+
"symfony/yaml": "^6.4"
2425
},
2526
"require-dev": {
2627
"g1a/composer-test-scenarios": "^2",

custom-vs-baseline.sh

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CUSTOM_URL="https://diffy.website"
2+
CUSTOM_SCREENSHOT_ID=$(diffy screenshot:create 22119 custom --envUrl=${MULTIDEV_SITE_URL})
3+
diffy diff:create 22119 ${CUSTOM_SCREENSHOT_ID} 520974
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
basic:
2+
name: 'Desk'
3+
environments:
4+
production: 'https://wordpress.diffy.website'
5+
staging: 'http://stage.wordpress.diffy.website'
6+
development: ''
7+
breakpoints:
8+
- 640
9+
- 1024
10+
- 1200
11+
pages:
12+
- /
13+
- /2019/01
14+
- /sample-page
15+
- /2019/03/12/hello-world
16+
- /category/uncategorized
17+
- /2019/03/01/delectus-quia-esse-aut
18+
monitoring:
19+
days: { }
20+
type: ''
21+
advanced:
22+
mask: ''
23+
remove: ''
24+
isolate: ''
25+
delay: 10
26+
scroll: false
27+
headers:
28+
- { header: user-agent, value: Googlebot-Image/1.0 }
29+
cookies: ''
30+
custom_js: ''
31+
custom_css: ''
32+
mock_content: ''
33+
login:
34+
type: ''
35+
click_element: false
36+
click_element_selector: ''
37+
login_url: ''
38+
username: ''
39+
password: ''
40+
username_selector: ''
41+
password_selector: ''
42+
submit_selector: ''
43+
after_login_selector: ''
44+
performance:
45+
workers_production: 30
46+
workers_nonproduction: 10
47+
workers_production_delay: 0
48+
workers_nonproduction_delay: 0
49+
stabilize: false

src/Commands/ProjectCommand.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use Diffy\Screenshot;
1010
use DiffyCli\Config;
1111
use GuzzleHttp\Exception\InvalidArgumentException;
12+
use GuzzleHttp\Utils;
1213
use Robo\Tasks;
1314
use Symfony\Component\Console\Style\SymfonyStyle;
14-
15-
use function GuzzleHttp\json_decode;
15+
use Symfony\Component\Yaml\Yaml;
1616

1717
class ProjectCommand extends Tasks
1818
{
@@ -41,7 +41,11 @@ private function isValidJsonConfig(string $configurationPath): array
4141
}
4242

4343
try {
44-
return json_decode($configuration, true);
44+
if (str_ends_with($configurationPath, '.yaml')) {
45+
return Yaml::parse($configuration, true);
46+
}
47+
48+
return Utils::jsonDecode($configuration, true);
4549
} catch (InvalidArgumentException $exception) {
4650
$this->getIO()->writeln('<error>Configuration is not valid JSON<error>');
4751

@@ -171,21 +175,25 @@ public function createCompare(
171175
}
172176

173177
/**
174-
* Update single project configuration
178+
* Update single project configuration from YAML file
175179
*
176180
* @command project:update
177181
*
178182
* @param int $projectId Id of the project.
179-
* @param string $configurationPath Path to the json config file.
183+
* @param string $configurationPath Path to the YAML config file.
180184
*
181-
* @usage project:update 342 ./examples/diffy_update_project.json
182-
* Updates given project ID with the diffy config.
185+
* @usage project:update 342 ./examples/diffy_update_project.yaml
186+
* Configuration can be downloaded from Project's settings page.
183187
*
184188
* @throws InvalidArgumentException
185189
*/
186190
public function updateProject(int $projectId, string $configurationPath)
187191
{
188-
Project::update($projectId, $this->isValidJsonConfig($configurationPath));
192+
if (str_ends_with($configurationPath, '.yaml')) {
193+
Project::updateYaml($projectId, $this->isValidJsonConfig($configurationPath));
194+
} else {
195+
Project::update($projectId, $this->isValidJsonConfig($configurationPath));
196+
}
189197

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

0 commit comments

Comments
 (0)