Skip to content
This repository was archived by the owner on Mar 16, 2020. It is now read-only.

Automate release tagging for package. #50

Merged
merged 5 commits into from
Jul 29, 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
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies:
dev_dependencies:
grinder: ^0.7.0
html: ^0.12.0
pub_semver: ^1.2.1
test: ^0.12.0
9 changes: 9 additions & 0 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
library atom.grind;

import 'dart:io';
import 'dart:convert';


import 'package:grinder/grinder.dart';
import 'package:pub_semver/pub_semver.dart';

part "publish.dart";

// crashes grinder -- so add it as a library dependency for now.
// import 'deploy.dart' show deploy;
// export 'publish.dart' show deploy;

main(List args) => grind(args);

Expand Down
58 changes: 58 additions & 0 deletions tool/publish.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
part of atom.grind;

// import 'dart:convert';
// import 'dart:io';

// import 'package:grinder/grinder.dart';
// import 'package:pub_semver/pub_semver.dart';

@Task('Publish a new version of dartlang')
publish() {
throw 'Sorry -- grinder does not yet support specifying options on the command line!';
// TODO: command line parsing (major, minor, patch) version update
// Comment out the if statements while developing this task.
var diffResult = Process.runSync("git", ["diff", "--shortstat"]);
if (diffResult.stdout.toString().isNotEmpty)
throw 'Index is dirty; commit files and try again';

var syncResult = Process.runSync("git", ["rev-list", "origin..HEAD"]);
if (syncResult.stdout.toString().isNotEmpty)
throw 'Not synchronized with master; git push and try again';

var packageFileData = new File('package.json').readAsStringSync();
var yamlFileData = new File('pubspec.yaml').readAsStringSync();
var changelogData = new File('CHANGELOG.md').readAsStringSync();

var packageData = JSON.decode(packageFileData);

var currentVersion = new Version.parse(packageData['version']);
// TODO: have this match the parameter passed in on the command line
var nextVersion = currentVersion.nextPatch;

var jsonPattern = (version) => '"version": "${version}"';
var yamlPattern = (version) => 'version: ${version}';
var changelogPattern = (version) => "# ${version}";
// We do pattern matches to preserve the formatting in the existing files.

var newPackageFileData =
packageFileData.replaceFirst(jsonPattern(currentVersion),
jsonPattern(nextVersion));
var newYamlFileData =
yamlFileData.replaceFirst(yamlPattern(currentVersion),
yamlPattern(nextVersion));
var newChangelogData =
changelogData.replaceFirst(changelogPattern('Upcoming Version'),
changelogPattern(nextVersion));

new File('package.json').writeAsStringSync(newPackageFileData);
new File('pubspec.yaml').writeAsStringSync(newYamlFileData);
new File('CHANGELOG.md').writeAsStringSync(newChangelogData);

Process.runSync("git", ["commit", "-a", '-m "prepare $nextVersion"']);
Process.runSync("git", ["tag", nextVersion.toString()]);
Process.runSync("git", ["push", "-t"]);
Process.runSync("apm", ["publish", "-t", nextVersion.toString()]);

print("Version ${nextVersion} has been published!");
print('¯\\_(ツ)_/¯');
}