Skip to content
This repository has been archived by the owner on Mar 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #122 from travco/symWarn
Browse files Browse the repository at this point in the history
Fix #29, add warn for failed symbolic link creation, make symlink replace atomic
  • Loading branch information
timkelty authored Jun 27, 2017
2 parents 4e9e155 + a277e6a commit 8e17d81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions tasks/deploy/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/tasks/deploy/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 8e17d81

Please sign in to comment.