Skip to content

Commit

Permalink
Merge pull request #31 from alleyinteractive/remove-wp-cli
Browse files Browse the repository at this point in the history
Remove wp-cli dependency/fix installation error
  • Loading branch information
srtfisher authored Aug 27, 2022
2 parents 8fb089f + 6016eb7 commit cedf5b1
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 94 deletions.
44 changes: 4 additions & 40 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,12 @@ name: Coding Standards

on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [7.4]
name: PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v3
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ matrix.php }}-composer-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
tools: composer:v2
coverage: none
- name: Validate Composer
run: composer validate --strict
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer install
- name: Run phpcs
run: composer run phpcs
coding-standards:
uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main
42 changes: 8 additions & 34 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,19 @@ name: Testing Suite

on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
tests:
runs-on: ubuntu-latest
php-tests:
strategy:
fail-fast: true
matrix:
php: [7.4, 8.0]
name: PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Set up Composer caching
uses: actions/cache@v3
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ matrix.php }}-composer-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
tools: composer:v2
coverage: none
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer install
- name: Run phpunit
run: composer run phpunit
wordpress: ["latest"]
uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main
with:
php: ${{ matrix.php }}
wordpress: ${{ matrix.wordpress }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.vscode/
composer.lock
.phpunit.result.cache
.DS_Store
Binary file added bin/wp-cli.phar
Binary file not shown.
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"require": {
"php": "^7.4|^8.0",
"symfony/console": "^5.0",
"symfony/process": "^5.0",
"wp-cli/core-command": "^2.0",
"wp-cli/wp-cli": "^2.4"
"symfony/process": "^5.0"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^0.3",
Expand All @@ -37,6 +35,10 @@
],
"scripts": {
"phpcs": "phpcs --standard=./phpcs.xml .",
"phpunit": "phpunit"
"phpunit": "phpunit",
"test": [
"@phpcs",
"@phpunit"
]
}
}
2 changes: 2 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

<rule ref="Alley-Interactive">
<exclude name="WordPress.WP.AlternativeFunctions" />
<exclude name="Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure" />
<exclude name="WordPress.NamingConventions.PrefixAllGlobals" />
</rule>
</ruleset>
43 changes: 28 additions & 15 deletions src/class-install-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/**
* Install_Command class file.
*
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
*
* @package Mantle
*/

Expand All @@ -28,11 +26,11 @@ protected function configure() {
$this->setName( 'new' )
->setDescription( 'Create a new Mantle application' )
->addArgument( 'name', InputOption::VALUE_OPTIONAL, 'Name of the folder to install WordPress in, optional.', null )
->addOption( 'dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release' )
->addOption( 'force', 'f', InputOption::VALUE_NONE, 'Install even if the directory already exists' )
->addOption( 'install', 'i', InputOption::VALUE_NONE, 'Install WordPress in the current location if it doesn\'t exist.' )
->addOption( 'no-must-use', 'no-mu', InputOption::VALUE_OPTIONAL, 'Don\'t load Mantle as a must-use plugin.', false )
->addOption( 'setup-dev', null, InputOption::VALUE_NONE, 'Setup mantle for development on the framework.' );
->addOption( 'dev', 'd', InputOption::VALUE_NONE, 'Setup mantle for development on the framework.' )
->addOption( 'setup-dev', null, InputOption::VALUE_NONE, '(Legacy) setup mantle for development on the framework.' );
}

/**
Expand Down Expand Up @@ -179,21 +177,27 @@ protected function install_wordpress( string $dir, InputInterface $input, Output
* @return string
*/
protected function find_wp_cli(): string {
// Check if the wp-cli path was set in an environment variable.
if ( $wp_cli = getenv( 'WP_CLI_PATH' ) ) {
return $wp_cli;
}

$path = getcwd() . '/wp-cli.phar';

if ( file_exists( $path ) ) {
return '"' . PHP_BINARY . '" ' . $path;
}

$paths = [
__DIR__ . '/../vendor/wp-cli/wp-cli/bin/wp',
__DIR__ . '/../../../wp-cli/wp-cli/bin/wp',
];
// Check if wp-cli is installed globally.
$path = exec( 'which wp' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec

foreach ( $paths as $path ) {
if ( file_exists( $path ) ) {
return $path;
}
if ( $path ) {
return $path;
}

// Fallback to the one installed with the package.
if ( file_exists( __DIR__ . '/../bin/wp-cli.phar' ) ) {
return '"' . PHP_BINARY . '" ' . __DIR__ . '/../bin/wp-cli.phar';
}

return 'wp';
Expand All @@ -205,6 +209,11 @@ protected function find_wp_cli(): string {
* @return string
*/
protected function find_composer(): string {
// Check if the composer path was set in an environment variable.
if ( $composer = getenv( 'COMPOSER_PATH' ) ) {
return $composer;
}

$composer_path = getcwd() . '/composer.phar';

if ( file_exists( $composer_path ) ) {
Expand Down Expand Up @@ -268,16 +277,20 @@ protected function install_mantle( string $dir, InputInterface $input, OutputInt
];

// Setup the application for local development on the framework.
if ( $input->getOption( 'setup-dev' ) ) {
if ( $input->getOption( 'dev' ) || $input->getOption( 'setup-dev' ) ) {
if ( is_dir( $framework_dir ) && file_exists( "{$framework_dir}/composer.json" ) ) {
throw new RuntimeException( "Mantle Framework is already installed: [{$framework_dir}'" );
}

$commands = [
"git clone [email protected]:alleyinteractive/mantle-framework.git {$framework_dir}",
"git clone https://github.com/alleyinteractive/mantle-framework.git {$framework_dir}",
"cd {$framework_dir} && git remote set-url origin [email protected]:alleyinteractive/mantle-framework.git",
"cd {$framework_dir} && composer install",
"git clone [email protected]:alleyinteractive/mantle.git {$mantle_dir}",
"git clone https://github.com/alleyinteractive/mantle.git {$mantle_dir}",
"cd {$framework_dir} && git remote set-url origin [email protected]:alleyinteractive/mantle.git",
"cd {$mantle_dir} && composer config repositories.mantle-framework '{\"type\": \"path\", \"url\": \"../{$name}-framework\", \"options\": {\"symlink\": true}}' --file composer.json",
// Update Mantle to accept any version of these dependencies.
"cd {$mantle_dir} && composer require alleyinteractive/mantle-framework:\"*\" alleyinteractive/composer-wordpress-autoloader:\"*\" --no-update --no-scripts",
"cd {$mantle_dir} && composer install --no-scripts",
];
}
Expand Down
46 changes: 45 additions & 1 deletion tests/test-install-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
use Throwable;

class Test_Install_Command extends TestCase {
public function test_install_wordpress() {
protected function setUp(): void {
parent::setUp();

$output = __DIR__ . '/output';

if ( is_dir( $output . '/new-site' ) ) {
exec( 'rm -rf ' . $output . '/new-site' );
}

if ( is_dir( $output . '/new-site-dev' ) ) {
exec( 'rm -rf ' . $output . '/new-site-dev' );
}
}

public function test_install_wordpress() {
$output = __DIR__ . '/output';

chdir( $output );

$tester = $this->get_tester();
Expand All @@ -41,6 +51,40 @@ public function test_install_wordpress() {
$this->assertFileExists( "{$output}/new-site/wp-content/mu-plugins/new-site-loader.php" );
}

public function test_install_wordpress_dev() {
$output = __DIR__ . '/output';

chdir( $output );

$tester = $this->get_tester();

try {
$status_code = $tester->execute(
[
'name' => [ 'new-site-dev' ],
'--install' => true,
'--force' => true,
'--dev' => true,
],
[
'i',
'f',
'd',
]
);
} catch ( Throwable $e ) {
echo $tester->getDisplay( true );
throw $e;
}

$this->assertEquals( 0, $status_code );
$this->assertDirectoryExists( "{$output}/new-site-dev" );
$this->assertFileExists( "{$output}/new-site-dev/wp-settings.php" );
$this->assertFileExists( "{$output}/new-site-dev/wp-content/plugins/new-site-dev/mantle.php" );
$this->assertFileExists( "{$output}/new-site-dev/wp-content/plugins/new-site-dev-framework/composer.json" );
$this->assertFileExists( "{$output}/new-site-dev/wp-content/mu-plugins/new-site-dev-loader.php" );
}

protected function get_tester(): CommandTester {
$app = new Application( 'Mantle Installer' );
$app->add( new Install_Command() );
Expand Down

0 comments on commit cedf5b1

Please sign in to comment.