Skip to content

Commit

Permalink
Merge branch 'release/9.x' of github.com:ec-europa/toolkit into relea…
Browse files Browse the repository at this point in the history
…se/10.x
  • Loading branch information
joaocsilva committed Jun 30, 2023
2 parents a9c8ac6 + da579e8 commit 94adb4a
Show file tree
Hide file tree
Showing 23 changed files with 352 additions and 202 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Toolkit change log

# Version 9.10.0 | 10.0.0
## Version 9.11.0
- DQA-6750: Command to check drupal permissions.
- DQA-6750: Control blocker of drupal:check-permissions.
- DQA-7006: Duplicated options when running toolkit:lint-php.
- DQA-6154: Component check - remove limitation of checking drupal module only.
- DQA-6681: Command drupal:permissions-setup should not apply permissions recursively.
- DQA-7280: Support Drush12.
- DQA-7333: Add aliases to commands.
- DQA-7296: Add user-agent to the Toolkit api calls.

## Version 9.10.0 | 10.0.0
- DQA-7047: Deploy commands run drush cr as first.
- DQA-5985: Update default value of toolkit to match the new environment.

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"consolidation/annotated-command": "^4.7.0",
"consolidation/robo": "^3.0 || ^4.0",
"cweagans/composer-patches": "^1.4 || ^1.7",
"drush/drush": "^10.0.0 || ^11.0.4",
"drush/drush": "^10.0.0 || ^11.0.4 || ^12.0",
"ec-europa/qa-automation": "^9.0",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"jakeasmith/http_build_url": "^1.0",
Expand Down Expand Up @@ -55,7 +55,8 @@
"sort-packages": true,
"allow-plugins": {
"cweagans/composer-patches": true,
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions config/runner/drupal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ drupal:
drush:
options:
uri: '${drupal.base_url}'
# Control whether the command drupal:check-permissions will exit on failure.
permissions:
blocker: true
# List of shell commands to be before and after the site installation.
# You can use same syntax as the "commands:", check the documentation for more.
# Configuration token replacement is supported too.
Expand Down
33 changes: 17 additions & 16 deletions docs/guide/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ See bellow current list of available commands:
docker
docker:refresh-configuration [dk-rc] Update docker-compose.yml file based on project's configurations.
drupal
drupal:check-permissions Command to check the forbidden permissions.
drupal:config-import Run the Drupal config import.
drupal:disable-cache Disable aggregation and clear cache.
drupal:drush-setup Write Drush configuration file at "${drupal.root}/drush/drush.yml".
Expand All @@ -32,46 +33,46 @@ See bellow current list of available commands:
drupal:symlink-project Symlink project as module, theme or profile in the proper directory.
drupal:upgrade-status [tdus] Check project compatibility for Drupal 9/10 upgrade.
toolkit
toolkit:build-assets [tba|tk-assets] Build theme assets (Css and Js).
toolkit:build-assets [tk-bassets|tk-assets|tba] Build theme assets (Css and Js).
toolkit:build-dev [tk-bdev] Build site for local development.
toolkit:build-dev-reset Build site for local development from scratch with a clean git.
toolkit:build-dev-reset [tk-bdev-reset] Build site for local development from scratch with a clean git.
toolkit:build-dist [tk-bdist] Build the distribution package.
toolkit:check-phpcs-requirements Make sure that the config file exists and configuration is correct.
toolkit:check-version Check the Toolkit version.
toolkit:code-review This command will execute all the testing tools.
toolkit:complock-check Check if 'composer.lock' exists on the project root folder.
toolkit:component-check Check composer.json for components that are not whitelisted/blacklisted.
toolkit:create-dump Export the local snapshot.
toolkit:download-dump Download ASDA snapshot.
toolkit:create-dump [tk-cdump] Export the local snapshot.
toolkit:download-dump [tk-ddump] Download ASDA snapshot.
toolkit:fix-permissions Run script to fix permissions (experimental).
toolkit:hooks-delete-all Remove all existing hooks, this will ignore active hooks list.
toolkit:hooks-disable Disable the git hooks.
toolkit:hooks-enable Enable the git hooks defined in the configuration or in given option.
toolkit:hooks-list List available hooks and its status.
toolkit:hooks-run Run a specific hook.
toolkit:hooks-delete-all [tk-hdel] Remove all existing hooks, this will ignore active hooks list.
toolkit:hooks-disable [tk-hdis] Disable the git hooks.
toolkit:hooks-enable [tk-hen] Enable the git hooks defined in the configuration or in given option.
toolkit:hooks-list [tk-hlist] List available hooks and its status.
toolkit:hooks-run [tk-hrun] Run a specific hook.
toolkit:import-config [DEPRECATED] Run the Drupal config import.
toolkit:install-clean [tk-iclean] Install a clean website.
toolkit:install-clone [tk-iclone] Install a clone website.
toolkit:install-dependencies Install packages present in the opts.yml file under extra_pkgs section.
toolkit:install-dump Import the production snapshot.
toolkit:lint-js [tljs|tk-js] Run lint JS.
toolkit:lint-php [tlp|tk-php] Run lint PHP.
toolkit:lint-yaml [tly|tk-yaml] Run lint YAML.
toolkit:install-dump [tk-idump] Import the production snapshot.
toolkit:lint-js [tk-js|tljs] Run lint JS.
toolkit:lint-php [tk-php|tlp] Run lint PHP.
toolkit:lint-yaml [tk-yaml|tly] Run lint YAML.
toolkit:opts-review Check project's .opts.yml file for forbidden commands.
toolkit:requirements Check the Toolkit Requirements.
toolkit:run-blackfire [tbf|tk-bfire] Run Blackfire.
toolkit:run-blackfire [tk-bfire|tbf] Run Blackfire.
toolkit:run-deploy Run deployment sequence.
toolkit:run-phpcbf [tk-phpcbf] Run PHP code autofixing.
toolkit:setup-behat Setup the Behat file.
toolkit:setup-blackfire-behat Copy the needed resources to run Behat with Blackfire.
toolkit:setup-eslint Setup the ESLint configurations and dependencies.
toolkit:setup-phpcs Setup PHP code sniffer.
toolkit:setup-phpunit Setup the PHPUnit file.
toolkit:test-behat [tb|tk-behat] Run Behat tests.
toolkit:test-behat [tk-behat|tb] Run Behat tests.
toolkit:test-phpcs [tk-phpcs] Run PHP code sniffer.
toolkit:test-phpmd [tk-phpmd] Run PHPMD.
toolkit:test-phpstan [tk-phpstan] Run PHPStan.
toolkit:test-phpunit [tp|tk-phpunit] Run PHPUnit tests.
toolkit:test-phpunit [tk-phpunit|tp] Run PHPUnit tests.
toolkit:vendor-list Check 'Vendor' packages being monitored.
.. toolkit-block-commands-end
Expand Down
2 changes: 1 addition & 1 deletion phpdoc.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<paths>
<output>docs</output>
</paths>
<version number="10.0.0">
<version number="9.11.0">
<folder>latest</folder>
<api>
<source dsn=".">
Expand Down
2 changes: 1 addition & 1 deletion src/DrupalReleaseHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getPackageDetails(string $package, string $version, string $core

$releaseHistory = $fullReleaseHistory = [];
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type' => 'application/hal+json']);
$result = curl_exec($curl);

Expand Down
2 changes: 1 addition & 1 deletion src/TaskRunner/Commands/BlackfireCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BlackfireCommands extends AbstractCommands
*
* @option endpoint The endpoint to use to connect to QA Website.
*
* @aliases tbf, tk-bfire
* @aliases tk-bfire, tbf
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
Expand Down
8 changes: 5 additions & 3 deletions src/TaskRunner/Commands/BuildCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public function getConfigurationFile()
*
* @command toolkit:build-dist
*
* @aliases tk-bdist
*
* @option root Drupal root.
* @option dist-root Distribution package root.
* @option keep Comma separated list of files and folders to keep.
* @option tag Version tag for manifest.
* @option sha Commit hash for manifest.
*
* @aliases tk-bdist
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand Down Expand Up @@ -228,6 +228,8 @@ public function buildDev(array $options = [
*
* @option root Drupal root.
* @option yes Skip the question.
*
* @aliases tk-bdev-reset
*/
public function buildDevReset(array $options = [
'root' => InputOption::VALUE_REQUIRED,
Expand Down Expand Up @@ -273,7 +275,7 @@ public function buildDevReset(array $options = [
* @option validate Whether to validate or fix the scss.
* @option theme-task-runner The runner to use, one of 'grunt' or 'gulp'.
*
* @aliases tba, tk-assets
* @aliases tk-bassets, tk-assets, tba
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
Expand Down
6 changes: 0 additions & 6 deletions src/TaskRunner/Commands/ComponentCheckCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,6 @@ protected function printComponentResults(ConsoleIO $io)
*/
protected function validateComponent(array $package, array $modules)
{

// Only validate module components for this time.
if (!isset($package['type']) || $package['type'] !== 'drupal-module') {
return;
}

$config = $this->getConfig();
$packageName = $package['name'];
$hasBeenQaEd = isset($modules[$packageName]);
Expand Down
62 changes: 61 additions & 1 deletion src/TaskRunner/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
use Consolidation\AnnotatedCommand\CommandData;
use EcEuropa\Toolkit\TaskRunner\AbstractCommands;
use EcEuropa\Toolkit\Toolkit;
use EcEuropa\Toolkit\Website;
use Robo\Contract\VerbosityThresholdInterface;
use Robo\ResultData;
use Robo\Symfony\ConsoleIO;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -143,7 +147,7 @@ public function drupalPermissionsSetup(array $options = [

$tasks = [
// Note that the chmod() method takes decimal values.
$this->taskFilesystemStack()->chmod($subdirPath, octdec('775'), 0000, true),
$this->taskFilesystemStack()->chmod($subdirPath, octdec('775')),
];

if (file_exists($subdirPath . '/settings.php')) {
Expand Down Expand Up @@ -510,6 +514,62 @@ public function drupalUpgradeStatus(): int
return $qaCompatibilityResult;
}

/**
* Command to check the forbidden permissions.
*
* @param array $options
* Command options.
*
* @command drupal:check-permissions
*
* @option endpoint The endpoint to use to connect to QA Website.
* @option blocker If given and in case of error the command will fail.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function drupalCheckPermissions(ConsoleIO $io, array $options = [
'endpoint' => InputOption::VALUE_REQUIRED,
'blocker' => InputOption::VALUE_NONE,
]): int
{
$blocker = $options['blocker'] === true || $this->getConfig()->get('drupal.permissions.blocker');
if (!empty($options['endpoint'])) {
Website::setUrl($options['endpoint']);
}
if (empty($auth = Website::apiAuth())) {
return ResultData::EXITCODE_ERROR;
}
$data = Website::get(Website::url() . '/api/v1/forbidden-permissions', $auth);
$data = json_decode($data, true);
if (empty($data) || !isset($data['forbidden_permissions'])) {
return ResultData::EXITCODE_ERROR;
}
$forbiddenPermissions = $data['forbidden_permissions'];

$roles = $this->taskExec($this->getBin('drush'))
->arg('role:list')
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_DEBUG)
->run()->getMessage();
$roles = (array) Yaml::parse($roles);

$fail = false;
foreach ($roles as $role) {
foreach ($role['perms'] ?? [] as $permission) {
if (in_array($permission, $forbiddenPermissions)) {
$io->say(sprintf(
"The role '%s' contains a forbidden permission '%s'",
$role['label'],
$permission
));
$fail = true;
}
}
}

return $fail && $blocker ? ResultData::EXITCODE_ERROR : ResultData::EXITCODE_OK;
}

/**
* Remove settings block from given content.
*
Expand Down
6 changes: 6 additions & 0 deletions src/TaskRunner/Commands/DumpCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function getConfigurationFile()
*
* @option dumpfile The dump file name.
* @option myloader If set, MyLoader will be used to import the database.
*
* @aliases tk-idump
*/
public function toolkitInstallDump(ConsoleIO $io, array $options = [
'dumpfile' => InputOption::VALUE_REQUIRED,
Expand Down Expand Up @@ -96,6 +98,8 @@ public function toolkitInstallDump(ConsoleIO $io, array $options = [
* @command toolkit:create-dump
*
* @option dumpfile The dump file name.
*
* @aliases tk-cdump
*/
public function toolkitCreateDump(ConsoleIO $io, array $options = [
'dumpfile' => InputOption::VALUE_REQUIRED,
Expand Down Expand Up @@ -162,6 +166,8 @@ public function toolkitCreateDump(ConsoleIO $io, array $options = [
* @option is-admin For nextcloud admin user.
* @option yes Skip the question to download newer dump.
*
* @aliases tk-ddump
*
* @return \Robo\Collection\CollectionBuilder
* Collection builder.
*
Expand Down
10 changes: 10 additions & 0 deletions src/TaskRunner/Commands/GitHooksCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function getConfigurationFile()
*
* @option hooks The hooks to enable (default: toolkit.hooks.active)
*
* @aliases tk-hen
*
* @usage --hooks=pre-push
*/
public function hooksEnable(ConsoleIO $io, array $options = [
Expand Down Expand Up @@ -90,6 +92,8 @@ public function hooksEnable(ConsoleIO $io, array $options = [
*
* @command toolkit:hooks-disable
*
* @aliases tk-hdis
*
* @option hooks The hooks to disable (default: toolkit.git.hooks)
*/
public function hooksDisable(ConsoleIO $io, array $options = [
Expand Down Expand Up @@ -120,6 +124,8 @@ public function hooksDisable(ConsoleIO $io, array $options = [
* Remove all existing hooks, this will ignore active hooks list.
*
* @command toolkit:hooks-delete-all
*
* @aliases tk-hdel
*/
public function hooksDeleteAll(ConsoleIO $io)
{
Expand All @@ -144,6 +150,8 @@ public function hooksDeleteAll(ConsoleIO $io)
*
* @command toolkit:hooks-list
*
* @aliases tk-hlist
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand Down Expand Up @@ -205,6 +213,8 @@ public function hooksList(ConsoleIO $io)
* The exit code.
*
* @command toolkit:hooks-run
*
* @aliases tk-hrun
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
public function hooksRun(ConsoleIO $io, string $hook, $arg1 = '', $arg2 = '', $arg3 = '')
Expand Down
6 changes: 3 additions & 3 deletions src/TaskRunner/Commands/LintCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function generateEslintConfigurations(string $config, array $options)
* @option extensions The extensions to check.
* @option options Extra options for the command without -- (only options with no value).
*
* @aliases tly, tk-yaml
* @aliases tk-yaml, tly
*
* @usage --extensions='.yml' --options='fix no-eslintrc'
*/
Expand All @@ -173,7 +173,7 @@ public function toolkitLintYaml(array $options = [
* @option extensions The extensions to check.
* @option options Extra options for the command without -- (only options with no value).
*
* @aliases tljs, tk-js
* @aliases tk-js, tljs
*
* @usage --extensions='.js' --options='fix no-eslintrc'
*/
Expand Down Expand Up @@ -233,7 +233,7 @@ private function toolkitRunEsLint(string $config, array $extensions, string $opt
* @option extensions The extensions to check.
* @option options Extra options for the command without -- (only options with no value).
*
* @aliases tlp, tk-php
* @aliases tk-php, tlp
*/
public function toolkitLintPhp(array $options = [
'extensions' => InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
Expand Down
Loading

0 comments on commit 94adb4a

Please sign in to comment.