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

Deployer detects wrong version when using composer global bin #1842

Closed
seriquynh opened this issue May 14, 2019 · 5 comments
Closed

Deployer detects wrong version when using composer global bin #1842

seriquynh opened this issue May 14, 2019 · 5 comments

Comments

@seriquynh
Copy link
Contributor

Q A
Issue Type Bug
Deployer Version v6.4.3
Local Machine OS Ubuntu 16.04
Remote Machine OS Ubuntu 16.04

Description

Deployer detects wrong version when using composer global bin.

I installed deployer/deployer package as a global composer package instead of using deployer.phar file.

$ composer global show deployer/deployer # Show the installed information of deployer
Changed current directory to /home/xuanquynh/.composer
name     : deployer/deployer
descrip. : Deployment Tool
keywords : 
versions : * v6.4.3
type     : library
$ which dep # Find the executable file
/home/xuanquynh/.composer/vendor/bin/dep
$ dep --version
Deployer master

Steps to reproduce

  1. Install deployer as a global composer package.
$ composer global require deployer/deployer
  1. Export the composer bin dir to the PATH environment variable.
$ export PATH="$HOME/.composer/bin:$PATH"
  1. Execute dep command with the '--version' option.
$ dep --version

Expected: "Deployer {{expected_version}}"

Actual: "Deployer master"

Output log

This isn't a bug about deploying, so I just try to describe the problem above.

Suggestion

I think we may use vendor/composer/installed.json file instead of composer.lock file.

Quickly refer this line for more details.

$composerLockFile = $deployFilePath . '/composer.lock';

It's simply solved by the code sample below:

<?php

$autoload = [
    $deployFilePath . '/vendor/autoload.php',
    __DIR__ . '/../../../autoload.php',
    __DIR__ . '/../vendor/autoload.php'
];

$includes = [
    $deployFilePath . '/vendor/deployer/deployer',
    __DIR__ . '/../../../deployer/deployer',
    __DIR__ . '/../'
];

$loaded = false;
$includePath = false;

for ($i = 0; $i < count($autoload); $i++) {
    if (file_exists($autoload[$i]) && file_exists($includes[$i])) {
        require $autoload[$i];
        $vendorDir = dirname($autoload[$i]);
        $includePath = $includes[$i];
        $loaded = true;
        break;
    }
}

// Detect version
$version = 'master';

$installedFile = $vendorDir.'/composer/installed.json';
if (is_readable($installedFile)) {
    $packages = json_decode(file_get_contents($installedFile), true);
    foreach ($packages as $package) {
        if ($package['name'] === 'deployer/deployer') {
            $version = $package['version'];
            break;
        }
    }
}
@seriquynh
Copy link
Contributor Author

Please correct me if I miss something. Thank you!

@antonmedv
Copy link
Member

Nice. I think we can use it.

@seriquynh
Copy link
Contributor Author

@antonmedv Can I help to create a pull request? I have to target "master" branch, don't I?

@antonmedv
Copy link
Member

Yes, master.

@seriquynh
Copy link
Contributor Author

This issue is solved.

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