Skip to content
This repository was archived by the owner on Apr 14, 2023. It is now read-only.
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ gulp.task('deploy', function() {

Only trigger deployment on the following branch(es). Defaults to `master`.

- `version`

Tag version from package.json. Defaults to `false`.


- `verbose`

Verbose mode. Will show output from all git commands run. Defaults to `false`.
Expand Down
51 changes: 51 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function(options) {
repository: '',
remoteBranch: 'master',
branches: ['master'],
version: false,
verbose: false,
debug: false
}, options);
Expand Down Expand Up @@ -201,6 +202,56 @@ module.exports = function(options) {
return callback(null);
});
},
function gitTag(callback) {
if (!options.version) {
return callback(null);
}
const packageJson = files.reduce(function(path, file) {
if (file.path.indexOf('package.json') !== -1) {
path = file.path
}
return path
}, '');
if (packageJson === '') {
return callback('package.json is required if option version is true');
}
var packageContent = fs.readFileSync(packageJson, 'utf8');
var json = JSON.parse(packageContent.toString());
var version = json.version;
gutil.log(gutil.colors.yellow('Tag version ' + version));
var cmdTag = spawn('git', ['tag', '-a', 'v' + version, '-m', 'Version ' + version], {cwd: repoPath});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the 'v' + version and 'Version ' + version strings to be configurable (maybe via a lambda call?), but that can be fixed in a later PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configurable is good, but I'm just make quick to reach my needs.... 😁

cmdTag.stderr.on('data', function(data) {
if (options.verbose || options.debug) gutil.log(gutil.colors.magenta('git tag: ') + data.toString().trim());
});
cmdTag.stdout.on('data', function(data) {
if (options.verbose || options.debug) gutil.log(gutil.colors.magenta('git tag: ') + data.toString().trim());
});
cmdTag.on('close', function(code) {
if (code !== 0) {
return callback('git tag exited with code ' + code);
}
return callback(null);
});
},
function gitPushTag(callback) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attaching this comment to the new changeset since it turned outdated on the rename:

Can't the versioned tag be pushed out with the rest of the repository? Shouldn't be a need for multiple git push calls. Do correct me if I'm missing something though.

Since this is also located before the gitPush function, I'm pretty sure this will break usage of the remoteBranch option and push to the default branch regardless.

if (!options.version) {
return callback(null);
}
gutil.log(gutil.colors.yellow('Pushing version to remote deployment repository'));
var cmdPush = spawn('git', ['push', 'origin', '--tags'], {cwd: repoPath});
cmdPush.stderr.on('data', function(data) {
if (options.verbose || options.debug) gutil.log(gutil.colors.magenta('git push verion: ') + data.toString().trim());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here: verion

});
cmdPush.stdout.on('data', function(data) {
if (options.verbose || options.debug) gutil.log(gutil.colors.magenta('git push verion: ') + data.toString().trim());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here: verion

});
cmdPush.on('close', function(code) {
if (code !== 0) {
return callback('git push verion exited with code ' + code);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here: verion

}
return callback(null);
});
},
function gitPush(callback) {
gutil.log(gutil.colors.yellow('Pushing to remote deployment repository'));
var cmdPush = spawn('git', ['push', 'origin', options.remoteBranch], {cwd: repoPath});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able tomake this var cmdPush = spawn('git', ['push', 'origin', options.remoteBranch, '--tags'], {cwd: repoPath}); to fix the git push comment above. Does require testing to make sure it works though.

Expand Down