Page MenuHomePhabricator

CI should run `pear package-validate` for PHP extensions with package.xml files
Open, Needs TriagePublic

Description

LuaSandbox is now in PECL, and has a package.xml file. We should run the validator (pear package-validate) to ensure it's valid (doesn't catch everything, but better than nothing).

Event Timeline

Legoktm changed the task status from Open to Stalled.Jan 22 2019, 7:59 AM

I intentionally introduced an error in package.xml, and ran the validator:

km@km-pt:/srv/mediawiki/php/luasandbox$ pear package-validate
Error: Invalid tag order in <lead>, found <active> expected one of "user"
Validation: 1 error(s), 0 warning(s)

km@km-pt:/srv/mediawiki/php/luasandbox$ echo $?
0

...so there's no exit code upon error, wonderful. Also the PEAR website is down so I can't file a bug. Meh.

I went with throwing an exception in the validation function:

$ pear package-validate
PHP Fatal error:  Uncaught Exception in /usr/share/php/PEAR/PackageFile/v2/Validator.php:60
Stack trace:
#0 /usr/share/php/PEAR/PackageFile/v2.php(1938): PEAR_PackageFile_v2_Validator->validate(Object(PEAR_PackageFile_v2), 3)
#1 /usr/share/php/PEAR/Command/Package.php(388): PEAR_PackageFile_v2->validate(3)
#2 /usr/share/php/PEAR/Command/Common.php(270): PEAR_Command_Package->doPackageValidate('package-validat...', Array, Array)
#3 /usr/share/php/pearcmd.php(316): PEAR_Command_Common->run('package-validat...', Array, Array)
#4 {main}
  thrown in /usr/share/php/PEAR/PackageFile/v2/Validator.php on line 60

The trace leads to:

/usr/share/php/PEAR/Command/Package.php
function doPackageValidate($command, $options, $params)
{
...
        $valid = false;
        if ($info->getPackagexmlVersion() == '2.0') {
            if ($valid = $info->validate(PEAR_VALIDATE_NORMAL)) {
                $info->flattenFileList();
                $valid = $info->validate(PEAR_VALIDATE_PACKAGING);
            }
        } else {
            $valid = $info->validate(PEAR_VALIDATE_PACKAGING);
        }

        $err = $warn = array();
        if ($errors = $info->getValidationWarnings()) {
            foreach ($errors as $error) {
                if ($error['level'] == 'warning') {
                    $warn[] = $error['message'];
                } else {
                    $err[] = $error['message'];
                }
            }
        }

        $this->_displayValidationResults($err, $warn);
        $this->ui->outputData($this->output, $command);
        return true;
    }
}

It unconditionally returns true, should probably return $valid instead though that is set to int(0) and that is not recognized as an error by PEAR::isError() ... So yeah it is broken :)

based on Debian Stretch package 1:1.10.1+submodules+notgz-9

Proposed workaround:

km@km-pt ~/g/m/p/luasandbox> pear package-validate | tee validation
Error: Invalid tag order in <lead>, found <active> expected one of "user"
Validation: 1 error(s), 0 warning(s)

km@km-pt ~/g/m/p/luasandbox> grep "0 error" validation 
(1) km@km-pt ~/g/m/p/luasandbox> echo $status
1
Legoktm changed the task status from Stalled to Open.Jul 10 2019, 6:40 PM