Skip to content

Commit d8c8a4c

Browse files
authored
Support configurable tag prefix in firehose and publish.yaml (#436)
1 parent edfdb3b commit d8c8a4c

8 files changed

Lines changed: 149 additions & 30 deletions

File tree

‎.github/workflows/publish.yaml‎

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ on:
9898
default: ''
9999
required: false
100100
type: string
101+
tag-prefix:
102+
description: >-
103+
The prefix to expect and generate for release git tags (e.g. 'v' or '').
104+
default: "v"
105+
required: false
106+
type: string
101107
local_debug:
102108
description: Whether to use a local copy of package:firehose - only for debug
103109
default: false
@@ -140,7 +146,9 @@ jobs:
140146

141147
- name: Install firehose (internal)
142148
if: ${{ !inputs.local_debug && github.repository == 'dart-lang/ecosystem' }}
143-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref ${{ github.head_ref || github.ref_name }}
149+
env:
150+
GIT_REF: ${{ github.head_ref || github.ref_name }}
151+
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref "$GIT_REF"
144152

145153
- name: Install firehose (external)
146154
if: ${{ !inputs.local_debug && github.repository != 'dart-lang/ecosystem' }}
@@ -169,11 +177,19 @@ jobs:
169177
ISSUE_NUMBER: ${{ github.event.number }}
170178
PR_LABELS: ${{ steps.fetch-labels.outputs.labels }}
171179
INPUTS_IGNORE_PACKAGES: ${{ inputs.ignore-packages }}
180+
INPUTS_TAG_PREFIX: ${{ inputs.tag-prefix }}
181+
USE_FLUTTER: ${{ inputs.use-flutter }}
172182
run: |
183+
if [ "$USE_FLUTTER" = "true" ]; then
184+
FLUTTER_FLAG="--use-flutter"
185+
else
186+
FLUTTER_FLAG="--no-use-flutter"
187+
fi
173188
dart pub global run firehose \
174189
--validate \
175-
${{ fromJSON('{"true":"--use-flutter","false":"--no-use-flutter"}')[inputs.use-flutter] }} \
176-
--ignore-packages "${INPUTS_IGNORE_PACKAGES}"
190+
"$FLUTTER_FLAG" \
191+
--ignore-packages "$INPUTS_IGNORE_PACKAGES" \
192+
--tag-prefix "$INPUTS_TAG_PREFIX"
177193
178194
- name: Get comment id
179195
id: comment-id
@@ -188,18 +204,22 @@ jobs:
188204
continue-on-error: true
189205
env:
190206
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
191-
run: dart pub global run firehose:comment create-or-update --issue ${{ github.event.number }} --body-path output/comment.md
207+
ISSUE_NUMBER: ${{ github.event.number }}
208+
run: dart pub global run firehose:comment create-or-update --issue "$ISSUE_NUMBER" --body-path output/comment.md
192209

193210
- name: Update comment
194211
if: ${{ (hashFiles('output/comment.md') != '') && inputs.write-comments && (steps.comment-id.outputs.comment != '') }}
195212
env:
196213
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
197-
run: dart pub global run firehose:comment create-or-update --comment-id ${{ steps.comment-id.outputs.comment }} --body-path output/comment.md
214+
COMMENT_ID: ${{ steps.comment-id.outputs.comment }}
215+
run: dart pub global run firehose:comment create-or-update --comment-id "$COMMENT_ID" --body-path output/comment.md
198216

199217
- name: Save PR number
200218
if: ${{ !inputs.write-comments }}
219+
env:
220+
ISSUE_NUMBER: ${{ github.event.number }}
201221
run: |
202-
mkdir -p output/ && echo ${{ github.event.number }} > output/issueNumber
222+
mkdir -p output/ && echo "$ISSUE_NUMBER" > output/issueNumber
203223
204224
- name: Upload folder with number and markdown
205225
if: ${{ !inputs.write-comments }}
@@ -244,7 +264,9 @@ jobs:
244264

245265
- name: Install firehose (internal)
246266
if: ${{ !inputs.local_debug && github.repository == 'dart-lang/ecosystem' }}
247-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref ${{ github.head_ref || github.ref_name }}
267+
env:
268+
GIT_REF: ${{ github.head_ref || github.ref_name }}
269+
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref "$GIT_REF"
248270

249271
- name: Install firehose (external)
250272
if: ${{ !inputs.local_debug && github.repository != 'dart-lang/ecosystem' }}
@@ -255,4 +277,16 @@ jobs:
255277
if: ${{ inputs.local_debug }}
256278

257279
- name: Publish packages
258-
run: dart pub global run firehose --publish ${{ fromJSON('{"true":"--use-flutter","false":"--no-use-flutter"}')[inputs.use-flutter] }}
280+
env:
281+
INPUTS_TAG_PREFIX: ${{ inputs.tag-prefix }}
282+
USE_FLUTTER: ${{ inputs.use-flutter }}
283+
run: |
284+
if [ "$USE_FLUTTER" = "true" ]; then
285+
FLUTTER_FLAG="--use-flutter"
286+
else
287+
FLUTTER_FLAG="--no-use-flutter"
288+
fi
289+
dart pub global run firehose \
290+
--publish \
291+
"$FLUTTER_FLAG" \
292+
--tag-prefix "$INPUTS_TAG_PREFIX"

‎pkgs/firehose/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.13.2-wip
22

3+
- Add `--tag-prefix` option to `firehose` and `tag-prefix` input to `publish.yaml` to allow configuring the release tag prefix (defaults to `'v'`).
34
- Run `pub get` before `dart format` in `groundskeeper`.
45
- Add `groundskeeper` executable to format and fix packages.
56
- Add parameter to `locatePackages` to allow locating all packages with `publish_to: none`.

‎pkgs/firehose/bin/firehose.dart‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const helpFlag = 'help';
1212
const validateFlag = 'validate';
1313
const publishFlag = 'publish';
1414
const useFlutterFlag = 'use-flutter';
15+
const tagPrefixOption = 'tag-prefix';
1516

1617
void main(List<String> arguments) async {
1718
final argParser = _createArgs();
@@ -26,6 +27,7 @@ void main(List<String> arguments) async {
2627
final validate = argResults[validateFlag] as bool;
2728
final publish = argResults[publishFlag] as bool;
2829
final useFlutter = argResults[useFlutterFlag] as bool;
30+
final tagPrefix = argResults[tagPrefixOption] as String;
2931
final ignoredPackages = (argResults['ignore-packages'] as List<String>)
3032
.where((pattern) => pattern.isNotEmpty)
3133
.map((pattern) => Glob(pattern, recursive: true))
@@ -47,7 +49,12 @@ void main(List<String> arguments) async {
4749
return;
4850
}
4951

50-
final firehose = Firehose(Directory.current, useFlutter, ignoredPackages);
52+
final firehose = Firehose(
53+
Directory.current,
54+
useFlutter,
55+
ignoredPackages,
56+
tagPrefix: tagPrefix,
57+
);
5158

5259
if (validate) {
5360
await firehose.validate();
@@ -95,6 +102,11 @@ ArgParser _createArgs() => ArgParser()
95102
negatable: true,
96103
help: 'Whether this is a Flutter project.',
97104
)
105+
..addOption(
106+
tagPrefixOption,
107+
defaultsTo: 'v',
108+
help: 'The tag prefix to expect and generate (e.g. "v" or "").',
109+
)
98110
..addMultiOption(
99111
'ignore-packages',
100112
help: 'Which packages to ignore.',

‎pkgs/firehose/lib/firehose.dart‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ class Firehose {
3131
final Directory directory;
3232
final bool useFlutter;
3333
final List<Glob> ignoredPackages;
34+
final String tagPrefix;
3435

35-
Firehose(this.directory, this.useFlutter, this.ignoredPackages);
36+
Firehose(
37+
this.directory,
38+
this.useFlutter,
39+
this.ignoredPackages, {
40+
this.tagPrefix = 'v',
41+
});
3642

3743
/// Validate the packages in the repository.
3844
///
@@ -109,7 +115,7 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
109115
final results = VerificationResults();
110116

111117
for (final package in packages) {
112-
final repoTag = repo.calculateRepoTag(package);
118+
final repoTag = repo.calculateRepoTag(package, tagPrefix: tagPrefix);
113119

114120
print('');
115121
print('Validating $package:${package.name}');
@@ -172,7 +178,11 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
172178
package,
173179
'**ready to publish**',
174180
repoTag,
175-
repo.calculateReleaseUri(package, github),
181+
repo.calculateReleaseUri(
182+
package,
183+
github,
184+
tagPrefix: tagPrefix,
185+
),
176186
);
177187
print(result);
178188
results.addResult(result);
@@ -206,7 +216,7 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
206216
if (!expectEnv(github.refName, 'GITHUB_REF_NAME')) return false;
207217

208218
// Validate the git tag.
209-
final tag = Tag(github.refName!);
219+
final tag = Tag(github.refName!, prefix: tagPrefix);
210220
if (!tag.valid) {
211221
stderr.writeln("Git tag not in expected format: '$tag'");
212222
return false;

‎pkgs/firehose/lib/src/repo.dart‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,20 @@ class Repository {
9090
}
9191
}
9292

93-
String calculateRepoTag(Package package) {
93+
String calculateRepoTag(Package package, {String tagPrefix = 'v'}) {
9494
if (isSinglePackageRepo) {
95-
return 'v${package.pubspec.version}';
95+
return '$tagPrefix${package.pubspec.version}';
9696
} else {
97-
return '${package.name}-v${package.pubspec.version}';
97+
return '${package.name}-$tagPrefix${package.pubspec.version}';
9898
}
9999
}
100100

101-
Uri calculateReleaseUri(Package package, GithubApi github) {
102-
final tag = calculateRepoTag(package);
101+
Uri calculateReleaseUri(
102+
Package package,
103+
GithubApi github, {
104+
String tagPrefix = 'v',
105+
}) {
106+
final tag = calculateRepoTag(package, tagPrefix: tagPrefix);
103107
final title = 'package:${package.name} v${package.pubspec.version}';
104108
final body = package.changelog.describeLatestChanges;
105109
return Uri.https('github.com', '/${github.repoSlug}/releases/new',

‎pkgs/firehose/lib/src/utils.dart‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,47 +59,50 @@ class CommandResult {
5959
class Tag {
6060
/// RegExp matching a version tag at the start of a line.
6161
///
62-
/// A version tag is an optional starting seqeuence of non-whitespace, which
63-
/// is the package name, followed by a `v` and a simplified SemVer version
64-
/// number.
62+
/// A version tag is an optional starting sequence of non-whitespace, which
63+
/// is the package name, followed by [prefix] (defaulting to `'v'`) and a
64+
/// simplified SemVer version number.
6565
///
6666
/// The version number accepted is:
6767
///
6868
/// > digits '.' digits '.' digits
6969
///
7070
/// and if followed by a `+` or `-`, then it includes the remaining
7171
/// non-whitespace characters.
72-
static final RegExp packageVersionTag =
73-
RegExp(r'^(?:(\S+)-)?v(\d+\.\d+\.\d+(?:[+\-]\S*)?)');
72+
static RegExp packageVersionTag({String prefix = 'v'}) => RegExp(
73+
'^(?:(\\S+)-)?${RegExp.escape(prefix)}(\\d+\\.\\d+\\.\\d+(?:[+\\-]\\S*)?)');
7474

7575
/// A package version tag.
7676
///
7777
/// Is expected to have the format:
7878
///
79-
/// > (package-name)? 'v' SemVer-version
79+
/// > (package-name)? prefix SemVer-version
8080
///
8181
/// If not, the tag is not [valid], and the [package] and [version] will both
8282
/// be `null`.
8383
final String tag;
84+
final String prefix;
8485

85-
Tag(this.tag);
86+
Tag(this.tag, {this.prefix = 'v'});
87+
88+
late final Match? _match = packageVersionTag(prefix: prefix).firstMatch(tag);
8689

8790
bool get valid => version != null;
8891

89-
/// The package name before the `v` in the version [tag], if any.
92+
/// The package name before the prefix in the version [tag], if any.
9093
///
91-
/// Is `null` if there is no package name before the `v`,
94+
/// Is `null` if there is no package name before the prefix,
9295
/// or if the tag is not [valid].
93-
String? get package => packageVersionTag.firstMatch(tag)?[1];
96+
String? get package => _match?[1];
9497

9598
/// The SemVer version string of the version [tag], if any.
9699
///
97-
/// This is the part after the `v` of the [tag] string,
100+
/// This is the part after the prefix of the [tag] string,
98101
/// of the form, which is a major/minor/patch version string
99102
/// optionally followed by a `+` and more characters.
100103
///
101104
/// Is `null` if the tag is not [valid].
102-
String? get version => packageVersionTag.firstMatch(tag)?[2];
105+
String? get version => _match?[2];
103106

104107
@override
105108
String toString() => tag;

‎pkgs/firehose/test/repo_test.dart‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ void main() {
6565
allOf(contains(package.name), contains(package.version.toString())));
6666
expect(queryParams['body'], package.changelog.describeLatestChanges);
6767
});
68+
69+
test('github release link with custom prefix', () {
70+
final github = GithubApi(
71+
repoSlug: RepositorySlug.full('dart-lang/ecosystem'),
72+
);
73+
final package = packages.locatePackages().first;
74+
final releaseUri = packages.calculateReleaseUri(
75+
package,
76+
github,
77+
tagPrefix: '',
78+
);
79+
expect(releaseUri.path, '/${github.repoSlug}/releases/new');
80+
81+
final queryParams = releaseUri.queryParameters;
82+
expect(
83+
queryParams['tag'],
84+
packages.calculateRepoTag(package, tagPrefix: ''),
85+
);
86+
expect(queryParams['tag'], '${package.name}-${package.pubspec.version}');
87+
});
6888
});
6989

7090
group('pub workspace repo', () {

‎pkgs/firehose/test/utils_test.dart‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,40 @@ void main() {
6262
tag = Tag('foobar-1.2.3');
6363
expect(tag.valid, false);
6464
});
65+
66+
test('empty prefix single package repo', () {
67+
final tag = Tag('1.2.3', prefix: '');
68+
expect(tag.valid, true);
69+
expect(tag.package, isNull);
70+
expect(tag.version, '1.2.3');
71+
});
72+
73+
test('empty prefix single package repo pre-release', () {
74+
final tag = Tag('1.2.3-beta', prefix: '');
75+
expect(tag.valid, true);
76+
expect(tag.package, isNull);
77+
expect(tag.version, '1.2.3-beta');
78+
});
79+
80+
test('empty prefix mono repo', () {
81+
final tag = Tag('foobar-1.2.3', prefix: '');
82+
expect(tag.valid, true);
83+
expect(tag.package, 'foobar');
84+
expect(tag.version, '1.2.3');
85+
});
86+
87+
test('custom prefix single package repo', () {
88+
final tag = Tag('rel-1.2.3', prefix: 'rel-');
89+
expect(tag.valid, true);
90+
expect(tag.package, isNull);
91+
expect(tag.version, '1.2.3');
92+
});
93+
94+
test('custom prefix mono repo', () {
95+
final tag = Tag('foobar-rel-1.2.3', prefix: 'rel-');
96+
expect(tag.valid, true);
97+
expect(tag.package, 'foobar');
98+
expect(tag.version, '1.2.3');
99+
});
65100
});
66101
}

0 commit comments

Comments
 (0)