Skip to content

diff command in custom recipe causes deployment process to exit #2903

Description

@stsonline
  • Deployer version: 6.8
  • Deployment OS: to cent OS 7

My deploy.php file references a custom recipe that I've built taking inspiration from one of the older NPM recipes. It's to run a composer install much like the npm install but only if the composer.json file is different from the previous release to prevent having to always run it, resulting in faster deployments.

My custom recipe is running the task, but the diff command is causing an exit code 1 which is causing the whole deployment process to exit despite this being the correct error code for the diff command, the exit code 1 implies that the files are different, which they are, so why is Deployer failing on this instead of running my install?

My [my_project]/deploy/recipe/sts-composer.php

<?php
/*
 * Custom composer recipe for us.
 */

namespace Deployer;

set('bin/composer', function () {
    return run('which composer');
});

desc('Install composer packages');
task('composer:install', function () {
    if (has('previous_release')) {
        if (test('[ -d {{previous_release}}/vendor ]')) {
            run('cp -R {{previous_release}}/vendor {{release_path}}');

            // If composer.json is unmodified, then skip running `composer install`
            if (!run('diff {{previous_release}}/composer.json {{release_path}}/composer.json')) {
                return;
            }
        }
    }
    run("cd {{release_path}} && {{bin/composer}} install");
});

This is then loaded into my [my_project]/deploy.php file

<?php
namespace Deployer;

require 'deploy/recipe/sts-composer.php';
...

Screenshot 2022-01-17 at 14 58 21

Thoughts on how to resolve as a workaround for Deployer 6.8 please.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions