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

Fixes issue 42 and 94. #125

Merged
merged 1 commit into from
Feb 17, 2015
Merged
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
70 changes: 63 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ grunt.initConfig({
push: true,
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false
globalReplace: false,
prereleaseName: null
}
},
})
Expand Down Expand Up @@ -124,6 +125,19 @@ Default value: `false`

Replace all occurrences of the version in the file. When set to `false`, only the first occurrence will be replaced.

#### options.prereleaseName
Type: `String`
Default value: `rc`

When bumping to a prerelease version this will be the identifier of the prerelease e.g. `dev`, `alpha`, `beta`, `rc` etc.
1.0.0-`prereleaseName`.0
When left as the default `null` version bump:prereleae will behave as follows:
* 1.0.0 to 1.0.1-0
* 1.0.1-0 to 1.0.1-1
* from a previous bump:git
* 1.0.0-7-g10b5 to 1.0.0-8


### Usage Examples

Let's say current version is `0.0.1`.
Expand Down Expand Up @@ -153,12 +167,6 @@ $ grunt bump:major
>> Tagged as "v1.0.0"
>> Pushed to origin

$ grunt bump:prerelease
>> Version bumped to 1.0.0-1
>> Committed as "Release v1.0.0-1"
>> Tagged as "v1.0.0-1"
>> Pushed to origin

$ grunt bump:patch
>> Version bumped to 1.0.1
>> Committed as "Release v1.0.1"
Expand All @@ -170,6 +178,54 @@ $ grunt bump:git
>> Committed as "Release v1.0.1-ge96c"
>> Tagged as "v1.0.1-ge96c"
>> Pushed to origin

$ grunt bump:prepatch
>> Version bumped to 1.0.2-0
>> Committed as "Release v1.0.2-0"
>> Tagged as "v1.0.2-0"
>> Pushed to origin

$ grunt bump:prerelease
Copy link
Collaborator

Choose a reason for hiding this comment

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

these examples are a little confusing. why go from prepatch to prerelease?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: examples/ expected behavior of prerelease
bump:prerelease is how you bump the prerelease version.
From a released version (1.0.0) you choose

  • prepatch -> 1.0.1-rc.0 prerelease -> 1.0.1-rc.1
  • preminor -> 1.1.0-rc.0 prerelease -> 1.1.0-rc.1
  • premajor -> 2.0.0-rc.0 prerelease -> 2.0.0-rc.1

The way it is now (and in the readme) is incorrect.

  • Current behavior. v1.0.0 bump:prerelease -> v1.0.0-1
    1.0.0-1 should be the prerelease for 1.0.0 so this should not be the expected behavior.

re: the defaulted prreleaeName.
There needs to be something other than an empty string as the prereleaseName otherwise the the versions are not bumped properly. They behave more like he existing functionality of prerelease which is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From Semver 2.0.0:

A pre-release ... Identifiers MUST NOT be empty. ... Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You missed:

A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version

Meaning everything after the hyphen is the identifier. To have multiple identifiers, you separate them with dots.

As for the current current behavior of going from 1.0.0 to 1.0.0-1 as the next prerelease, that is a bug that existed in semver which has since been fixed. Purely upgrading semver with no other changes would make it go from 1.0.0 to 1.0.1-0.

>> Version bumped to 1.0.2-1
>> Committed as "Release v1.0.2-1"
>> Tagged as "v1.0.2-1"
>> Pushed to origin

$ grunt bump:patch # (major, minor or patch) will do this
>> Version bumped to 1.0.2
>> Committed as "Release v1.0.2"
>> Tagged as "v1.0.2"
>> Pushed to origin

$ grunt bump:preminor
>> Version bumped to 1.1.0-0
>> Committed as "Release v1.1.0-0"
>> Tagged as "v1.1.0-0"
>> Pushed to origin

$ grunt bump
>> Version bumped to 1.1.0
>> Committed as "Release v1.1.0"
>> Tagged as "v1.1.0"
>> Pushed to origin

$ grunt bump:premajor (with prerelaseName set to 'rc' in options)
>> Version bumped to 2.0.0-rc.0
>> Committed as "Release v2.0.0-rc.0"
>> Tagged as "v2.0.0-rc.0"
>> Pushed to origin

$ grunt bump
>> Version bumped to 2.0.0
>> Committed as "Release v2.0.0"
>> Tagged as "v2.0.0"
>> Pushed to origin

$ grunt bump:prerelease # from a released version `prerelease` defaults to prepatch
>> Version bumped to 2.0.1-rc.0
>> Committed as "Release v2.0.1-rc.0"
>> Tagged as "v2.0.1-rc.0"
>> Pushed to origin
````

If you want to jump to an exact version, you can use the ```setversion``` tag in the command line.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"license": "MIT",
"dependencies": {
"semver": "~2.3.0"
"semver": "~4.2.2"
},
"peerDependencies": {
"grunt": ">=0.4.0"
Expand Down
18 changes: 10 additions & 8 deletions tasks/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* grunt bump:patch
* grunt bump:minor
* grunt bump:major
* grunt bump:prepatch
* grunt bump:preminor
* grunt bump:premajor
* grunt bump:prerelease
*
* @author Vojta Jina <[email protected]>
* @author Mathias Paumgarten <[email protected]>
Expand Down Expand Up @@ -34,7 +38,8 @@ module.exports = function(grunt) {
push: true,
pushTo: 'upstream',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false
globalReplace: false,
prereleaseName: null
});

var dryRun = grunt.option('dry-run');
Expand Down Expand Up @@ -77,14 +82,12 @@ module.exports = function(grunt) {

var globalVersion; // when bumping multiple files
var gitVersion; // when bumping using `git describe`
var VERSION_REGEXP = /([\'|\"]?version[\'|\"]?[ ]*:[ ]*[\'|\"]?)([\d||A-a|.|-]*)([\'|\"]?)/i;

var VERSION_REGEXP = new RegExp('([\\\'|\\\"]?version[\\\'|\\\"]?[ ]*:[ ]*[\\\'|\\\"]?)(\\\d+\\\.\\\d+\\\.\\\d+(-'+opts.prereleaseName+'\\\.\\\d+)?(-\\\d+)?)[\\\d||A-a|.|-]*([\\\'|\\\"]?)', 'i');
Copy link
Collaborator

Choose a reason for hiding this comment

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

holy smokes batman, that is one scary regex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you get rid of all the escapes (that are there so we can add a variable) it's much less scary looking. I tried to write a couple of tests, but am unfamiliar with testing node modules.
I could just copy the regex over to a test for now (though not a great strategy). If you have any suggestions on how to add tests for the regex I'd be happy to flush them out.
I have tested this quite a bit manually. Let me know if there's anything I can do to help out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

didnt notice this before, but shouldn't the regex replace:

(-'+opts.prereleaseName+'\\\.\\\d+)?

with something that won't translate to: (-null\\\.\\\d+)? like:

(-'+ (opts.prereleaseName || '') +'\\\.\\\d+)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so.
When there is a prereleaseName the format is 1.0.0-.0
Without a name the format is different, there is not just, just the dash so 1.0.0-0 so the name || '' would not match.


if (opts.globalReplace) {
VERSION_REGEXP = new RegExp(VERSION_REGEXP.source, 'gi');
}


// GET VERSION FROM GIT
runIf(opts.bumpVersion && versionType === 'git', function() {
exec('git describe ' + opts.gitDescribeOptions, function(err, stdout) {
Expand All @@ -96,14 +99,13 @@ module.exports = function(grunt) {
});
});


// BUMP ALL FILES
runIf(opts.bumpVersion, function() {
grunt.file.expand(opts.files).forEach(function(file, idx) {
var version = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part got left off so bump:git isn't working. #129 Working on fixing it.

var content = grunt.file.read(file).replace(VERSION_REGEXP, function(match, prefix, parsedVersion, suffix) {
gitVersion = gitVersion && parsedVersion + '-' + gitVersion;
version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch');
var bumpFrom;
var content = grunt.file.read(file).replace(VERSION_REGEXP, function(match, prefix, parsedVersion, namedPre, noNamePre, suffix) {
version = exactVersionToSet || gitVersion || semver.inc(parsedVersion, versionType || 'patch', opts.prereleaseName);
return prefix + version + suffix;
});

Expand Down