Skip to content

Commit

Permalink
[ci] version_check_command now checks markdown of first CHANGELOG lin…
Browse files Browse the repository at this point in the history
…e. (flutter#7266)

This PR:

* Modifies the `version_check_command` test so it checks the leading markdown of the first line of a CHANGELOG file, to ensure it's `'##'`.
* Fixes the CHANGELOG in two packages that were allowed by the tool before this fix:
  * google_maps_flutter_web
  * interactive_media_ads

## Issues

Fixes flutter/flutter#152638
  • Loading branch information
ditman authored Aug 1, 2024
1 parent 37c4b1c commit f8fbcdb
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 0.5.9
## 0.5.9+1

* Fixes a typo in the formatting of the CHANGELOG.

## 0.5.9

* Updates `package:google_maps` dependency to latest (`^8.0.0`).
* Supports `web: ">=0.5.1 <2.0.0"`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_web
description: Web platform implementation of google_maps_flutter
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 0.5.9
version: 0.5.9+1

environment:
sdk: ^3.4.0
Expand Down
6 changes: 5 additions & 1 deletion packages/interactive_media_ads/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 0.1.1
## 0.1.1+1

* Fixes a typo in the formatting of the CHANGELOG.

## 0.1.1

* Adds iOS implementation.
* Adds support for setting the layout direction of the `AdDisplayContainer`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
*
* This must match the version in pubspec.yaml.
*/
const val pluginVersion = "0.1.1"
const val pluginVersion = "0.1.1+1"
}

override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AdsRequestProxyAPIDelegate: PigeonApiDelegateIMAAdsRequest {
/// The current version of the `interactive_media_ads` plugin.
///
/// This must match the version in pubspec.yaml.
static let pluginVersion = "0.1.1"
static let pluginVersion = "0.1.1+1"

func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer,
Expand Down
2 changes: 1 addition & 1 deletion packages/interactive_media_ads/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: interactive_media_ads
description: A Flutter plugin for using the Interactive Media Ads SDKs on Android and iOS.
repository: https://github.com/flutter/packages/tree/main/packages/interactive_media_ads
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+interactive_media_ads%22
version: 0.1.1 # This must match the version in
version: 0.1.1+1 # This must match the version in
# `android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt` and
# `ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift`

Expand Down
6 changes: 5 additions & 1 deletion script/tool/lib/src/version_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
}
// Remove all leading mark down syntax from the version line.
String? versionString = firstLineWithText?.split(' ').last;
String? leadingMarkdown = firstLineWithText?.split(' ').first;

final String badNextErrorMessage = '${indentation}When bumping the version '
'for release, the NEXT section should be incorporated into the new '
Expand All @@ -413,15 +414,18 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
// CHANGELOG. That means the next version entry in the CHANGELOG should
// pass the normal validation.
versionString = null;
leadingMarkdown = null;
while (iterator.moveNext()) {
if (iterator.current.trim().startsWith('## ')) {
versionString = iterator.current.trim().split(' ').last;
leadingMarkdown = iterator.current.trim().split(' ').first;
break;
}
}
}

if (versionString == null) {
final bool validLeadingMarkdown = leadingMarkdown == '##';
if (versionString == null || !validLeadingMarkdown) {
printError('${indentation}Unable to find a version in CHANGELOG.md');
print('${indentation}The current version should be on a line starting '
'with "## ", either on the first non-empty line or after a "## NEXT" '
Expand Down
35 changes: 35 additions & 0 deletions script/tool/test/version_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,41 @@ void main() {
);
});

test('fails gracefully if the first entry uses the wrong style', () async {
final RepositoryPackage plugin =
createFakePlugin('plugin', packagesDir, version: '1.0.0');

const String changelog = '''
# 1.0.0
* Some changes for a later release.
## 0.9.0
* Some earlier changes.
''';
plugin.changelogFile.writeAsStringSync(changelog);
processRunner.mockProcessesForExecutable['git-show'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(stdout: 'version: 1.0.0')),
];

Error? commandError;
final List<String> output = await runCapturingPrint(runner, <String>[
'version-check',
'--base-sha=main',
], errorHandler: (Error e) {
commandError = e;
});

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains('Unable to find a version in CHANGELOG.md'),
contains('The current version should be on a line starting with '
'"## ", either on the first non-empty line or after a "## NEXT" '
'section.'),
]),
);
});

test(
'fails gracefully if the version headers are not found due to using the wrong style',
() async {
Expand Down

0 comments on commit f8fbcdb

Please sign in to comment.