diff --git a/tasks/deploy/publish.js b/tasks/deploy/publish.js index 31c5fdd..7063173 100644 --- a/tasks/deploy/publish.js +++ b/tasks/deploy/publish.js @@ -27,8 +27,23 @@ module.exports = function (gruntOrShipit) { var relativeReleasePath = path.join('releases', shipit.releaseDirname); - return shipit.remote('cd ' + shipit.config.deployTo + ' && ln -nfs ' + relativeReleasePath + ' current') - .then(function () { + return shipit.remote( + 'cd ' + shipit.config.deployTo + ' && ' + + 'if [[ -d current && ! (-L current) ]]; then ' + + 'echo \"ERR: could not make symlink\"; ' + + 'else ' + + 'ln -nfs ' + relativeReleasePath + ' current_tmp && ' + + 'mv -fT current_tmp current; ' + + 'fi' + ) + .then(function (res) { + var failedresult = res ? res.stdout.filter(function(r) { + return r.indexOf('could not make symlink') > -1; + }) : []; + if(failedresult.length && failedresult.length > 0) { + shipit.log(chalk.yellow('Symbolic link at remote not made, as something already exists at ' + path(shipit.config.deployTo, 'current'))); + } + shipit.log(chalk.green('Release published.')); }); } diff --git a/test/unit/tasks/deploy/publish.js b/test/unit/tasks/deploy/publish.js index de98397..81653d8 100644 --- a/test/unit/tasks/deploy/publish.js +++ b/test/unit/tasks/deploy/publish.js @@ -39,7 +39,7 @@ describe('deploy:publish task', function () { shipit.start('deploy:publish', function (err) { if (err) return done(err); expect(shipit.currentPath).to.equal('/remote/deploy/current'); - expect(shipit.remote).to.be.calledWith('cd /remote/deploy && ln -nfs releases/20141704123138 current'); + expect(shipit.remote).to.be.calledWith('cd /remote/deploy && if [[ -d current && ! (-L current) ]]; then echo "ERR: could not make symlink"; else ln -nfs releases/20141704123138 current_tmp && mv -fT current_tmp current; fi'); done(); }); });