Finish release script

This commit is contained in:
shilangyu 2021-02-04 22:07:41 +01:00
parent da210d37eb
commit b033c78dd8
1 changed files with 49 additions and 6 deletions

View File

@ -1,6 +1,13 @@
import 'dart:io';
Future<void> main(List<String> args) async {
final res =
await Process.run('git', ['diff-index', '--cached', '--quiet', 'HEAD']);
if (res.exitCode != 0) {
print('You have staged files, commit or unstage them.');
exit(1);
}
if (args.isEmpty || !{'patch', 'minor', 'major'}.contains(args[0])) {
print('Unknown version bump type');
exit(1);
@ -33,18 +40,54 @@ Future<void> main(List<String> args) async {
}
code++;
final newVersion = '$major.$minor.$patch+$code';
confirm('Version looks good? $newVersion');
final newVersionName = '$major.$minor.$patch';
final newVersionString = '$newVersionName+$code';
confirm('Version looks good? $newVersionString');
final updatedPubspec = pubspecContents.replaceFirst(
versionMatch.group(0), 'version: $newVersion');
versionMatch.group(0), 'version: $newVersionString');
await pubspecFile.writeAsString(updatedPubspec);
final changelogFile = File('CHANGELOG.md');
final changelogContents = await changelogFile.readAsString();
var thisChangelog =
RegExp(r'^## Unreleased$.+?^##[^#]', multiLine: true, dotAll: true)
.stringMatch(changelogContents);
thisChangelog = thisChangelog.substring(0, thisChangelog.length - 4);
final date = DateTime.now();
final dateString =
'${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
thisChangelog = thisChangelog.replaceFirst(
'Unreleased', 'v$newVersionName - $dateString');
confirm('Changelog looks good?\n$thisChangelog\n');
await changelogFile.writeAsString(changelogContents.replaceFirst(
'Unreleased', 'v$newVersionName - $dateString'));
await File('fastlane/metadata/android/en-US/changelogs/$code.txt')
.writeAsString(thisChangelog.split('\n').skip(2).join('\n'));
stdout.write('Running git tag... ');
await Process.run('git', ['tag', 'v$newVersionName']);
print('done');
stdout.write('Running git add... ');
await Process.run('git', [
'add',
'CHANGELOG.md',
'pubspec.yaml',
'fastlane/metadata/android/en-US/changelogs/$code.txt'
]);
print('done');
print(
'Review your staged files, commit them with a message of "Release v$newVersionName" push it and finish off with `git push --tags`');
}
void confirm(String message) {
print('$message [y/n]');
stdout.write('$message [y/n] ');
switch (stdin.readLineSync()) {
case 'y':