Skip to content

Commit

Permalink
feat(prepare_release): no-build flag for writing no-build version
Browse files Browse the repository at this point in the history
  • Loading branch information
asartalo committed Mar 29, 2024
1 parent d31d7b2 commit a8d71ea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
35 changes: 27 additions & 8 deletions lib/prepare_release_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,31 @@ class PrepareReleaseCommand extends ReleaseToolsCommand {
required this.updateYearCommand,
}) {
argParser.addFlag(
'writeSummary',
'write-summary',
abbr: 'w',
help:
'Writes release information to files (VERSION.txt and RELEASE_SUMMARY.txt)',
aliases: ['writeSummary'],
);
argParser.addFlag(
'updateYear',
'update-year',
abbr: 'Y',
help:
'Also update year in license files. Better to eave this off if you are not sure.',
aliases: ['updateYear'],
);
argParser.addFlag(
'ensureMajor',
'ensure-major',
abbr: 'm',
help: 'Ensure next version >= 1.0.0',
aliases: ['ensureMajor'],
);
argParser.addFlag(
'no-build',
abbr: 'n',
help:
'When paired with --write-summary, it will also write with VERSION-NO-BUILD.txt with no-build number',
aliases: ['no-build'],
);
}

Expand All @@ -69,14 +79,15 @@ class PrepareReleaseCommand extends ReleaseToolsCommand {
commits,
currentVersion,
incrementBuild: true,
ensureMajor: args['ensureMajor'] as bool,
ensureMajor: args['ensure-major'] as bool,
);
if (nextVersion != currentVersion) {
await _createRelease(
commits: commits,
nextVersion: nextVersion,
writeSummary: args['writeSummary'] as bool,
updateYear: args['updateYear'] as bool,
writeSummary: args['write-summary'] as bool,
updateYear: args['update-year'] as bool,
noBuild: args['no-build'] as bool,
);
} else {
printer.println('There are no releasable commits');
Expand All @@ -88,6 +99,7 @@ class PrepareReleaseCommand extends ReleaseToolsCommand {
required String nextVersion,
required bool writeSummary,
required bool updateYear,
required bool noBuild,
}) async {
final summary = await changelogCommand.writeChangelog(
commits: commits,
Expand All @@ -103,11 +115,18 @@ class PrepareReleaseCommand extends ReleaseToolsCommand {
if (summary is ChangeSummary) {
if (writeSummary) {
final project = changelogCommand.project;
final versionFile = project.getFile('VERSION.txt');
await versionFile.writeAsString(nextVersion);

final summaryFile = project.getFile('RELEASE_SUMMARY.txt');
await summaryFile.writeAsString(summary.toMarkdown());

final versionFile = project.getFile('VERSION.txt');
await versionFile.writeAsString(nextVersion);

if (noBuild) {
final noBuildVersion = versionStringWithoutBuild(nextVersion);
final noBuildVersionFile = project.getFile('VERSION-NO-BUILD.txt');
await noBuildVersionFile.writeAsString(noBuildVersion);
}
}

printer.printSuccess('Version bumped to: $nextVersion\n');
Expand Down
18 changes: 18 additions & 0 deletions test/prepare_release_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,24 @@ Redistribution and use in source and binary forms, with or without...
expect(await versionFile.readAsString(), equals('2.0.0+2'));
});
});

group('when passed with -w and --no-build', () {
setUp(() async {
await runner.run([command, '-w', '--no-build']);
});

successTest();

test('it still writes a version file', () async {
final versionFile = getFile('VERSION.txt');
expect(await versionFile.readAsString(), equals('2.0.0+2'));
});

test('it also writes a no-build version file', () async {
final versionFile = getFile('VERSION-NO-BUILD.txt');
expect(await versionFile.readAsString(), equals('2.0.0'));
});
});
});
});

Expand Down

0 comments on commit a8d71ea

Please sign in to comment.