Skip to content

Commit

Permalink
Merge pull request #124 from magento-commerce/develop
Browse files Browse the repository at this point in the history
MCLOUD-11293: Release ECE-Tools 2002.1.16
  • Loading branch information
BaDos authored Oct 16, 2023
2 parents def1e5a + 4264e7b commit c6a2c38
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 10 deletions.
14 changes: 6 additions & 8 deletions .github/.metadata.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"templateVersion": "0.1",
"templateVersion": "0.2",
"product": {
"name": "Magento Commerce Cloud Deployment Tools",
"description": "ECE-Tools is a set of scripts and tools designed to manage and deploy Cloud projects"
},
"contacts": {
"team": {
"name": "Magic Mountain",
"DL": "Grp-magento-cloud-all",
"slackChannel": "magic_mountain"
"name": "Mystic Mountain",
"DL": "Grp-Mystic-Mountain",
"slackChannel": "#mystic-mountain-team"
}
},
"ticketTracker": {
Expand All @@ -17,10 +17,8 @@
},
"securityJiraQueue": {
"projectKey": "MAGREQ",
"component": "Magento Cloud Engineering"
"component": "MAGREQ/Magento Cloud Engineering"
}
},
"staticScan": {
"enable": false
}
"productionCodeBranches": ["2002.0", "2002.1"]
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magento/ece-tools",
"description": "Provides tools to build and deploy Magento 2 Enterprise Edition",
"type": "magento2-component",
"version": "2002.1.15",
"version": "2002.1.16",
"license": "OSL-3.0",
"repositories": {
"repo.magento.com": {
Expand Down
10 changes: 10 additions & 0 deletions config/schema.error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,16 @@
suggestion: 'Check the `cloud.log` for more information.'
stage: general
type: critical
!php/const Magento\MagentoCloud\App\Error::GLOBAL_WEBHOOKS_MODULE_GENERATE_FAILED:
title: 'Failed to generate the AdobeCommerceWebhookPlugins module'
suggestion: 'Check the `cloud.log` for more information.'
stage: general
type: critical
!php/const Magento\MagentoCloud\App\Error::GLOBAL_WEBHOOKS_MODULE_ENABLEMENT_FAILED:
title: 'Failed to enable the AdobeCommerceWebhookPlugins module'
suggestion: 'Check the `cloud.log` for more information.'
stage: general
type: critical
# Warning errors
!php/const Magento\MagentoCloud\App\Error::WARN_CONFIG_PHP_NOT_EXISTS:
title: 'File app/etc/config.php does not exist'
Expand Down
11 changes: 11 additions & 0 deletions config/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ variables:
- stage:
global:
ENABLE_EVENTING: true
ENABLE_WEBHOOKS:
description: Enables Commerce webhooks.
type: boolean
stages:
- global
default:
global: false
examples:
- stage:
global:
ENABLE_WEBHOOKS: true

# Environment variables
ENV_RELATIONSHIPS:
Expand Down
2 changes: 2 additions & 0 deletions dist/error-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Critical errors indicate a problem with the Commerce on cloud infrastructure pro
| 246 | | Unable to read the `.schema.yaml` file | |
| 247 | | Unable to generate a module for eventing | Check the `cloud.log` for more information. |
| 248 | | Unable to enable a module for eventing | Check the `cloud.log` for more information. |
| 249 | | Failed to generate the AdobeCommerceWebhookPlugins module | Check the `cloud.log` for more information. |
| 250 | | Failed to enable the AdobeCommerceWebhookPlugins module | Check the `cloud.log` for more information. |

## Warning Errors

Expand Down
1 change: 1 addition & 0 deletions scenario/build/generate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<step name="marshall-files" type="Magento\MagentoCloud\Step\Build\MarshallFiles" priority="800"/>
<step name="copy-sample-data" type="Magento\MagentoCloud\Step\Build\CopySampleData" priority="900"/>
<step name="enable-eventing" type="Magento\MagentoCloud\Step\Build\EnableEventing" priority="950" />
<step name="enable-webhooks" type="Magento\MagentoCloud\Step\Build\EnableWebhooks" priority="975" />
<step name="compile-di" type="Magento\MagentoCloud\Step\Build\CompileDi" priority="1000"/>
<step name="dump-autoload" type="Magento\MagentoCloud\Step\Build\ComposerDumpAutoload" priority="1100"/>
<step name="deploy-static-content" type="Magento\MagentoCloud\Step\Build\DeployStaticContent" priority="1200">
Expand Down
2 changes: 2 additions & 0 deletions src/App/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class Error
public const GLOBAL_CONFIG_UNABLE_TO_READ_SCHEMA_YAML = 246;
public const GLOBAL_EVENTING_MODULE_GENERATE_FAILED = 247;
public const GLOBAL_EVENTING_MODULE_ENABLEMENT_FAILED = 248;
public const GLOBAL_WEBHOOKS_MODULE_GENERATE_FAILED = 249;
public const GLOBAL_WEBHOOKS_MODULE_ENABLEMENT_FAILED = 250;

/**
* Build
Expand Down
1 change: 1 addition & 0 deletions src/Config/StageConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface StageConfigInterface
public const VAR_SCD_NO_PARENT = 'SCD_NO_PARENT';
public const VAR_X_FRAME_CONFIGURATION = 'X_FRAME_CONFIGURATION';
public const VAR_ENABLE_EVENTING = 'ENABLE_EVENTING';
public const VAR_ENABLE_WEBHOOKS = 'ENABLE_WEBHOOKS';

/**
* Settings for deployment from git.
Expand Down
2 changes: 1 addition & 1 deletion src/Step/Build/EnableEventing.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function execute()
} catch (ShellException $e) {
$this->logger->error(
'Failed to generate the Magento_AdobeCommerceEvents module. ' .
'Refer to the eventing documentation to determine if all required modules are have been installed. ' .
'Refer to the eventing documentation to determine if all required modules have been installed. ' .
'Error: ' . $e->getMessage()
);
throw new StepException($e->getMessage(), Error::GLOBAL_EVENTING_MODULE_GENERATE_FAILED, $e);
Expand Down
94 changes: 94 additions & 0 deletions src/Step/Build/EnableWebhooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud\Step\Build;

use Magento\MagentoCloud\App\Error;
use Magento\MagentoCloud\Config\ConfigException;
use Magento\MagentoCloud\Config\GlobalSection;
use Magento\MagentoCloud\Config\StageConfigInterface;
use Magento\MagentoCloud\Shell\MagentoShell;
use Magento\MagentoCloud\Shell\ShellException;
use Magento\MagentoCloud\Shell\ShellFactory;
use Magento\MagentoCloud\Step\StepException;
use Magento\MagentoCloud\Step\StepInterface;
use Psr\Log\LoggerInterface;

/**
* Runs a command to generate a module for webhooks and enables this module in case when
* it is enabled in configuration
*/
class EnableWebhooks implements StepInterface
{
/**
* @var LoggerInterface
*/
private $logger;

/**
* @var MagentoShell
*/
private $magentoShell;

/**
* @var GlobalSection
*/
private $globalConfig;

/**
* @param LoggerInterface $logger
* @param ShellFactory $shellFactory
* @param GlobalSection $globalConfig
*/
public function __construct(
LoggerInterface $logger,
ShellFactory $shellFactory,
GlobalSection $globalConfig
) {
$this->logger = $logger;
$this->magentoShell = $shellFactory->createMagento();
$this->globalConfig = $globalConfig;
}

/**
* Generates and enables a module for Commerce webhooks
* if @see StageConfigInterface::VAR_ENABLE_WEBHOOKS set to true
*
* {@inheritDoc}
*/
public function execute()
{
try {
if (!$this->globalConfig->get(StageConfigInterface::VAR_ENABLE_WEBHOOKS)) {
return;
}
} catch (ConfigException $e) {
throw new StepException($e->getMessage(), $e->getCode(), $e);
}

try {
$this->logger->notice('Generating module for Commerce webhooks');
$this->magentoShell->execute('webhooks:generate:module');
} catch (ShellException $e) {
$this->logger->error(
'Failed to generate the AdobeCommerceWebhookPlugins module. ' .
'Refer to the Commerce webhooks documentation to determine if all ' .
'required modules have been installed. ' .
'Error: ' . $e->getMessage()
);
throw new StepException($e->getMessage(), Error::GLOBAL_WEBHOOKS_MODULE_GENERATE_FAILED, $e);
}

try {
$this->logger->notice('Enabling module for Commerce webhooks');
$this->magentoShell->execute('module:enable Magento_AdobeCommerceWebhookPlugins');
} catch (ShellException $e) {
$this->logger->error('Failed to enable module for Commerce webhooks: ' . $e->getMessage());
throw new StepException($e->getMessage(), Error::GLOBAL_WEBHOOKS_MODULE_ENABLEMENT_FAILED, $e);
}
}
}
1 change: 1 addition & 0 deletions src/Test/Unit/Config/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public function testGetDefaultsForGlobalSection(): void
StageConfigInterface::VAR_MIN_LOGGING_LEVEL => '',
StageConfigInterface::VAR_X_FRAME_CONFIGURATION => 'SAMEORIGIN',
StageConfigInterface::VAR_ENABLE_EVENTING => false,
StageConfigInterface::VAR_ENABLE_WEBHOOKS => false,
],
$this->schema->getDefaults(StageConfigInterface::STAGE_GLOBAL)
);
Expand Down
165 changes: 165 additions & 0 deletions src/Test/Unit/Step/Build/EnableWebhooksTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud\Test\Unit\Step\Build;

use Magento\MagentoCloud\App\Error;
use Magento\MagentoCloud\Config\GlobalSection;
use Magento\MagentoCloud\Config\StageConfigInterface;
use Magento\MagentoCloud\Shell\MagentoShell;
use Magento\MagentoCloud\Shell\ShellException;
use Magento\MagentoCloud\Shell\ShellFactory;
use Magento\MagentoCloud\Step\Build\EnableWebhooks;
use Magento\MagentoCloud\Step\StepException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

/**
* @inheritDoc
*/
class EnableWebhooksTest extends TestCase
{
/**
* @var EnableWebhooks
*/
private $step;

/**
* @var LoggerInterface|MockObject
*/
private $loggerMock;

/**
* @var MagentoShell|MockObject
*/
private $magentoShellMock;

/**
* @var GlobalSection|MockObject
*/
private $globalConfigMock;

/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
$this->magentoShellMock = $this->createMock(MagentoShell::class);
/** @var ShellFactory|MockObject $shellFactoryMock */
$shellFactoryMock = $this->createMock(ShellFactory::class);
$shellFactoryMock->expects($this->once())
->method('createMagento')
->willReturn($this->magentoShellMock);
$this->globalConfigMock = $this->createMock(GlobalSection::class);

$this->step = new EnableWebhooks(
$this->loggerMock,
$shellFactoryMock,
$this->globalConfigMock
);
}

/**
* @return void
* @throws StepException
*/
public function testExecuteWebhooksNotEnabled()
{
$this->globalConfigMock->expects(self::once())
->method('get')
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS)
->willReturn(false);

$this->magentoShellMock->expects(self::never())
->method('execute');
$this->loggerMock->expects(self::never())
->method('notice');

$this->step->execute();
}

/**
* @return void
* @throws StepException
*/
public function testExecuteGenerateCommandFailed()
{
$this->expectException(StepException::class);
$this->expectExceptionMessage('error during module generation');
$this->expectExceptionCode(Error::GLOBAL_WEBHOOKS_MODULE_GENERATE_FAILED);

$this->globalConfigMock->expects(self::once())
->method('get')
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS)
->willReturn(true);
$this->magentoShellMock->expects(self::once())
->method('execute')
->with('webhooks:generate:module')
->willThrowException(new ShellException('error during module generation'));
$this->loggerMock->expects(self::once())
->method('notice');
$this->loggerMock->expects(self::once())
->method('error');

$this->step->execute();
}

/**
* @return void
* @throws StepException
*/
public function testExecuteEnableModuleCommandFailed()
{
$this->expectException(StepException::class);
$this->expectExceptionMessage('error during module enablement');
$this->expectExceptionCode(Error::GLOBAL_WEBHOOKS_MODULE_ENABLEMENT_FAILED);

$this->globalConfigMock->expects(self::once())
->method('get')
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS)
->willReturn(true);
$this->magentoShellMock->expects(self::at(0))
->method('execute')
->with('webhooks:generate:module');
$this->magentoShellMock->expects(self::at(1))
->method('execute')
->with('module:enable Magento_AdobeCommerceWebhookPlugins')
->willThrowException(new ShellException('error during module enablement'));
$this->loggerMock->expects(self::exactly(2))
->method('notice');
$this->loggerMock->expects(self::once())
->method('error');

$this->step->execute();
}

/**
* @return void
* @throws StepException
*/
public function testExecuteSuccess()
{
$this->globalConfigMock->expects(self::once())
->method('get')
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS)
->willReturn(true);
$this->magentoShellMock->expects(self::at(0))
->method('execute')
->with('webhooks:generate:module');
$this->magentoShellMock->expects(self::at(1))
->method('execute')
->with('module:enable Magento_AdobeCommerceWebhookPlugins');
$this->loggerMock->expects(self::exactly(2))
->method('notice');
$this->loggerMock->expects(self::never())
->method('error');

$this->step->execute();
}
}

0 comments on commit c6a2c38

Please sign in to comment.