diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b2ba2..3eb4afc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.5] - 2023-03-30 +### Added +- Ability to yank/unyank specific versions + ## [0.1.4] - 2023-03-01 ### Changed - Bumped dependencies versions (thanks [@zeshuaro](https://github.com/zeshuaro)) @@ -74,6 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial version +[0.1.5]: https://github.com/f3ath/cider/compare/0.1.4...0.1.5 [0.1.4]: https://github.com/f3ath/cider/compare/0.1.3...0.1.4 [0.1.3]: https://github.com/f3ath/cider/compare/0.1.2...0.1.3 [0.1.2]: https://github.com/f3ath/cider/compare/0.1.1...0.1.2 diff --git a/README.md b/README.md index d66c9ec..df945d4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This tool assumes that the changelog: - is called `CHANGELOG.md` - is sitting in the project root folder -- strictly follows the [Keep a Changelog v1.0.0](https://keepachangelog.com/en/1.0.0/) format +- strictly follows the [Changelog] format - uses basic markdown (no HTML and complex formatting supported) It also assumes that your project follows [Semantic Versioning v2.0.0](https://semver.org/spec/v2.0.0.html). @@ -106,10 +106,26 @@ cider version Examples: - Version before | Command | Version after -----------------|--------------------------------|---------------- - 1.2.3+1 | `cider version 3.2.1` | 3.2.1 - 0.2.1-dev | `cider version 0.0.1-alpha+42` | 0.0.1-alpha+42 +| Version before | Command | Version after | +|----------------|--------------------------------|----------------| +| 1.2.3+1 | `cider version 3.2.1` | 3.2.1 | +| 0.2.1-dev | `cider version 0.0.1-alpha+42` | 0.0.1-alpha+42 | + +### Yanking/unyanking a version +The [Changelog] defines yanked releases as version that are pulled (withdrawn) due to a serious bug or security issue. +According to the [Changelog], a yanked release should be marked with a `[YANKED]` tag in the changelog file. + +To mark a version as yanked, run the following command: + +``` +cider yank +``` + +To unyank a version, run the following command: + +``` +cider unyank +``` ### Bumping the project version @@ -143,22 +159,22 @@ corresponding part. Remember that according to [semver] v2, `build` is considered metadata and is ignored when determining version precedence. - Version before | Command | Version after -----------------|---------------------------------------------|------------------ - 1.2.1-alpha+42 | `cider bump breaking` | 2.0.0 - 0.2.1-alpha+42 | `cider bump breaking` | 0.3.0 - 0.2.1-alpha+42 | `cider bump major` | 1.0.0 - 0.2.1-alpha+42 | `cider bump minor` | 0.3.0 - 0.2.1-alpha+42 | `cider bump patch` | 0.2.1 - 0.2.1 | `cider bump patch` | 0.2.2 - 0.2.1-alpha+42 | `cider bump pre` | 0.2.1-alpha.1 - 1.2.1-alpha+42 | `cider bump breaking --keep-build` | 2.0.0+42 - 0.2.1-alpha+42 | `cider bump breaking --bump-build` | 0.3.0+43 - 0.2.1-alpha+42 | `cider bump major --build=2020-02-02` | 1.0.0+2020-02-02 - 0.2.1-alpha+42 | `cider bump minor --pre=aplha --bump-build` | 0.3.0-alpha+43 - 0.2.1-alpha+42 | `cider bump release` | 0.2.1 - 0.2.1-alpha+42 | `cider bump release --keep-build` | 0.2.1+42 +| Version before | Command | Version after | +|----------------|---------------------------------------------|------------------| +| 1.2.1-alpha+42 | `cider bump breaking` | 2.0.0 | +| 0.2.1-alpha+42 | `cider bump breaking` | 0.3.0 | +| 0.2.1-alpha+42 | `cider bump major` | 1.0.0 | +| 0.2.1-alpha+42 | `cider bump minor` | 0.3.0 | +| 0.2.1-alpha+42 | `cider bump patch` | 0.2.1 | +| 0.2.1 | `cider bump patch` | 0.2.2 | +| 0.2.1-alpha+42 | `cider bump pre` | 0.2.1-alpha.1 | +| 1.2.1-alpha+42 | `cider bump breaking --keep-build` | 2.0.0+42 | +| 0.2.1-alpha+42 | `cider bump breaking --bump-build` | 0.3.0+43 | +| 0.2.1-alpha+42 | `cider bump major --build=2020-02-02` | 1.0.0+2020-02-02 | +| 0.2.1-alpha+42 | `cider bump minor --pre=aplha --bump-build` | 0.3.0-alpha+43 | +| 0.2.1-alpha+42 | `cider bump release` | 0.2.1 | +| 0.2.1-alpha+42 | `cider bump release --keep-build` | 0.2.1+42 | [logo]: https://raw.githubusercontent.com/f3ath/cider/master/cider.png - [semver]: https://semver.org +[Changelog]: https://keepachangelog.com/en/1.1.0/ \ No newline at end of file diff --git a/bin/cider.dart b/bin/cider.dart index 06b6697..f5544d9 100644 --- a/bin/cider.dart +++ b/bin/cider.dart @@ -2,5 +2,6 @@ import 'dart:io'; import 'package:cider/cider.dart'; -void main(List args) => - Cider().run(args).then((code) => exitCode = code); +Future main(List args) async { + exitCode = await Cider().run(args); +} diff --git a/lib/src/cider.dart b/lib/src/cider.dart index ac14ad6..4d39743 100644 --- a/lib/src/cider.dart +++ b/lib/src/cider.dart @@ -67,8 +67,7 @@ class Cider { final cmd = await _runner.run(args); final handler = _handler[cmd]; if (handler != null) { - final code = await handler(cmd!.argResults!, _di.get); - return code ?? 0; + return await handler(cmd!.argResults!, _di.get); } return 0; } on Error catch (e) { @@ -80,4 +79,4 @@ class Cider { } /// A command handler -typedef Handler = FutureOr Function(ArgResults args, ServiceLocator get); +typedef Handler = FutureOr Function(ArgResults args, ServiceLocator get); diff --git a/lib/src/service/changelog_service.dart b/lib/src/service/changelog_service.dart index cdfa4b9..7454b2a 100644 --- a/lib/src/service/changelog_service.dart +++ b/lib/src/service/changelog_service.dart @@ -17,25 +17,39 @@ class ChangelogService { cider.provide((get) => ChangelogService(get('root'), get())); - cider.addCommand(_LogCommand(), (args, get) { + cider.addCommand(_Log(), (args, get) { get().addUnreleased(args.rest.first, args.rest[1]); - return null; + return 0; }); - cider.addCommand(_DescribeCommand(), (args, get) { + cider.addCommand(_Describe(), (args, get) { final version = args.rest.isEmpty ? null : args.rest.first; final section = get().describe(version); get().writeln(section); - return null; + return 0; }); - cider.addCommand(_ReleaseCommand(), (args, get) { + cider.addCommand(_Release(), (args, get) { final date = args['date']; final parsedDate = date == 'today' ? DateTime.now() : DateTime.parse(date); final release = get().release(parsedDate); get().writeln(release); - return null; + return 0; + }); + + cider.addCommand(_Yank(), (args, get) { + final version = args.rest.first; + final release = get().yank(version); + get().writeln(release); + return 0; + }); + + cider.addCommand(_Unyank(), (args, get) { + final version = args.rest.first; + final release = get().unyank(version); + get().writeln(release); + return 0; }); } @@ -79,6 +93,22 @@ class ChangelogService { printChangelog(changelog, keepEmptyUnreleased: keepEmptyUnreleased)); } + String yank(String version) { + final log = read() ?? (throw StateError('No changelog found')); + final release = log.get(version); + release.isYanked = true; + write(log); + return printRelease(release); + } + + String unyank(String version) { + final log = read() ?? (throw StateError('No changelog found')); + final release = log.get(version); + release.isYanked = false; + write(log); + return printRelease(release); + } + /// Reads the project changelog Changelog? read() { if (_file.existsSync()) return parseChangelog(_file.readAsStringSync()); @@ -120,20 +150,28 @@ class ChangelogService { } } -class _LogCommand extends CiderCommand { - _LogCommand() : super('log', 'Add a new entry to the changelog'); +class _Log extends CiderCommand { + _Log() : super('log', 'Add a new entry to the changelog'); } -class _DescribeCommand extends CiderCommand { - _DescribeCommand() : super('describe', 'Print the version description'); +class _Describe extends CiderCommand { + _Describe() : super('describe', 'Print the version description'); } -class _ReleaseCommand extends CiderCommand { - _ReleaseCommand() : super('release', 'Release the unreleased changes') { +class _Release extends CiderCommand { + _Release() : super('release', 'Release the unreleased changes') { argParser.addOption('date', help: 'Release date', defaultsTo: 'today'); } } +class _Yank extends CiderCommand { + _Yank() : super('yank', 'Yank a version from the changelog'); +} + +class _Unyank extends CiderCommand { + _Unyank() : super('unyank', 'Unyank a version from the changelog'); +} + extension _String on String { String get capitalized => substring(0, 1).toUpperCase() + substring(1).toLowerCase(); diff --git a/lib/src/service/pubspec_service.dart b/lib/src/service/pubspec_service.dart index 23803f4..34332e6 100644 --- a/lib/src/service/pubspec_service.dart +++ b/lib/src/service/pubspec_service.dart @@ -33,7 +33,7 @@ class PubspecService { get().writeVersion(version); } get().writeln(get().readVersion()); - return null; + return 0; }); cider.addCommand(_BumpCommand(_bumpCommands.keys), (args, get) { @@ -47,7 +47,7 @@ class PubspecService { build: args['build'], pre: args['pre']); get().writeln(result); - return null; + return 0; }); } diff --git a/pubspec.yaml b/pubspec.yaml index 85041e1..0d18bf1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: cider -version: 0.1.4 +version: 0.1.5 description: Tools for Dart package maintainers. Automates changelog and pubspec.yaml updates. homepage: https://github.com/f3ath/cider repository: https://github.com/f3ath/cider diff --git a/test/functional_test.dart b/test/functional_test.dart index 1abc0e9..9aefae4 100644 --- a/test/functional_test.dart +++ b/test/functional_test.dart @@ -78,6 +78,22 @@ void main() { [1.1.0]: https://github.com/example/project/compare/1.0.0...1.1.0 '''; expect(out.buffer.toString(), step4); + out.buffer.clear(); + await cider.run(['yank', '1.1.0']); + final step5 = ''' +## [1.1.0] - 2021-02-03 \\[YANKED\\] +### Changed +- New turbo V6 engine installed + +### Fixed +- Wheels falling off sporadically + +[1.1.0]: https://github.com/example/project/compare/1.0.0...1.1.0 +'''; + expect(out.buffer.toString(), step5); + out.buffer.clear(); + await cider.run(['unyank', '1.1.0']); + expect(out.buffer.toString(), step4); }); group('Version', () {