Skip to content

Commit

Permalink
Add yank/unyank commands (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath authored Mar 31, 2023
1 parent 1576332 commit 65bc8a5
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -106,10 +106,26 @@ cider version <new_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 <version>
```
To unyank a version, run the following command:
```
cider unyank <version>
```
### Bumping the project version
Expand Down Expand Up @@ -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/
5 changes: 3 additions & 2 deletions bin/cider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import 'dart:io';

import 'package:cider/cider.dart';

void main(List<String> args) =>
Cider().run(args).then((code) => exitCode = code);
Future<void> main(List<String> args) async {
exitCode = await Cider().run(args);
}
5 changes: 2 additions & 3 deletions lib/src/cider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -80,4 +79,4 @@ class Cider {
}

/// A command handler
typedef Handler = FutureOr<int?> Function(ArgResults args, ServiceLocator get);
typedef Handler = FutureOr<int> Function(ArgResults args, ServiceLocator get);
62 changes: 50 additions & 12 deletions lib/src/service/changelog_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,39 @@ class ChangelogService {
cider.provide((get) =>
ChangelogService(get<Directory>('root'), get<PubspecService>()));

cider.addCommand(_LogCommand(), (args, get) {
cider.addCommand(_Log(), (args, get) {
get<ChangelogService>().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<ChangelogService>().describe(version);
get<Stdout>().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<ChangelogService>().release(parsedDate);
get<Stdout>().writeln(release);
return null;
return 0;
});

cider.addCommand(_Yank(), (args, get) {
final version = args.rest.first;
final release = get<ChangelogService>().yank(version);
get<Stdout>().writeln(release);
return 0;
});

cider.addCommand(_Unyank(), (args, get) {
final version = args.rest.first;
final release = get<ChangelogService>().unyank(version);
get<Stdout>().writeln(release);
return 0;
});
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/service/pubspec_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PubspecService {
get<PubspecService>().writeVersion(version);
}
get<Stdout>().writeln(get<PubspecService>().readVersion());
return null;
return 0;
});

cider.addCommand(_BumpCommand(_bumpCommands.keys), (args, get) {
Expand All @@ -47,7 +47,7 @@ class PubspecService {
build: args['build'],
pre: args['pre']);
get<Stdout>().writeln(result);
return null;
return 0;
});
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/functional_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit 65bc8a5

Please sign in to comment.