From 5998cc1e59d5eddd74f387a3eb6cf53243675e8f Mon Sep 17 00:00:00 2001 From: Mihail Gregurco Date: Sun, 17 Mar 2024 16:52:09 +0200 Subject: [PATCH 1/5] #618 project settings yaml --- README.md | 2 +- composer.json | 3 ++- examples/diffy_update_project.yaml | 15 +++++++++++++++ examples/diffy_update_projects.yaml | 30 +++++++++++++++++++++++++++++ src/Commands/ProjectCommand.php | 10 +++++++--- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 examples/diffy_update_project.yaml create mode 100644 examples/diffy_update_projects.yaml diff --git a/README.md b/README.md index d885a90..d8c40ea 100644 --- a/README.md +++ b/README.md @@ -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_update_project.yaml file for a valid config file. For multiple projects ```shell script diff --git a/composer.json b/composer.json index d2cb075..c909c70 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/examples/diffy_update_project.yaml b/examples/diffy_update_project.yaml new file mode 100644 index 0000000..92d6848 --- /dev/null +++ b/examples/diffy_update_project.yaml @@ -0,0 +1,15 @@ +name: Your project name +breakpoints: + - 320 + - 1024 + - 1920 + - 333 +production: https://your-site.com +staging: https://user:password@staging.your-site.com +development: https://user:password@dev.your-site.com +urls: + - https://your-site.com/faq + - https://your-site.com/questions + - https://your-site.com/news +schedule: + type: '' diff --git a/examples/diffy_update_projects.yaml b/examples/diffy_update_projects.yaml new file mode 100644 index 0000000..5cba2d0 --- /dev/null +++ b/examples/diffy_update_projects.yaml @@ -0,0 +1,30 @@ +'1': + name: Your project1 name + breakpoints: + - 320 + - 1024 + - 1920 + production: https://your-site1.com + staging: https://user1:password1@staging.your-site1.com + development: https://user1:password1@dev.your-site1.com + urls: + - https://your-site1.com/faq + - https://your-site1.com/questions + - https://your-site1.com/news + schedule: + type: '' +'2': + name: Your project2 name + breakpoints: + - 320 + - 1024 + - 1920 + production: https://your-site2.com + staging: https://user2:password2@staging.your-site2.com + development: https://user2:password2@dev.your-site2.com + urls: + - https://your-site2.com/faq + - https://your-site2.com/questions + - https://your-site2.com/news + schedule: + type: '' diff --git a/src/Commands/ProjectCommand.php b/src/Commands/ProjectCommand.php index d2b9144..20bd53e 100644 --- a/src/Commands/ProjectCommand.php +++ b/src/Commands/ProjectCommand.php @@ -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 { @@ -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('Configuration is not valid JSON'); From 5d4764afbcfd8d872ae4072b12aea61c27e1444f Mon Sep 17 00:00:00 2001 From: Mihail Gregurco Date: Sun, 17 Mar 2024 17:00:51 +0200 Subject: [PATCH 2/5] #618 update yaml file --- examples/diffy_update_project.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/diffy_update_project.yaml b/examples/diffy_update_project.yaml index 92d6848..5ec40eb 100644 --- a/examples/diffy_update_project.yaml +++ b/examples/diffy_update_project.yaml @@ -3,7 +3,6 @@ breakpoints: - 320 - 1024 - 1920 - - 333 production: https://your-site.com staging: https://user:password@staging.your-site.com development: https://user:password@dev.your-site.com From 4164fa1cf3aca5d3269771d26d5ac077cda4ecbb Mon Sep 17 00:00:00 2001 From: Mihail Gregurco Date: Wed, 27 Mar 2024 19:51:47 +0200 Subject: [PATCH 3/5] #618 project settings yaml --- examples/diffy_update_project.yaml | 34 ++++++++++++++++----------- examples/diffy_update_projects.json | 36 ----------------------------- src/Commands/ProjectCommand.php | 6 ++++- 3 files changed, 25 insertions(+), 51 deletions(-) delete mode 100644 examples/diffy_update_projects.json diff --git a/examples/diffy_update_project.yaml b/examples/diffy_update_project.yaml index 5ec40eb..fa693f3 100644 --- a/examples/diffy_update_project.yaml +++ b/examples/diffy_update_project.yaml @@ -1,14 +1,20 @@ -name: Your project name -breakpoints: - - 320 - - 1024 - - 1920 -production: https://your-site.com -staging: https://user:password@staging.your-site.com -development: https://user:password@dev.your-site.com -urls: - - https://your-site.com/faq - - https://your-site.com/questions - - https://your-site.com/news -schedule: - type: '' +basic: + name: 'Demo test project' + environments: { production: 'https://wordpress.diffy.website', staging: 'http://stage.wordpress.diffy.website', development: '' } + breakpoints: [640, 1024, 1200] + pages: ['https://wordpress.diffy.website', 'https://wordpress.diffy.website/2019/01', 'https://wordpress.diffy.website/sample-page', 'https://wordpress.diffy.website/2019/03/12/hello-world', 'https://wordpress.diffy.website/category/uncategorized', 'https://wordpress.diffy.website/2019/03/01/delectus-quia-esse-aut', 'https://wordpress.diffy.website/2019/04/01/tempora-ut-similique-corporis-sit', 'https://wordpress.diffy.website/2019/02/08/sed-natus-molestiae-ullam-sint-quia', 'https://wordpress.diffy.website/2019/02/02/quo-suscipit-aut-et-est-adipisci-qui', 'https://wordpress.diffy.website/2019/02/12/qui-officia-et-veniam-sit-quibusdam-non', 'https://wordpress.diffy.website/2019/03/16/sunt-praesentium-animi-sed-omnis-ut-iste', 'https://wordpress.diffy.website/2019/04/01/tempora-ut-similique-corporis-sit/#respond', 'https://wordpress.diffy.website/2019/02/08/sed-natus-molestiae-ullam-sint-quia/#respond', 'https://wordpress.diffy.website/2019/02/01/quaerat-earum-aut-reiciendis-vitae-aut-dolore', 'https://wordpress.diffy.website/2019/02/02/quo-suscipit-aut-et-est-adipisci-qui/#respond', 'https://wordpress.diffy.website/2019/02/12/qui-officia-et-veniam-sit-quibusdam-non/#respond', 'https://wordpress.diffy.website/2019/03/16/sunt-praesentium-animi-sed-omnis-ut-iste/#respond', 'https://wordpress.diffy.website/2019/03/21/voluptatibus-tenetur-iste-commodi-officiis-repellat', 'https://wordpress.diffy.website/2019/04/03/ratione-laboriosam-velit-quibusdam-animi-maiores-labore-vel', 'https://wordpress.diffy.website/2019/03/21/voluptatibus-tenetur-iste-commodi-officiis-repellat/#respond', 'https://wordpress.diffy.website/2019/04/03/ratione-laboriosam-velit-quibusdam-animi-maiores-labore-vel/#respond'] + monitoring: { days: { }, type: '' } +advanced: + mask: '' + remove: '' + isolate: '' + delay: 10 + scroll: false + headers: [{ value: Googlebot-Image/1.0, header: user-agent }] + 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 diff --git a/examples/diffy_update_projects.json b/examples/diffy_update_projects.json deleted file mode 100644 index ccec79a..0000000 --- a/examples/diffy_update_projects.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "1" : { - "name" : "Your project1 name", - "breakpoints" : [ - 320, 1024, 1920 - ], - "production" : "https://your-site1.com", - "staging": "https://user1:password1@staging.your-site1.com", - "development": "https://user1:password1@dev.your-site1.com", - "urls": [ - "https://your-site1.com/faq", - "https://your-site1.com/questions", - "https://your-site1.com/news" - ], - "schedule": { - "type": "" - } - }, - "2" : { - "name" : "Your project2 name", - "breakpoints" : [ - 320, 1024, 1920 - ], - "production" : "https://your-site2.com", - "staging": "https://user2:password2@staging.your-site2.com", - "development": "https://user2:password2@dev.your-site2.com", - "urls": [ - "https://your-site2.com/faq", - "https://your-site2.com/questions", - "https://your-site2.com/news" - ], - "schedule": { - "type": "" - } - } -} diff --git a/src/Commands/ProjectCommand.php b/src/Commands/ProjectCommand.php index 20bd53e..ef4a5a2 100644 --- a/src/Commands/ProjectCommand.php +++ b/src/Commands/ProjectCommand.php @@ -189,7 +189,11 @@ public function createCompare( */ 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 ' . $projectId . ' updated.'); } From 6435d742b9b90732a06d5da64144a60a3de7d893 Mon Sep 17 00:00:00 2001 From: Mihail Gregurco Date: Wed, 27 Mar 2024 19:54:36 +0200 Subject: [PATCH 4/5] #618 update projects json --- examples/diffy_update_projects.json | 36 +++++++++++++++++++++++++++++ examples/diffy_update_projects.yaml | 30 ------------------------ 2 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 examples/diffy_update_projects.json delete mode 100644 examples/diffy_update_projects.yaml diff --git a/examples/diffy_update_projects.json b/examples/diffy_update_projects.json new file mode 100644 index 0000000..ccec79a --- /dev/null +++ b/examples/diffy_update_projects.json @@ -0,0 +1,36 @@ +{ + "1" : { + "name" : "Your project1 name", + "breakpoints" : [ + 320, 1024, 1920 + ], + "production" : "https://your-site1.com", + "staging": "https://user1:password1@staging.your-site1.com", + "development": "https://user1:password1@dev.your-site1.com", + "urls": [ + "https://your-site1.com/faq", + "https://your-site1.com/questions", + "https://your-site1.com/news" + ], + "schedule": { + "type": "" + } + }, + "2" : { + "name" : "Your project2 name", + "breakpoints" : [ + 320, 1024, 1920 + ], + "production" : "https://your-site2.com", + "staging": "https://user2:password2@staging.your-site2.com", + "development": "https://user2:password2@dev.your-site2.com", + "urls": [ + "https://your-site2.com/faq", + "https://your-site2.com/questions", + "https://your-site2.com/news" + ], + "schedule": { + "type": "" + } + } +} diff --git a/examples/diffy_update_projects.yaml b/examples/diffy_update_projects.yaml deleted file mode 100644 index 5cba2d0..0000000 --- a/examples/diffy_update_projects.yaml +++ /dev/null @@ -1,30 +0,0 @@ -'1': - name: Your project1 name - breakpoints: - - 320 - - 1024 - - 1920 - production: https://your-site1.com - staging: https://user1:password1@staging.your-site1.com - development: https://user1:password1@dev.your-site1.com - urls: - - https://your-site1.com/faq - - https://your-site1.com/questions - - https://your-site1.com/news - schedule: - type: '' -'2': - name: Your project2 name - breakpoints: - - 320 - - 1024 - - 1920 - production: https://your-site2.com - staging: https://user2:password2@staging.your-site2.com - development: https://user2:password2@dev.your-site2.com - urls: - - https://your-site2.com/faq - - https://your-site2.com/questions - - https://your-site2.com/news - schedule: - type: '' From 91f24670d8c7045a793b86b178f5e959549e950a Mon Sep 17 00:00:00 2001 From: Mihail Gregurco Date: Wed, 10 Apr 2024 09:46:08 +0300 Subject: [PATCH 5/5] #618 change test yaml file --- CHANGELOG.md | 4 ++ README.md | 6 +-- VERSION | 2 +- custom-vs-baseline.sh | 3 ++ ...y-project-projectID-demo-test-project.yaml | 49 +++++++++++++++++++ examples/diffy_update_project.yaml | 20 -------- src/Commands/ProjectCommand.php | 8 +-- 7 files changed, 64 insertions(+), 28 deletions(-) mode change 100644 => 100755 custom-vs-baseline.sh create mode 100644 examples/diffy-project-projectID-demo-test-project.yaml delete mode 100644 examples/diffy_update_project.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index c127155..2c65608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index d8c40ea..9ea801f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 or ./examples/diffy_update_project.yaml 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 diff --git a/VERSION b/VERSION index 50140e3..9f42295 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.33 +0.1.37 diff --git a/custom-vs-baseline.sh b/custom-vs-baseline.sh old mode 100644 new mode 100755 index e69de29..22fb2b3 --- a/custom-vs-baseline.sh +++ b/custom-vs-baseline.sh @@ -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 diff --git a/examples/diffy-project-projectID-demo-test-project.yaml b/examples/diffy-project-projectID-demo-test-project.yaml new file mode 100644 index 0000000..3a46e46 --- /dev/null +++ b/examples/diffy-project-projectID-demo-test-project.yaml @@ -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 diff --git a/examples/diffy_update_project.yaml b/examples/diffy_update_project.yaml deleted file mode 100644 index fa693f3..0000000 --- a/examples/diffy_update_project.yaml +++ /dev/null @@ -1,20 +0,0 @@ -basic: - name: 'Demo test project' - environments: { production: 'https://wordpress.diffy.website', staging: 'http://stage.wordpress.diffy.website', development: '' } - breakpoints: [640, 1024, 1200] - pages: ['https://wordpress.diffy.website', 'https://wordpress.diffy.website/2019/01', 'https://wordpress.diffy.website/sample-page', 'https://wordpress.diffy.website/2019/03/12/hello-world', 'https://wordpress.diffy.website/category/uncategorized', 'https://wordpress.diffy.website/2019/03/01/delectus-quia-esse-aut', 'https://wordpress.diffy.website/2019/04/01/tempora-ut-similique-corporis-sit', 'https://wordpress.diffy.website/2019/02/08/sed-natus-molestiae-ullam-sint-quia', 'https://wordpress.diffy.website/2019/02/02/quo-suscipit-aut-et-est-adipisci-qui', 'https://wordpress.diffy.website/2019/02/12/qui-officia-et-veniam-sit-quibusdam-non', 'https://wordpress.diffy.website/2019/03/16/sunt-praesentium-animi-sed-omnis-ut-iste', 'https://wordpress.diffy.website/2019/04/01/tempora-ut-similique-corporis-sit/#respond', 'https://wordpress.diffy.website/2019/02/08/sed-natus-molestiae-ullam-sint-quia/#respond', 'https://wordpress.diffy.website/2019/02/01/quaerat-earum-aut-reiciendis-vitae-aut-dolore', 'https://wordpress.diffy.website/2019/02/02/quo-suscipit-aut-et-est-adipisci-qui/#respond', 'https://wordpress.diffy.website/2019/02/12/qui-officia-et-veniam-sit-quibusdam-non/#respond', 'https://wordpress.diffy.website/2019/03/16/sunt-praesentium-animi-sed-omnis-ut-iste/#respond', 'https://wordpress.diffy.website/2019/03/21/voluptatibus-tenetur-iste-commodi-officiis-repellat', 'https://wordpress.diffy.website/2019/04/03/ratione-laboriosam-velit-quibusdam-animi-maiores-labore-vel', 'https://wordpress.diffy.website/2019/03/21/voluptatibus-tenetur-iste-commodi-officiis-repellat/#respond', 'https://wordpress.diffy.website/2019/04/03/ratione-laboriosam-velit-quibusdam-animi-maiores-labore-vel/#respond'] - monitoring: { days: { }, type: '' } -advanced: - mask: '' - remove: '' - isolate: '' - delay: 10 - scroll: false - headers: [{ value: Googlebot-Image/1.0, header: user-agent }] - 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 diff --git a/src/Commands/ProjectCommand.php b/src/Commands/ProjectCommand.php index ef4a5a2..a487fd0 100644 --- a/src/Commands/ProjectCommand.php +++ b/src/Commands/ProjectCommand.php @@ -175,15 +175,15 @@ 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 */