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

--force doesn't work reliably #105

Open
2 tasks done
slaFFik opened this issue Feb 1, 2025 · 9 comments · May be fixed by #108
Open
2 tasks done

--force doesn't work reliably #105

slaFFik opened this issue Feb 1, 2025 · 9 comments · May be fixed by #108

Comments

@slaFFik
Copy link

slaFFik commented Feb 1, 2025

Bug Report

Describe the current, buggy behavior

--force does not trigger the file override when the .distignore was changed between runs.

Describe how other contributors can replicate this bug

  • create an assets directory in a plugin
  • in the dir create one/ and two/ dir
  • add to the .distignore this line: **/one/
  • run the command: wp dist-archive . ./build --create-target-dir --force
  • zip file is created, it does not have the assets/one dir
  • add to the .distignore this line: **/two/
  • run the command: wp dist-archive . ./build --create-target-dir --force
  • 🐛 zip file is created, it still has the assets/two directory even through it was excluded
  • remove the generated file inside the build/ directory
  • run the command: wp dist-archive . ./build --create-target-dir --force
  • newly created file does not have both assets/one/ and assets/two/

So the problem looks like not with the .distignore processing, but the force overwrite. Even though the cli reports that the file was overwritten - the contents of it was not affected by that change in the .distignore.

Describe what you would expect as the correct outcome

--force always overwrites the file with any changes introduced in .distignore between runs.

Let us know what environment you are running this on

OS:	Darwin 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 arm64
Shell:	/bin/zsh
PHP binary:	/opt/homebrew/Cellar/[email protected]/8.2.27/bin/php
PHP version:	8.2.27
php.ini used:	/opt/homebrew/etc/php/8.2/php.ini
MySQL binary:	/Users/Shared/DBngin/mysql/8.0.27/bin/mysql
MySQL version:	mysql  Ver 8.0.27 for macos11 on arm64 (MySQL Community Server - GPL)
SQL modes:
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/slaffik/Projects/test
WP-CLI packages dir:	/Users/slaffik/.wp-cli/packages/
WP-CLI cache dir:	/Users/slaffik/.wp-cli/cache
WP-CLI global config:	/Users/slaffik/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version:	2.11.0

Provide a possible solution

The logic inside the --force processing (here) seems to be fine.

So I think this is OS-level file-content caching of the .distignore file.

Maybe, use clearstatcache() for this file between runs?

@slaFFik
Copy link
Author

slaFFik commented Feb 1, 2025

At this point, I'm not sure that the whole .distignore file reading logic is working correctly.

I see the PR and discussion around gitignore-checker library update to 1.0.4. And in its tests I see rules that do not work here with the latest version of dist-archive.

For, example, if I include the /build/ line in my .distignore - this directory (although empty) is still included in the resulting zip.

But .git and .github directories are never included, for some reason.

@swissspidy
Copy link
Member

The problem is not with the ignore logic, but the force param doesn‘t exactly do what you might think.

Previously, if the ZIP file already existed, you would get a prompt to overwrite it. If selecting no, the command would exit. Otherwise it rund the zip command. The force param simply skips that prompt.

The problem: if you run the zip program and the destination file already exists, it simply adds new files to it and it doesn‘t delete old ones.

I think we need to pass the -FS (filesync) argument to the zip command, see https://linux.die.net/man/1/zip

@slaFFik
Copy link
Author

slaFFik commented Feb 2, 2025

This, or just drop the zip file before creating a new one if --force is set.
wp dist-archive is running long enough on a small plugin anyways, so no one will even notice that speed difference.

@swissspidy
Copy link
Member

I prefer simply passing an argument for a speed gain :-)

@swissspidy swissspidy linked a pull request Feb 2, 2025 that will close this issue
@swissspidy
Copy link
Member

#108 should fix this, if you wanna give it a try.

@slaFFik
Copy link
Author

slaFFik commented Feb 2, 2025

@swissspidy I found this doc to checkout locally everything, but I don't understand how to run a global wp dist-archive command from a code inside my checked out dir.
Could you please help me understand that?

@slaFFik
Copy link
Author

slaFFik commented Feb 2, 2025

Also, I tried running composer behat, from here, but got this:

> run-behat-tests
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Script run-behat-tests handling the behat event returned with error code 1

I'm using valet, and TablePlus to manage users, and MySQL 8, and PHP 8.2 as my default PHP version.

@swissspidy
Copy link
Member

If you check out only this repository and run wp dist-archive in that directory, it should actually use the version from the checkout. Alternatively, vendor/bin/wp should work also.

If you want to run composer behat, you first need to run composer prepare-tests to set up the database. Alternatively you can run with WP_CLI_TEST_DBTYPE=sqlite composer behat to run without MySQL setup. That should work fine in this case.

@slaFFik
Copy link
Author

slaFFik commented Feb 2, 2025

I tried composer prepare-tests, but it failed as well, as it needs to connect to MySQL from a socket file. I already created db, user, etc, so I don't think this is even needed. Thanks for the sqlite tip.

Trying to figure out how to run the command from the branch while zip'ing a plugin located elsewhere :)

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

Successfully merging a pull request may close this issue.

2 participants