Skip to content

Commit

Permalink
feat: fetch tags before versioning (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold authored Feb 4, 2023
1 parent a3e9bdc commit 3088b7b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,14 @@ Whether to generate and print a link to the prefilled release creation page for
each package after versioning. Defaults to `false`.

[glob]: https://docs.python.org/3/library/glob.html

### `command/version/fetchTags`

Whether to fetch tags from the `origin` remote before versioning. Defaults to
`true`.

```yaml
command:
version:
fetchTags: false
```
4 changes: 4 additions & 0 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ mixin _VersionMixin on _RunMixin {

final commitMessageTemplate = Template(message, delimiters: '{ }');

if (config.commands.version.fetchTags) {
await gitFetchTags(workingDirectory: workspace.path, logger: logger);
}

final packageCommits = await _getPackageCommits(
workspace,
versionPrivatePackages: versionPrivatePackages,
Expand Down
11 changes: 11 additions & 0 deletions packages/melos/lib/src/common/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ Future<String?> gitLatestTagForPackage(
return tags.first;
}

Future<void> gitFetchTags({
required String workingDirectory,
required MelosLogger logger,
}) async {
await gitExecuteCommand(
arguments: ['fetch', '--tags'],
workingDirectory: workingDirectory,
logger: logger,
);
}

/// Stage files matching the specified file pattern for committing.
Future<void> gitAdd(
String filePattern, {
Expand Down
19 changes: 17 additions & 2 deletions packages/melos/lib/src/workspace_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ class VersionCommandConfigs {
this.updateGitTagRefs = false,
this.releaseUrl = false,
List<AggregateChangelogConfig>? aggregateChangelogs,
this.fetchTags = true,
}) : _aggregateChangelogs = aggregateChangelogs;

factory VersionCommandConfigs.fromYaml(
Expand Down Expand Up @@ -489,6 +490,12 @@ class VersionCommandConfigs {
aggregateChangelogs.add(changelogConfig);
}

final fetchTags = assertKeyIsA<bool?>(
key: 'fetchTags',
map: yaml,
path: 'command/version',
);

return VersionCommandConfigs(
branch: branch,
message: message,
Expand All @@ -498,6 +505,7 @@ class VersionCommandConfigs {
updateGitTagRefs: updateGitTagRefs ?? false,
releaseUrl: releaseUrl ?? false,
aggregateChangelogs: aggregateChangelogs,
fetchTags: fetchTags ?? true,
);
}

Expand Down Expand Up @@ -534,6 +542,9 @@ class VersionCommandConfigs {

final List<AggregateChangelogConfig>? _aggregateChangelogs;

/// Whether to fetch tags from the `origin` remote before versioning.
final bool fetchTags;

Map<String, Object?> toJson() {
return {
if (branch != null) 'branch': branch,
Expand All @@ -544,6 +555,7 @@ class VersionCommandConfigs {
'updateGitTagRefs': updateGitTagRefs,
'aggregateChangelogs':
aggregateChangelogs.map((config) => config.toJson()).toList(),
'fetchTags': fetchTags,
};
}

Expand All @@ -559,7 +571,8 @@ class VersionCommandConfigs {
other.updateGitTagRefs == updateGitTagRefs &&
other.releaseUrl == releaseUrl &&
const DeepCollectionEquality()
.equals(other.aggregateChangelogs, aggregateChangelogs);
.equals(other.aggregateChangelogs, aggregateChangelogs) &&
other.fetchTags == fetchTags;

@override
int get hashCode =>
Expand All @@ -571,7 +584,8 @@ class VersionCommandConfigs {
linkToCommits.hashCode ^
updateGitTagRefs.hashCode ^
releaseUrl.hashCode ^
const DeepCollectionEquality().hash(aggregateChangelogs);
const DeepCollectionEquality().hash(aggregateChangelogs) ^
fetchTags.hashCode;

@override
String toString() {
Expand All @@ -585,6 +599,7 @@ VersionCommandConfigs(
updateGitTagRefs: $updateGitTagRefs,
releaseUrl: $releaseUrl,
aggregateChangelogs: $aggregateChangelogs,
fetchTags: $fetchTags,
)''';
}
}
Expand Down

0 comments on commit 3088b7b

Please sign in to comment.