Skip to content

Commit

Permalink
fix: More robust version check (#104)
Browse files Browse the repository at this point in the history
* fix: More combust version check

* Switch to regex extraction

Reverted logic in firehose.dart
Updated latestVersion
Added a new latestHeading method
Added lots of test cases

* comment

* Version bump + remove prints
  • Loading branch information
M123-dev authored Jun 13, 2023
1 parent 601d5a8 commit a2dac18
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.16

- More robust version checking, now more diverse changelog formats are accepted.

## 0.3.15

- Make publish tags link to the new release page for that tag, with
Expand Down
21 changes: 20 additions & 1 deletion pkgs/firehose/lib/src/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,27 @@ class Changelog {
bool get exists => file.existsSync();

String? get latestVersion {
var input = latestHeading;

if (input == null) {
return null;
}

final versionRegex = RegExp(r'[0-9]+\.[0-9]+\.[0-9]+(\+[0-9]+)?');

This comment has been minimized.

Copy link
@natebosch

natebosch Jun 13, 2023

Member

I think we need to add something like (-\w+)?


var match = versionRegex.firstMatch(input);

if (match != null) {
var version = match.group(0);
return version;
}
return null;
}

String? get latestHeading {
var sections = _parseSections();
return sections.firstOrNull?.title.substring(3).trim();
// Remove all leading "#"
return sections.firstOrNull?.title.replaceAll(RegExp(r'^#*'), '').trim();
}

List<String> get latestChangeEntries {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: firehose
description: A tool to automate publishing of Pub packages from GitHub actions.
version: 0.3.15
version: 0.3.16
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down
70 changes: 69 additions & 1 deletion pkgs/firehose/test/changelog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,79 @@ void main() {
});
});

test('latestHeading', () {
withChangelog(_defaultContents, (file) {
var changelog = Changelog(file);
var heading = changelog.latestHeading;
expect(heading, '0.3.7+1');
});
});

test('Custom heading extraction', () {
withChangelog('''
## 1.2.3+4 is the new version ## :)
''', (file) {
var changelog = Changelog(file);
var heading = changelog.latestHeading;
expect(heading, '1.2.3+4 is the new version ## :)');
});
});

test('latestVersion', () {
withChangelog(_defaultContents, (file) {
var changelog = Changelog(file);
var version = changelog.latestVersion;
expect(version, isNotNull);
expect(version, '0.3.7+1');
});
});

test('on digit version + x', () {
withChangelog('''
## 1.2.3+4
''', (file) {
var changelog = Changelog(file);
var version = changelog.latestVersion;
expect(version, '1.2.3+4');
});
});

test('multi digit version + x', () {
withChangelog('''
## 123.456.789+123456789
''', (file) {
var changelog = Changelog(file);
var version = changelog.latestVersion;
expect(version, '123.456.789+123456789');
});
});

test('no "+ x" at the end', () {
withChangelog('''
## 123.456.789
''', (file) {
var changelog = Changelog(file);
var version = changelog.latestVersion;
expect(version, '123.456.789');
});
});

test('custom heading version', () {
withChangelog('''
## [4.7.0](https://github.com/...) (2023-05-06)
''', (file) {
var changelog = Changelog(file);
var version = changelog.latestVersion;
expect(version, '4.7.0');
});
});

test('multiple versions mentioned', () {
withChangelog('''
## [4.7.0](https://github.com/.../.../compare/v4.6.0...v4.7.0) (25.05.23)
''', (file) {
var changelog = Changelog(file);
var version = changelog.latestVersion;
expect(version, '4.7.0');
});
});

Expand Down

0 comments on commit a2dac18

Please sign in to comment.