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

Do not attempt deploy without changes. #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ module.exports = function(grunt) {
message: 'second deploy'
},
src: 'tmp/src'
},
null_deploy: {
options: {
url: '../repo',
tag: 'null',
message: 'null deploy, should not work'
},
src: 'tmp/src'
}
},

Expand All @@ -125,7 +133,7 @@ module.exports = function(grunt) {

// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'init_repo', 'copy:first', 'git_deploy:first', 'clean:deploy', 'clean:test_build', 'copy:second', 'git_deploy:second', 'nodeunit']);
grunt.registerTask('test', ['clean', 'init_repo', 'copy:first', 'git_deploy:first', 'clean:deploy', 'clean:test_build', 'copy:second', 'git_deploy:second', 'clean:deploy', 'clean:test_build', 'copy:second', 'git_deploy:null_deploy', 'nodeunit']);

// By default, run all tests.
grunt.registerTask('default', ['test']);
Expand Down
42 changes: 33 additions & 9 deletions tasks/git_deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,45 @@ module.exports = function(grunt) {

var done = this.async();

// stage files for checkin

var commands = [
git(['clone', '-b', options.branch, options.url, '.' ]),
git(['checkout', '-B', options.branch]),
copyIntoRepo( src, deployDir ),
git(['add', '--all']),
git(['commit', '--message=' + options.message ])
copyIntoRepo( src, deployDir )
];

if ( options.tag ) {
commands.push( git(['tag', '-a', options.tag, '-m', options.tagMessage]) );
}

commands.push( git(['push', '--prune', '--force', '--quiet', '--follow-tags', options.url, options.branch]) );
grunt.util.async.series(commands, function() {
spawn({ // determine if any files need to be checked in
cmd: 'git',
args: ['status'],
opts: {cwd: deployDir}
}, function(error, result, code) {
if(code == 0) {
if(result.stdout.indexOf('nothing to commit, working directory clean') < 0) { // files need to be checked in
commands = [
git(['add', '--all']),
git(['commit', '--message=' + options.message ])
];

if ( options.tag ) {
commands.push( git(['tag', '-a', options.tag, '-m', options.tagMessage]) );
}

commands.push( git(['push', '--prune', '--force', '--quiet', '--follow-tags', options.url, options.branch]) );

grunt.util.async.series(commands, done);
} else { // files do not need to be checked in
grunt.log.writeln('Nothing for git_deploy to commit.');
done();
}
} else {
grunt.fail.warn('Error running "git status":' + result.stderr);
done();
}
});
});

grunt.util.async.series(commands, done);

});
};
Expand Down