Skip to content

Commit

Permalink
fix an issue validating pre-release git publishing tags (#180)
Browse files Browse the repository at this point in the history
* fix an issue validating pre-release git publishing tags

* fix changelog version parsing as well

* review feedback
  • Loading branch information
devoncarew authored Sep 28, 2023
1 parent 1154183 commit 297e63e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 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.32

- Fix an issue validating pre-release git publishing tags (#176).

## 0.3.31

- Add PR Health checks for breaking changes.
Expand Down
18 changes: 7 additions & 11 deletions pkgs/firehose/lib/src/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ class Changelog {
/// Pattern recognizing some SemVer formats.
///
/// Accepts:
/// > digits '.' digits '.' digits
///
/// optionally followed by `-` or `+` character
/// and one or more "word characters", which are
/// ASCII letters (`a`-`z`, `A`-`Z`), digits (`0`-`9`),
/// underscore (`_`) and dollar-sign (`$`).
/// > digits '.' digits '.' digits
///
/// This is not all complete SemVer version strings,
/// since it doesn't allow `.` in the continuation,
/// or a `+...` sequence after a `-` sequence.
/// It should be enough for the user-cases we need it for
/// in this package.
static final _versionRegex = RegExp(r'\d+\.\d+\.\d+(?:[\-+]\w+)?');
/// optionally followed by `-` or `+` character and one of more non-whitespace
/// characters, without validating them as valid semver.
///
/// This is not all complete SemVer version strings but it should be enough
/// for the user-cases we need it for in this package.
static final _versionRegex = RegExp(r'\d+\.\d+\.\d+(?:[+\-]\S*)?');

String? get latestVersion {
var input = latestHeading;
Expand Down
20 changes: 11 additions & 9 deletions pkgs/firehose/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,27 @@ Future<int> runCommand(
class Tag {
/// RegExp matching a version tag at the start of a line.
///
/// A version tag is an optional starting seqeuence
/// of non-whitespace, which is the package name,
/// followed by a `v` and a simplified SemVer version
/// A version tag is an optional starting seqeuence of non-whitespace, which
/// is the package name, followed by a `v` and a simplified SemVer version
/// number.
/// The version number accepted is
///
/// The version number accepted is:
///
/// > digits '.' digits '.' digits
///
/// and if followed by a `+`, then it includes the
/// rest of the line.
/// and if followed by a `+` or `-`, then it includes the remaining
/// non-whitespace characters.
static final RegExp packageVersionTag =
RegExp(r'^(?:(\S+)-)?v(\d+\.\d+\.\d+(?:\+.*)?)');
RegExp(r'^(?:(\S+)-)?v(\d+\.\d+\.\d+(?:[+\-]\S*)?)');

/// A package version tag.
///
/// Is expected to have the format:
///
/// > (package-name)? 'v' SemVer-version
///
/// If not, the tag is not [valid], and the [package] and [version]
/// will both be `null`.
/// If not, the tag is not [valid], and the [package] and [version] will both
/// be `null`.
final String tag;

Tag(this.tag);
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.31
version: 0.3.32
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down
10 changes: 10 additions & 0 deletions pkgs/firehose/test/changelog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ void main() {
});
});

test('with prerelease tag 2', () {
withChangelog('''
## 123.456.789-beta.2
''', (file) {
var changelog = Changelog(file);
var version = changelog.latestVersion;
expect(version, '123.456.789-beta.2');
});
});

test('custom heading version', () {
withChangelog('''
## [4.7.0](https://github.com/...) (2023-05-06)
Expand Down
11 changes: 11 additions & 0 deletions pkgs/firehose/test/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void main() {
expect(tag.version, '1.2.3');
});

test('pre-release package repo', () {
var tag = Tag('v1.2.3-beta');
expect(tag.version, '1.2.3-beta');
});

test('service release', () {
var tag = Tag('v1.2.3+1');
expect(tag.version, '1.2.3+1');
Expand All @@ -39,6 +44,12 @@ void main() {
expect(tag.version, '1.2.3');
});

test('mono repo pre-release', () {
var tag = Tag('foo_bar-v1.2.3-dev.1');
expect(tag.package, 'foo_bar');
expect(tag.version, '1.2.3-dev.1');
});

test('mono repo bad', () {
var tag = Tag('foobar_v1.2.3');
expect(tag.valid, false);
Expand Down

0 comments on commit 297e63e

Please sign in to comment.