wp-cli / dist-archive-command

Create a distribution .zip or .tar.gz based on a plugin or theme's .distignore file
https://developer.wordpress.org/cli/commands/dist-archive/
MIT License
47 stars 23 forks source link

Incorrect version number used when creating zip archive #92

Open brianhogg opened 3 months ago

brianhogg commented 3 months ago

Bug Report

Describe the current, buggy behavior

It looks like if there's a PHP file with a PHPdoc version number in the header like this, in a class file in the root folder of the plugin that isn't the main plugin file, it will be used instead of the actual plugin version number:

/**
 * Class file
 * 
 * @version 7.2.0
 */

Describe how other contributors can replicate this bug

<?php
/**
 * Main LifterLMS plugin file
 *
 * @package LifterLMS/Main
 *
 * @since 1.0.0
 * @version 5.3.0
 *
 * Plugin Name: LifterLMS
 * Plugin URI: https://lifterlms.com/
 * Description: Complete e-learning platform to sell online courses, protect lessons, offer memberships, and quiz students.
 * Version: 7.6.0
 * Author: LifterLMS
 * Author URI: https://lifterlms.com/
 * Text Domain: lifterlms
 * Domain Path: /languages
 * License: GPLv3
 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
 * Requires at least: 5.9
 * Tested up to: 6.5
 * Requires PHP: 7.4
 *
 * * * * * * * * * * * * * * * * * * * * * *
 *                                         *
 * Reporting a Security Vulnerability      *
 *                                         *
 * Please disclose any security issues or  *
 * vulnerabilities to team@lifterlms.com   *
 *                                         *
 * See our full Security Policy at         *
 * https://lifterlms.com/security-policy   *
 *                                         *
 * * * * * * * * * * * * * * * * * * * * * *
 */
<?php
/**
 * Main LifterLMS class
 *
 * @package LifterLMS/Main
 *
 * @since 1.0.0
 * @version 7.2.0
 */

Expected

Creates zip archive with name lifterlms.7.6.0.zip

Actual

Creates zip archive with name liftrerlms.7.2.0.zip

Let us know what environment you are running this on

OS: Darwin 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030 x86_64
Shell:  /bin/zsh
PHP binary: /usr/local/Cellar/php@8.2/8.2.18/bin/php
PHP version:    8.2.18
php.ini used:   /usr/local/etc/php/8.2/php.ini
MySQL binary:   /usr/local/bin/mysql
MySQL version:  mysql  Ver 8.1.0 for macos14.0 on x86_64 (Homebrew)
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/brianhogg/laravel/lifter2/wp-content/plugins/lifterlms
WP-CLI packages dir:    /Users/brianhogg/.wp-cli/packages/
WP-CLI cache dir:   /Users/brianhogg/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.10.0

Provide a possible solution

Other than removing the @version 7.2.0 header in the other class file I'm not sure a fix without checking the code that fetches the plugin version number. Likely just needs a tweak to what it's looking for to ignore @version but grab Version:

danielbachhuber commented 3 months ago

Thanks for the report, @brianhogg ! This seems like a genuine bug.

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.