Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise build script #15

Open
remcotolsma opened this issue Aug 2, 2024 · 1 comment
Open

Revise build script #15

remcotolsma opened this issue Aug 2, 2024 · 1 comment

Comments

@remcotolsma
Copy link
Member

remcotolsma commented Aug 2, 2024

I had to use a custom build script in the WordPress plugin "Pronamic Pay with Rabo Smart Pay for WooCommerce", because the WordPress.org plugin review team did not allow certain files in the build.

https://github.com/pronamic/pronamic-pay-with-rabo-smart-pay-for-woocommerce/blob/14eea88aa9a4fb62e5b0a149ca0effe41bf7ea91/build/scripts/build.php#L1-L34

I had to split the build into 2 steps/stages.

$slug = 'pronamic-pay-with-rabo-smart-pay-for-woocommerce';

$src_dir       = realpath( __DIR__ . '/../../' );
$build_dir     = realpath( __DIR__ . '/../' );
$stage_1_dir   = $build_dir . '/stage-1';
$stage_2_dir   = $build_dir . '/stage-2';
$artifacts_dir = $build_dir . '/artifacts';

echo $src_dir, PHP_EOL;
echo $build_dir, PHP_EOL;
echo $stage_1_dir, PHP_EOL;
echo $stage_2_dir, PHP_EOL;

run_command( "rm -rf $stage_1_dir" );
run_command( "rm -rf $stage_2_dir" );

run_command( "mkdir $stage_1_dir" );
run_command( "mkdir $stage_2_dir" );

run_command( "rsync --recursive --verbose --exclude-from=$build_dir/scripts/stage-1-ignore.txt --exclude-from=.distignore $src_dir/ $stage_1_dir/" );

run_command( "composer install --no-dev --prefer-dist --optimize-autoloader --working-dir=$stage_1_dir" );

run_command( "rsync --recursive --verbose --exclude-from=.distignore $stage_1_dir/ $stage_2_dir/" );

run_command( "vendor/bin/phpcbf -s -v --standard=$build_dir/scripts/phpcs-text-domain-fixer.xml $stage_2_dir", null );

run_command( "vendor/bin/wp i18n make-pot $stage_2_dir --slug=$slug" );

run_command( "vendor/bin/wp dist-archive $stage_2_dir $artifacts_dir/ --create-target-dir --plugin-dirname=$slug" );

The problem in this tool is dat composer install --no-dev --prefer-dist --optimize-autoloader can still install files that are not allowed:

// Composer.
$io->section( 'Composer' );
$io->text( 'The build command installs the required Composer libraries.' );
$command = \sprintf(
'composer install --no-dev --prefer-dist --optimize-autoloader --working-dir=%s',
$build_dir
);
$process = Process::fromShellCommandline( $command );
$helper->mustRun( $output, $process );

To work around this I perform a second rsync call to again exclude the .distignore paths, for this I use 2 folders:

  • build/stage-1
  • build/stage-2

In this tool it's currently just one:

  • build/project

  1. rsync --recursive --verbose --exclude-from=$build_dir/scripts/stage-1-ignore.txt --exclude-from=.distignore $src_dir/ $stage_1_dir/
  2. composer install --no-dev --prefer-dist --optimize-autoloader --working-dir=$stage_1_dir
  3. rsync --recursive --verbose --exclude-from=.distignore $stage_1_dir/ $stage_2_dir/
  4. vendor/bin/phpcbf -s -v --standard=$build_dir/scripts/phpcs-text-domain-fixer.xml $stage_2_dir
  5. vendor/bin/wp i18n make-pot $stage_2_dir --slug=$slug
  6. vendor/bin/wp dist-archive $stage_2_dir $artifacts_dir/ --create-target-dir --plugin-dirname=$slug

It would be nice if this tool could be adapted to work in a similar way.

@rvdsteege
Copy link
Member

Untested, command to remove all paths listed in a .distignore file (ignoring lines starting with # — comments — and empty lines):

grep -v '^#' .distignore | grep -v '^$' | xargs rm -rf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants