Skip to content

Commit

Permalink
Sync development (#16)
Browse files Browse the repository at this point in the history
* License normalization
    - remove license text in every file
    - rewording in README
    - year in LICENSE
* Add support for custom env config files in 'vip-composer-plugin-env-config' packages (#14)
* Fix copyright in LICENSE
* Add "preprod" as standard env name
* Add 'develop' to default envConfigs

---------

Signed-off-by: Giuseppe Mazzapica <[email protected]>
Co-authored-by: Viktor Kuliebiakin <[email protected]>
  • Loading branch information
gmazzap and kuliebiakin authored Mar 21, 2024
1 parent f767eaf commit c84c73c
Show file tree
Hide file tree
Showing 42 changed files with 282 additions and 460 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/quality-assurance-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run lint only')) }}
strategy:
matrix:
php: [ "8.0", "8.1", "8.2" ]
php: [ "8.0", "8.1", "8.2", "8.3" ]
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
with:
PHP_VERSION: ${{ matrix.php }}
Expand All @@ -49,8 +49,8 @@ jobs:
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run Psalm only')) }}
strategy:
matrix:
php: [ "8.0", "8.1", "8.2" ]
php: [ "8.0", "8.1", "8.2", "8.3" ]
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
with:
PHP_VERSION: ${{ matrix.php }}
PSALM_ARGS: --output-format=github --no-suggestions --no-cache --no-diff --find-unused-psalm-suppress --php-version=${{ matrix.php }}
PSALM_ARGS: --output-format=github --no-suggestions --no-cache --no-diff --find-unused-psalm-suppress
8 changes: 3 additions & 5 deletions .github/workflows/unit-tests-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ jobs:
strategy:
fail-fast: false
matrix:
php-ver: [ '8.0', '8.1', '8.2' ]
php-ver: [ '8.0', '8.1', '8.2', '8.3' ]
composer: [ '2.4', '2.5', '2.6', '2' ]
dependency-versions: [ 'lowest', 'highest' ]
exclude:
- composer: '2'
dependency-versions: 'lowest'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -50,9 +47,10 @@ jobs:
composer require "composer/composer:~${{ matrix.composer }}.0" --dev --no-update
- name: Install dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependency-versions }}
tools: composer:v${{ matrix.composer-ver }}

- name: Run unit tests
run: ./vendor/bin/phpunit --no-coverage
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Syde GmbH
Copyright (c) 2024 Syde GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ The whole set of settings available, with their defaults, looks like this:
"vip-config-dir": "vip-config",
"config-dir": "config",
"private-dir": "private"
}
},
"custom-env-names": [
]
}
}
}
Expand Down Expand Up @@ -289,6 +291,14 @@ Only the `config/vip-config.php` is mandatory all the other folders and their co
`vip-composer.dev-paths` controls the name of those folders. By default names are the same names used by VIP Go repository, except for `mu-plugins/` is renamed to `client-mu-plugins/`.


#### `vip-composer.custom-env-names`

VIP expects WordPress configuration normally placed in `wp-config.php` (e.g. constants with secrets) to be placed in a `vip-config.php` file. To help having environment-specific setting, this package support multiple files where to set such configuration, where each file is environment-specific and named after the environment.
The configuration files can be placed directly in the `./vip-config/` folder in a "website repository" root folder, or can be placed in separate Composer packages having the `vip-composer-plugin-env-config` type, whose support is handled by this package.
In the latter case, the supported files that are copied over from packages into website config folder are, by default, those named after the environments supported by WordPress core, and they are: `local.php`, `development.php`, `staging.php`, and `production.php`, plus a file named `all.php`aimed at target all environments.
Considering VIP GO allows us to have more environments or anyway name them differently, it is possible to expand the list of supported files names via the `vip-composer.custom-env-names` configuration.



## Folder structure *after* the command runs

Expand Down Expand Up @@ -678,6 +688,9 @@ composer vip --vip-dev-env
vip dev-env create --app-code="./vip"
```

## Copyright
## License and Copyright

_VIP Composer Plugin_ is a free software, and is released under the terms of the MIT license.
See [LICENSE](./LICENSE) for complete license.

This repository is a free software, and is released under the terms of the MIT license. See [LICENSE](./LICENSE) for complete license.
The team at Syde is engineering the Web since 2006.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"require-dev": {
"composer/composer": "^2.4",
"inpsyde/php-coding-standards": "^2@dev",
"vimeo/psalm": "^5.15.0",
"phpunit/phpunit": "^9.6.11"
"vimeo/psalm": "^5.23.1",
"phpunit/phpunit": "^9.6.17"
},
"autoload": {
"psr-4": {
Expand All @@ -47,7 +47,7 @@
},
"scripts": {
"phpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-cache --show-info=false --no-progress",
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-suggestions --report-show-info=false --find-unused-psalm-suppress --no-diff --no-cache --no-file-cache --output-format=compact",
"tests": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
"tests:coverage": "@php ./vendor/phpunit/phpunit/phpunit --coverage-clover",
"qa": [
Expand Down
16 changes: 2 additions & 14 deletions src/Command.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/**
* This file is part of the vip-composer-plugin package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Inpsyde\VipComposer;
Expand Down Expand Up @@ -162,12 +153,9 @@ protected function configure(): void
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*
* phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
// phpcs:enable Inpsyde.CodeQuality.ReturnTypeDeclaration
try {
$this->resetComposer();
$composer = $this->requireComposer();
Expand All @@ -186,8 +174,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
->addTask($taskFactory->downloadWpCore())
->addTask($taskFactory->downloadVipGoMuPlugins())
->addTask($taskFactory->symlinkVipGoDir())
->addTask($taskFactory->copyDevPaths())
->addTask($taskFactory->copyEnvConfig())
->addTask($taskFactory->copyDevPaths())
->addTask($taskFactory->generateMuPluginsLoader())
->addTask($taskFactory->generateProductionAutoload())
->addTask($taskFactory->updateLocalWpConfigFile())
Expand Down
63 changes: 44 additions & 19 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/**
* This file is part of the vip-composer-plugin package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Inpsyde\VipComposer;
Expand Down Expand Up @@ -53,6 +44,8 @@ final class Config implements \ArrayAccess
public const DEV_PATHS_YAML_CONFIG_DIR_KEY = 'config-dir';
public const DEV_PATHS_PRIVATE_DIR_KEY = 'private-dir';

public const CUSTOM_ENV_NAMES_KEY = 'custom-env-names';

public const PACKAGE_TYPE_MULTI_MU_PLUGINS = 'wordpress-multiple-mu-plugins';

public const DEFAULTS = [
Expand Down Expand Up @@ -83,6 +76,7 @@ final class Config implements \ArrayAccess
self::DEV_PATHS_YAML_CONFIG_DIR_KEY => 'config',
self::DEV_PATHS_PRIVATE_DIR_KEY => 'private',
],
self::CUSTOM_ENV_NAMES_KEY => [],
];

private array $config;
Expand All @@ -94,7 +88,7 @@ final class Config implements \ArrayAccess
*/
public function __construct(Composer $composer, string $basePath)
{
$extra = (array)($composer->getPackage()->getExtra()[self::CONFIG_KEY] ?? []);
$extra = (array) ($composer->getPackage()->getExtra()[self::CONFIG_KEY] ?? []);
$this->composerConfig = $composer->getConfig();

$this->config = [];
Expand All @@ -114,15 +108,15 @@ public function __construct(Composer $composer, string $basePath)
*/
public function basePath(): string
{
return (string)$this->offsetGet(self::BASE_PATH_KEY);
return (string) $this->offsetGet(self::BASE_PATH_KEY);
}

/**
* @return string
*/
public function prodAutoloadDir(): string
{
return (string)$this->offsetGet(self::PROD_AUTOLOAD_DIR_KEY);
return (string) $this->offsetGet(self::PROD_AUTOLOAD_DIR_KEY);
}

/**
Expand All @@ -131,7 +125,7 @@ public function prodAutoloadDir(): string
*/
public function composerConfigValue(string $key): string
{
return (string)$this->composerConfig->get($key);
return (string) $this->composerConfig->get($key);
}

/**
Expand All @@ -143,47 +137,78 @@ public function composerLockPath(): string
$configSource = $this->composerConfig->getConfigSource();
$composerJsonSource = $configSource->getName();

return (string)preg_replace('~\.json$~', '.lock', $composerJsonSource, 1);
return (string) preg_replace('~\.json$~', '.lock', $composerJsonSource, 1);
}

/**
* @return array
*/
public function vipConfig(): array
{
return (array)$this->offsetGet(self::VIP_CONFIG_KEY);
return (array) $this->offsetGet(self::VIP_CONFIG_KEY);
}

/**
* @return array
*/
public function gitConfig(): array
{
return (array)$this->offsetGet(self::GIT_CONFIG_KEY);
return (array) $this->offsetGet(self::GIT_CONFIG_KEY);
}

/**
* @return array
*/
public function wpConfig(): array
{
return (array)$this->offsetGet(self::WP_CONFIG_KEY);
return (array) $this->offsetGet(self::WP_CONFIG_KEY);
}

/**
* @return array
*/
public function pluginsAutoloadConfig(): array
{
return (array)$this->offsetGet(self::PLUGINS_AUTOLOAD_KEY);
return (array) $this->offsetGet(self::PLUGINS_AUTOLOAD_KEY);
}

/**
* @return array
*/
public function devPathsConfig(): array
{
return (array)$this->offsetGet(self::DEV_PATHS_CONFIG_KEY);
return (array) $this->offsetGet(self::DEV_PATHS_CONFIG_KEY);
}

/**
* @return list<non-empty-string>
*/
public function envConfigs(): array
{
$customEnvs = (array) $this->offsetGet(self::CUSTOM_ENV_NAMES_KEY);
if ($customEnvs === []) {
/*
* WordPress supports by default: `local`, `development`, `staging`, and `production`.
* VIP supports by default: `develop`, `preprod`, and `production`.
* This list targets both for larger by-default compatibility.
*/
return ['local', 'develop', 'development', 'staging', 'preprod', 'production', 'all'];
}
$envNames = [];
foreach ($customEnvs as $envName) {
if (!is_string($envName)) {
continue;
}
$envName = trim(strtolower($envName));
if (
preg_match('~^[a-z][a-z0-9_\.\-]+$~', $envName)
&& !in_array($envName, $envNames, true)
) {
$envNames[] = $envName;
}
}
/** @var list<non-empty-string> $envNames */
return $envNames;
}

/**
Expand Down
9 changes: 0 additions & 9 deletions src/Factory.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/**
* This file is part of the vip-composer-plugin package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Inpsyde\VipComposer;
Expand Down
9 changes: 0 additions & 9 deletions src/Git/EnsureGitIgnore.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/**
* This file is part of the vip-composer-plugin package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Inpsyde\VipComposer\Git;
Expand Down
13 changes: 2 additions & 11 deletions src/Git/GitProcess.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/**
* This file is part of the vip-composer-plugin package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Inpsyde\VipComposer\Git;
Expand Down Expand Up @@ -44,8 +35,8 @@ public function __construct(
ProcessExecutor $executor = null
) {

$cwd = $workingDir ?: getcwd();
if (!$cwd) {
$cwd = $workingDir ?? getcwd();
if ($cwd === false) {
throw new \Exception('Could not determine current dir');
}

Expand Down
Loading

0 comments on commit c84c73c

Please sign in to comment.