Skip to content

Commit a9823df

Browse files
authored
Build: Add --dry-run and improve the development experience
Closes gh-98
2 parents 591ca61 + 21b0f6f commit a9823df

File tree

11 files changed

+49
-34
lines changed

11 files changed

+49
-34
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ node release.js --remote=jquery/<project-name>
1414

1515
### Testing the Release Script
1616

17-
***This only applies to those with access to some private repos. You can also use any other repo with a release script.***
18-
1917
You can do a test run of the release script by using a different remote repository. **It is recommended to perform tests from a fresh clone of the project being released.** The script is smart enough to detect if you're using an official repository and adjust which actions are taken so that undesired actions, such as publishing to npm, don't occur for test runs.
2018

19+
You can also explicitly specify `--dry-run` to skip actions that affect external state.
20+
2121
When working on features of this script, adapt the following to simplify testing a bit, replacing the paths for `project` and `cdn`:
2222

2323
```bash
@@ -40,14 +40,14 @@ cd $cdn
4040
git push -f
4141
cd -
4242

43-
rm -rf __release/
44-
node release.js --remote=$project
43+
npm run clean
44+
env TEST_REMOTE=$cdn node --dry-run release.js --remote=$project
4545
```
4646

47-
You need local clones of [fake-project](https://github.com/jquery/fake-project) and [fake-cdn](https://github.com/jquery/fake-cdn) (private, see note above), then update both variables to point to those.
48-
4947
Save as `test-release.sh` in the checkout of this repo, make it executable with `chmod +x test-release.sh`, then run with `./test-release.sh`.
5048

49+
***If you have access to the private repositories [fake-project](https://github.com/jquery/fake-project) and [fake-cdn](https://github.com/jquery/fake-cdn)***, you can use them by dropping the `--dry-run` argument and updating the `TEST_REMOTE` environment variable to "git@github.com:jquery/fake-cdn.git".
50+
5151
### Full Usage Options
5252

5353
See the [usage documentation](/docs/usage.txt) for the full set of options. You can also run the script with no parameters to see the usage.

docs/usage.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
Usage: node release.js [--pre-release=version] [--branch=branch] --remote=repo
1+
Usage: node release.js [--dry-run] [--pre-release=version] [--branch=branch] --remote=repo
22

33
OPTIONS
4+
--dry-run
5+
Executes in test mode, skipping npm publish and CDN push.
6+
47
--pre-release=version
58
Creates a pre-release instead of a stable release. Since the
69
version number can't be determined automatically, it must be

lib/bootstrap.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Release.define({
4141
Release._parseRemote();
4242
Release.branch = Release.args.branch || "master";
4343
Release.preRelease = Release.args.preRelease || false;
44+
if ( Release.args.dryRun || Release.args.isTest ) {
45+
Release.isTest = true;
46+
}
4447

4548
if ( Release.preRelease && !semver.valid( Release.preRelease) ) {
4649
Release.abort( "Invalid --pre-release argument, not valid semver: " +
@@ -54,7 +57,7 @@ Release.define({
5457
console.log();
5558

5659
if ( Release.isTest ) {
57-
console.log( "This is a test release. npm will not be updated." );
60+
console.log( "This is a test release. GitHub and npm will not be updated." );
5861
} else {
5962
console.log( "This is a real release. GitHub and npm will be updated." );
6063
}

lib/cdn.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var shell = require( "shelljs" ),
44

55
module.exports = function( Release ) {
66
var realRemote = "git@github.com:jquery/codeorigin.jquery.com.git",
7-
testRemote = "git@github.com:jquery/fake-cdn.git";
7+
testRemote = process.env.TEST_REMOTE || "git@github.com:jquery/fake-cdn.git";
88

99
function projectCdn() {
1010
var project = Release.readPackage().name,
@@ -66,7 +66,8 @@ module.exports = function( Release ) {
6666

6767
_pushToCdn: function() {
6868
Release.chdir( projectCdn() );
69-
Release.exec( "git push", "Error pushing to CDN." );
69+
Release.exec( "git push" + (Release.isTest ? " --dry-run" : ""),
70+
"Error pushing to CDN." );
7071
console.log();
7172
}
7273
});

lib/git.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ module.exports = function( Release ) {
22

33
Release.define({
44
gitLog: function( format ) {
5-
var command = "git log " + Release.prevVersion + ".." + Release.newVersion + " " +
6-
"--format=\"" + format + "\"",
5+
var commitRange = Release.prevVersion + ".." + Release.newVersion,
6+
gitLog = "git log --format=\"" + format + "\" " + commitRange,
77
result = Release.exec({
8-
command: command,
8+
command: gitLog,
99
silent: true
10-
}, "Error getting git log, command was: " + command );
10+
}, "Error getting git log, command was: " + gitLog );
1111

1212
result = result.split( /\r?\n/ );
1313
if ( result[ result.length - 1 ] === "" ) {

lib/github.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Release.define({
2727
})[ 0 ];
2828

2929
if ( !milestone ) {
30-
Release.abort( "No milestone found." );
30+
Release.abort( "Milestone not found: " + version );
3131
}
3232

3333
callback( milestone.number );

lib/npm.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var chalk = require( "chalk" ),
2-
shell = require( "shelljs" );
1+
var chalk = require( "chalk" );
32

43
module.exports = function( Release ) {
54
Release.define({
@@ -17,7 +16,7 @@ module.exports = function( Release ) {
1716
},
1817

1918
_getNpmOwners: function( npmPackage ) {
20-
var result = shell.exec( "npm owner ls " + npmPackage, { silent: true } );
19+
var result = Release.rawExec( "npm owner ls " + npmPackage, { silent: true } );
2120
if ( result.code !== 0 ) {
2221

2322
// The npm package may not exist yet
@@ -68,26 +67,26 @@ module.exports = function( Release ) {
6867

6968
Release.chdir( Release.dir.repo );
7069

71-
var name = Release.readPackage().name,
72-
npmTags = Release.npmTags(),
73-
npmCommand = "npm publish --tag " + npmTags.pop();
70+
var npmPublish,
71+
newVersion = Release.readPackage().name + "@" + Release.newVersion,
72+
safety = Release.isTest ? " --dry-run" : "",
73+
npmTags = Release.npmTags();
7474

7575
if ( Release.isTest ) {
7676
console.log( "Actual release would now publish to npm using:" );
7777
} else {
7878
console.log( "Publishing to npm, running:" );
7979
}
8080

81-
console.log( " " + chalk.cyan( npmCommand ) );
82-
if ( !Release.isTest ) {
83-
Release.exec( npmCommand );
84-
}
81+
npmPublish = "npm publish" + safety + " --tag " + npmTags.pop();
82+
console.log( " " + chalk.cyan( npmPublish ) );
83+
Release.exec( npmPublish );
8584

8685
while ( npmTags.length ) {
87-
npmCommand = "npm dist-tag add " + name + "@" + Release.newVersion + " " + npmTags.pop();
88-
console.log( " " + chalk.cyan( npmCommand ) );
86+
npmPublish = "npm dist-tag add " + newVersion + " " + npmTags.pop();
87+
console.log( " " + chalk.cyan( npmPublish ) );
8988
if ( !Release.isTest ) {
90-
Release.exec( npmCommand );
89+
Release.exec( npmPublish );
9190
}
9291
}
9392

lib/repo.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ Release.define({
255255
_pushRelease: function() {
256256
Release.chdir( Release.dir.repo );
257257
console.log( "Pushing release to git repo..." );
258-
Release.exec( "git push --tags", "Error pushing tags to git repo." );
258+
Release.exec( "git push" + (Release.isTest ? " --dry-run " : "") + " --tags",
259+
"Error pushing tags to git repo." );
259260
},
260261

261262
_updateBranchVersion: function() {
@@ -276,7 +277,8 @@ Release.define({
276277
_pushBranch: function() {
277278
Release.chdir( Release.dir.repo );
278279
console.log( "Pushing " + chalk.cyan( Release.branch ) + " to GitHub..." );
279-
Release.exec( "git push", "Error pushing to GitHub." );
280+
Release.exec( "git push" + (Release.isTest ? " --dry-run " : ""),
281+
"Error pushing to GitHub." );
280282
}
281283
});
282284

lib/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ var shell = require( "shelljs" ),
44
module.exports = function( Release ) {
55

66
Release.define({
7+
rawExec: function( command, options ) {
8+
return shell.exec( command, options );
9+
},
10+
711
exec: function( _options, errorMessage ) {
812
var result,
913
command = _options.command || _options,
@@ -15,7 +19,7 @@ Release.define({
1519

1620
errorMessage = errorMessage || "Error executing command: " + command;
1721

18-
result = shell.exec( command, options );
22+
result = Release.rawExec( command, options );
1923
if ( result.code !== 0 ) {
2024
Release.abort( errorMessage );
2125
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"grunt-contrib-jshint": "~0.7.2"
1313
},
1414
"scripts": {
15-
"test": "grunt"
15+
"test": "grunt",
16+
"clean": "rm -rf __release/"
1617
},
1718
"repository": "jquery/jquery-release",
1819
"license": "MIT"

0 commit comments

Comments
 (0)