Skip to content

Commit

Permalink
Add a command to promote to release (addresses #32) (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath authored Dec 10, 2022
1 parent ee6ac8f commit e17bd18
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 48 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

container:
image: google/dart:latest

image: dart:stable
steps:
- uses: actions/checkout@v2
- name: Install dependencies
Expand All @@ -25,4 +21,4 @@ jobs:
- name: Tests
run: dart test --coverage=.coverage
- name: Coverage
run: dart run coverage:format_coverage -l -c -i .coverage --report-on=lib --packages=.packages | dart run check_coverage:check_coverage 94
run: dart run coverage:format_coverage -l -c -i .coverage --report-on=lib --packages=.dart_tool/package_config.json | dart run check_coverage:check_coverage 94
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.2] - 2022-12-07
### Added
- Release promotion command

## [0.1.1] - 2021-12-28
### Changed
- Updated dependencies
Expand Down Expand Up @@ -62,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial version

[0.1.2]: https://github.com/f3ath/cider/compare/0.1.1...0.1.2
[0.1.1]: https://github.com/f3ath/cider/compare/0.1.0...0.1.1
[0.1.0]: https://github.com/f3ath/cider/compare/0.0.5...0.1.0
[0.0.5]: https://github.com/f3ath/cider/compare/0.0.4...0.0.5
Expand Down
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ 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
### Bumping the project version
Expand All @@ -126,6 +126,7 @@ cider bump <part> [options]
- `patch`
- `build`
- `pre` (pre-release)
- `release` (promotes the version to a release, removing the pre-release part)
Options:
Expand All @@ -142,19 +143,21 @@ 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
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+43
[logo]: https://raw.githubusercontent.com/f3ath/cider/master/cider.png
Expand Down
Binary file modified cider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions lib/src/service/changelog_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class ChangelogService {

cider.addCommand(_LogCommand(), (args, get) {
get<ChangelogService>().addUnreleased(args.rest.first, args.rest[1]);
return null;
});

cider.addCommand(_DescribeCommand(), (args, get) {
final version = args.rest.isEmpty ? null : args.rest.first;
final section = get<ChangelogService>().describe(version);
get<Stdout>().writeln(section);
return null;
});

cider.addCommand(_ReleaseCommand(), (args, get) {
Expand All @@ -33,6 +35,7 @@ class ChangelogService {
date == 'today' ? DateTime.now() : DateTime.parse(date);
final release = get<ChangelogService>().release(parsedDate);
get<Stdout>().writeln(release);
return null;
});
}

Expand Down Expand Up @@ -79,6 +82,7 @@ class ChangelogService {
/// Reads the project changelog
Changelog? read() {
if (_file.existsSync()) return parseChangelog(_file.readAsStringSync());
return null;
}

/// Returns a markdown description of the given [version] or the `Unreleased`
Expand Down
36 changes: 19 additions & 17 deletions lib/src/service/pubspec_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ class PubspecService {
PubspecService(Directory root)
: _file = File(join(root.path, 'pubspec.yaml'));

static final _bumpCommands = <String, VersionMutation>{
'breaking': BumpBreaking(),
'build': BumpBuild(),
'major': BumpMajor(),
'minor': BumpMinor(),
'patch': BumpPatch(),
'pre': BumpPreRelease(),
'release': Release(),
};

/// Publishes the [PubspecService] and installs commands (`version`, `bump`)
static void install(Cider cider) {
cider.provide((get) => PubspecService(get<Directory>('root')));
Expand All @@ -23,9 +33,10 @@ class PubspecService {
get<PubspecService>().writeVersion(version);
}
get<Stdout>().writeln(get<PubspecService>().readVersion());
return null;
});

cider.addCommand(_BumpCommand(), (args, get) {
cider.addCommand(_BumpCommand(_bumpCommands.keys), (args, get) {
final pubspec = get<PubspecService>();
final part = args.command?.name;
if (part == null) throw 'Version part must be specified';
Expand All @@ -36,6 +47,7 @@ class PubspecService {
build: args['build'],
pre: args['pre']);
get<Stdout>().writeln(result);
return null;
});
}

Expand All @@ -59,15 +71,7 @@ class PubspecService {
bool bumpBuild = false,
String build = '',
String pre = ''}) {
final map = <String, VersionMutation>{
'breaking': BumpBreaking(),
'major': BumpMajor(),
'minor': BumpMinor(),
'patch': BumpPatch(),
'pre': BumpPreRelease(),
'build': BumpBuild(),
};
var mutation = map[part.toLowerCase()] ??
var mutation = _bumpCommands[part.toLowerCase()] ??
(throw ArgumentError('Invalid version part'));
if (keepBuild) {
mutation = KeepBuild(mutation);
Expand Down Expand Up @@ -114,14 +118,12 @@ class _VersionCommand extends CiderCommand {
}

class _BumpCommand extends CiderCommand {
_BumpCommand() : super('bump', 'Bump project version') {
_BumpCommand(Iterable<String> commands)
: super('bump', 'Bump project version') {
for (final command in commands) {
argParser.addCommand(command);
}
argParser
..addCommand('breaking')
..addCommand('major')
..addCommand('minor')
..addCommand('patch')
..addCommand('pre')
..addCommand('build')
..addFlag('keep-build', help: 'Keep the existing build')
..addFlag('bump-build', help: 'Also bump the build')
..addOption('build',
Expand Down
14 changes: 7 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: cider
version: 0.1.1
version: 0.1.2
description: Tools for Dart package maintainers. Automates changelog and pubspec.yaml updates.
homepage: https://github.com/f3ath/cider
repository: https://github.com/f3ath/cider
issue_tracker: https://github.com/f3ath/cider/issues
environment:
sdk: ">=2.15.1 <3.0.0"
sdk: ">=2.17.0 <3.0.0"
dependencies:
args: ^2.0.0
change: ^0.3.1
change: ^0.5.0
klizma: ^0.2.0
intl: ^0.17.0
markdown: ^4.0.0
marker: ^0.2.2
markdown: ^6.0.0
marker: ^0.4.0
path: ^1.6.0
pub_semver: ^2.0.0
version_manipulation: ^0.1.0
version_manipulation: ^0.1.1
yaml: ^3.1.0
rfc_6901: ^0.1.0
pubspec_parse: ^1.0.0

dev_dependencies:
lints: ^1.0.1
lints: ^2.0.1
test: ^1.15.3
coverage: ^1.0.2
check_coverage: ^0.0.2
Expand Down
4 changes: 3 additions & 1 deletion test/functional_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ void main() {
['bump', 'pre', '--bump-build']: '0.0.5-alpha.1+43',
['bump', 'pre', '--build=foo']: '0.0.5-alpha.1+foo',
['bump', 'pre', '--pre=beta']: '0.0.5-beta',
['bump', 'release']: '0.0.5',
['bump', 'release', '--keep-build']: '0.0.5+42',
}.forEach((args, expected) {
test(args.join(' ') + ' => $expected', () async {
test('${args.join(' ')} => $expected', () async {
final code = await cider.run(args);
expect(code, 0);
out.buffer.clear();
Expand Down

0 comments on commit e17bd18

Please sign in to comment.