Skip to content

Commit cb14b9b

Browse files
committed
Build: Make isTest skip git commits and expose it as --dry-run
1 parent 28c14a3 commit cb14b9b

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ node release.js --remote=jquery/<project-name>
1818

1919
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.
2020

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

2325
```bash
@@ -41,7 +43,7 @@ git push -f
4143
cd -
4244

4345
npm run clean
44-
node release.js --remote=$project
46+
node --dry-run release.js --remote=$project
4547
```
4648

4749
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.

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/npm.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ module.exports = function( Release ) {
6868

6969
Release.chdir( Release.dir.repo );
7070

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

7576
if ( Release.isTest ) {
7677
console.log( "Actual release would now publish to npm using:" );
7778
} else {
7879
console.log( "Publishing to npm, running:" );
7980
}
8081

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

8686
while ( npmTags.length ) {
87-
npmCommand = "npm dist-tag add " + name + "@" + Release.newVersion + " " + npmTags.pop();
88-
console.log( " " + chalk.cyan( npmCommand ) );
87+
npmPublish = "npm dist-tag add " + newVersion + " " + npmTags.pop();
88+
console.log( " " + chalk.cyan( npmPublish ) );
8989
if ( !Release.isTest ) {
90-
Release.exec( npmCommand );
90+
Release.exec( npmPublish );
9191
}
9292
}
9393

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

0 commit comments

Comments
 (0)