From 1917b9d32508962a1488d07368573fea7029f6df Mon Sep 17 00:00:00 2001 From: Lucas Mounsey Date: Thu, 21 Jul 2022 10:37:09 +1000 Subject: [PATCH 1/9] Upgrade for v4 support --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 494992e..4e3c91e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "todaydesign/craft-static-dusk", "description": "Static site builder for Craft and AWS Code Pipelines", "type": "craft-plugin", - "version": "1.1.0", + "version": "1.2.0", "keywords": [ "craft", "cms", @@ -22,7 +22,7 @@ } ], "require": { - "craftcms/cms": "^3.0.0-RC1" + "craftcms/cms": "^4.0.0" }, "autoload": { "psr-4": { From ca83133a97b45944ef5ef478f0bc1cde861ff831 Mon Sep 17 00:00:00 2001 From: Lucas Mounsey Date: Thu, 21 Jul 2022 10:43:09 +1000 Subject: [PATCH 2/9] Iterate schema version and set as string --- src/CraftStaticDusk.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CraftStaticDusk.php b/src/CraftStaticDusk.php index 07dcbd2..7bb69cd 100644 --- a/src/CraftStaticDusk.php +++ b/src/CraftStaticDusk.php @@ -63,7 +63,7 @@ class CraftStaticDusk extends Plugin * * @var string */ - public $schemaVersion = '1.0.1'; + public string $schemaVersion = '1.2.0'; // Public Methods // ========================================================================= From bca131b30bce035ab85355a8d1e26c0f21a01a5f Mon Sep 17 00:00:00 2001 From: Lucas Mounsey Date: Thu, 21 Jul 2022 10:46:07 +1000 Subject: [PATCH 3/9] Fix settings --- src/CraftStaticDusk.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CraftStaticDusk.php b/src/CraftStaticDusk.php index 7bb69cd..dcd2cf0 100644 --- a/src/CraftStaticDusk.php +++ b/src/CraftStaticDusk.php @@ -15,6 +15,7 @@ use todaydesign\craftstaticdusk\models\Settings; use Craft; +use craft\base\Model; use craft\base\Plugin; use craft\services\Plugins; use craft\events\PluginEvent; @@ -174,7 +175,7 @@ function (PluginEvent $event) { * * @return \craft\base\Model|null */ - protected function createSettingsModel() + protected function createSettingsModel(): ?Model { return new Settings(); } From b47f873d731adf8c2782850e18f760570fd21cce Mon Sep 17 00:00:00 2001 From: Matt Di Florio Date: Wed, 10 Aug 2022 12:13:15 +1000 Subject: [PATCH 4/9] [FEAT] CNB-21: Add php types to adhere to php 8 --- src/CraftStaticDusk.php | 3 ++- src/models/BuildSettings.php | 2 +- src/models/Settings.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CraftStaticDusk.php b/src/CraftStaticDusk.php index dcd2cf0..f0ca7b0 100644 --- a/src/CraftStaticDusk.php +++ b/src/CraftStaticDusk.php @@ -15,8 +15,8 @@ use todaydesign\craftstaticdusk\models\Settings; use Craft; -use craft\base\Model; use craft\base\Plugin; +use craft\base\Model; use craft\services\Plugins; use craft\events\PluginEvent; use craft\web\UrlManager; @@ -195,4 +195,5 @@ protected function settingsHtml(): string ] ); } + } diff --git a/src/models/BuildSettings.php b/src/models/BuildSettings.php index 8e1e5da..7fd69a1 100644 --- a/src/models/BuildSettings.php +++ b/src/models/BuildSettings.php @@ -52,7 +52,7 @@ class BuildSettings extends Model * * @return array */ - public function rules() + public function rules(): array { return [ ['someAttribute', 'string'], diff --git a/src/models/Settings.php b/src/models/Settings.php index 0632fa1..bc79431 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -61,7 +61,7 @@ class Settings extends Model * * @return array */ - public function rules() + public function rules(): array { return [ ['someAttribute', 'string'], From 99c35bf4e6fcb34e8c329482d05a780fea6eaf08 Mon Sep 17 00:00:00 2001 From: Matt Di Florio Date: Wed, 10 Aug 2022 12:14:13 +1000 Subject: [PATCH 5/9] [BUG] CNB-21: Update deprecated query params function --- src/templates/index.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/index.twig b/src/templates/index.twig index 6ea8cf1..7380cfe 100644 --- a/src/templates/index.twig +++ b/src/templates/index.twig @@ -36,8 +36,8 @@ {% set siteIds = siteIds ?? craft.app.sites.getEditableSiteIds() %} {% if selectedSiteId is not defined %} - {% if craft.request.getQuery('site') %} - {% set selectedSiteId = craft.request.getQuery('site') %} + {% if craft.app.request.getQueryParam('site') %} + {% set selectedSiteId = craft.app.request.getQueryParam('site') %} {% else %} {% set selectedSiteId = siteIds|first %} {% endif %} From d9916bfd4381b2a508f06da07f20400ede135332 Mon Sep 17 00:00:00 2001 From: Matt Di Florio Date: Wed, 10 Aug 2022 12:32:44 +1000 Subject: [PATCH 6/9] [BUG] CNB-21: Downgrade craftcms 4 requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4e3c91e..dbd026a 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "craftcms/cms": "^4.0.0" + "craftcms/cms": "^3.0.0-RC1" }, "autoload": { "psr-4": { From 48d6d1be34013a40d0bad8888f09570db527fc93 Mon Sep 17 00:00:00 2001 From: Matt Di Florio Date: Wed, 17 Aug 2022 09:56:09 +1000 Subject: [PATCH 7/9] [BUG] CNB-21: Set minimum version of craft rather than requiring v3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dbd026a..d596722 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "craftcms/cms": "^3.0.0-RC1" + "craftcms/cms": ">=3.0.0-RC1" }, "autoload": { "psr-4": { From 59a0797553a2a7129ae887735a312b1492d8a42e Mon Sep 17 00:00:00 2001 From: Lucas Mounsey Date: Fri, 15 Mar 2024 08:35:55 +1100 Subject: [PATCH 8/9] [FIX] Site parameter as numeric --- src/templates/index.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/index.twig b/src/templates/index.twig index 7380cfe..48fb85c 100644 --- a/src/templates/index.twig +++ b/src/templates/index.twig @@ -36,7 +36,7 @@ {% set siteIds = siteIds ?? craft.app.sites.getEditableSiteIds() %} {% if selectedSiteId is not defined %} - {% if craft.app.request.getQueryParam('site') %} + {% if craft.app.request.getQueryParam('site') is numeric %} {% set selectedSiteId = craft.app.request.getQueryParam('site') %} {% else %} {% set selectedSiteId = siteIds|first %} From 954a094a4d208fc7a678ccd3c351c2b9b7f16f4f Mon Sep 17 00:00:00 2001 From: anderssonlinda Date: Mon, 16 Feb 2026 17:20:16 +1100 Subject: [PATCH 9/9] [FIX] CCA-30: check hook type --- src/managers/StaticBuildManager.php | 117 +++++++++++----------- src/templates/index.twig | 19 ++-- src/variables/CraftStaticDuskVariable.php | 35 +++++-- 3 files changed, 101 insertions(+), 70 deletions(-) diff --git a/src/managers/StaticBuildManager.php b/src/managers/StaticBuildManager.php index 89929d2..194edf5 100644 --- a/src/managers/StaticBuildManager.php +++ b/src/managers/StaticBuildManager.php @@ -17,44 +17,46 @@ public function getScheduledBuilds($site) { $settings = CraftStaticDusk::$plugin->getSettings(); - $payload = [ - 'secret' => Craft::parseEnv($settings->webHookSecret), - 'repo' => Craft::parseEnv($settings->gitRepo), - 'ref' => Craft::parseEnv($settings->gitRef), - 'envName' => Craft::parseEnv($settings->environmentName), - 'site' => $site - ]; - - $response = null; - $curl = curl_init(); - curl_setopt_array($curl, array( - CURLOPT_URL => Craft::parseEnv($settings->webHookUrl) . '/scheduled', + if (Craft::parseEnv($settings->webHookType) === 'GH') { + $payload = [ + 'secret' => Craft::parseEnv($settings->webHookSecret), + 'repo' => Craft::parseEnv($settings->gitRepo), + 'ref' => Craft::parseEnv($settings->gitRef), + 'envName' => Craft::parseEnv($settings->environmentName), + 'site' => $site + ]; + + $response = null; + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => Craft::parseEnv($settings->webHookUrl) . '/scheduled', // CURLOPT_URL => "http://host.docker.internal:3000/static-build/scheduled", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_CUSTOMREQUEST => "GET", - CURLOPT_POSTFIELDS => json_encode((object)$payload), - CURLOPT_VERBOSE => TRUE, - )); + CURLOPT_RETURNTRANSFER => true, + CURLOPT_CUSTOMREQUEST => "GET", + CURLOPT_POSTFIELDS => json_encode((object)$payload), + CURLOPT_VERBOSE => TRUE, + )); - $response = curl_exec($curl); + $response = curl_exec($curl); - if ($response === false) { - return []; - } + if ($response === false) { + return []; + } - $response = json_decode($response); + $response = json_decode($response); - curl_close($curl); + curl_close($curl); - if (property_exists($response, "responseObject")) { + if ($response !== null && property_exists($response, "responseObject")) { - // Convert unix milliseconds to seconds - $data = array_map(function ($build) { - $build->LaunchTime = $build->LaunchTime / 1000; - return $build; - }, $response->responseObject); + // Convert unix milliseconds to seconds + $data = array_map(function ($build) { + $build->LaunchTime = $build->LaunchTime / 1000; + return $build; + }, $response->responseObject); - return $response->responseObject; + return $response->responseObject; + } } return []; @@ -69,38 +71,41 @@ public function getScheduledBuilds($site) public function getBuildHistory($site) { $settings = CraftStaticDusk::$plugin->getSettings(); - $ref = str_replace("refs/heads/", "", Craft::parseEnv($settings->gitRef)); - - $payload = [ - 'secret' => Craft::parseEnv($settings->webHookSecret), - 'repo' => Craft::parseEnv($settings->gitRepo), - 'ref' => $ref, - 'site' => $site - ]; - - $response = null; - $curl = curl_init(); - curl_setopt_array($curl, array( - CURLOPT_URL => Craft::parseEnv($settings->webHookUrl) . '/history', + + if (Craft::parseEnv($settings->webHookType) === 'GH') { + $ref = str_replace("refs/heads/", "", Craft::parseEnv($settings->gitRef)); + + $payload = [ + 'secret' => Craft::parseEnv($settings->webHookSecret), + 'repo' => Craft::parseEnv($settings->gitRepo), + 'ref' => $ref, + 'site' => $site + ]; + + $response = null; + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => Craft::parseEnv($settings->webHookUrl) . '/history', // CURLOPT_URL => "http://host.docker.internal:3000/static-build/history", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_CUSTOMREQUEST => "GET", - CURLOPT_POSTFIELDS => json_encode((object)$payload), - CURLOPT_VERBOSE => TRUE, - )); + CURLOPT_RETURNTRANSFER => true, + CURLOPT_CUSTOMREQUEST => "GET", + CURLOPT_POSTFIELDS => json_encode((object)$payload), + CURLOPT_VERBOSE => TRUE, + )); - $response = curl_exec($curl); + $response = curl_exec($curl); - if ($response === false) { - return []; - } + if ($response === false) { + return []; + } - $response = json_decode($response); + $response = json_decode($response); - curl_close($curl); + curl_close($curl); - if (property_exists($response, "responseObject")) { - return $response->responseObject; + if ($response !== null && property_exists($response, "responseObject")) { + return $response->responseObject; + } } return []; diff --git a/src/templates/index.twig b/src/templates/index.twig index 48fb85c..bb73ab5 100644 --- a/src/templates/index.twig +++ b/src/templates/index.twig @@ -52,6 +52,7 @@ {% set buildHistory = craft.craftStaticDusk.getBuildHistory(site.handle) %} {% set isMissingEnvVariables = craft.craftStaticDusk.isMissingEnvVariables() %} +{% set isGhWebhook = craft.craftStaticDusk.isGhWebhook() %} {# Content that should appear in the page header #} {% set extraPageHeaderHtml %} @@ -67,7 +68,7 @@
  • Warning: Missing environment variables

  • - Make sure that the environment variables webHookSecret, webHookUrl, gitRepo, gitRef and environmentName are set in the project.yaml and are correctly set in the CI + Make sure that the environment variables {% if isGhWebhook %}webHookSecret, webHookUrl, gitRepo, gitRef and environmentName{% else %}webHookSecret, webHookUrl and environmentName{% endif %} are set in the project.yaml and are correctly set in the CI
  • {% endif %} @@ -107,6 +108,7 @@

    + {% if isGhWebhook %}

    When do you want to launch the build?


    - - + {% else %} +
    + {% endif %}
    {{ csrfInput() }} @@ -142,6 +145,7 @@
    + {% if isGhWebhook %}