Skip to content

Commit bf35c1b

Browse files
stuartmorgan-gfkorotkov
authored andcommitted
[tools] Add update-release-info (flutter#5643)
1 parent 72c1752 commit bf35c1b

10 files changed

+1238
-40
lines changed

script/tool/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 0.8.6
22

3+
- Adds `update-release-info` to apply changelog and optional version changes
4+
across multiple packages.
35
- Fixes changelog validation when reverting to a `NEXT` state.
46
- Fixes multiplication of `--force` flag when publishing multiple packages.
57
- Adds minimum deployment target flags to `xcode-analyze` to allow

script/tool/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,31 @@ cd <repository root>
118118
dart run ./script/tool/bin/flutter_plugin_tools.dart update-excerpts --packages plugin_name
119119
```
120120

121+
### Update CHANGELOG and Version
122+
123+
`update-release-info` will automatically update the version and `CHANGELOG.md`
124+
following standard repository style and practice. It can be used for
125+
single-package updates to handle the details of getting the `CHANGELOG.md`
126+
format correct, but is especially useful for bulk updates across multiple packages.
127+
128+
For instance, if you add a new analysis option that requires production
129+
code changes across many packages:
130+
131+
```sh
132+
cd <repository root>
133+
dart run ./script/tool/bin/flutter_plugin_tools.dart update-release-info \
134+
--version=minimal \
135+
--changelog="Fixes violations of new analysis option some_new_option."
136+
```
137+
138+
The `minimal` option for `--version` will skip unchanged packages, and treat
139+
each changed package as either `bugfix` or `next` depending on the files that
140+
have changed in that package, so it is often the best choice for a bulk change.
141+
142+
For cases where you know the change time, `minor` or `bugfix` will make the
143+
corresponding version bump, or `next` will update only `CHANGELOG.md` without
144+
changing the version.
145+
121146
### Publish a Release
122147

123148
**Releases are automated for `flutter/plugins` and `flutter/packages`.**
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:meta/meta.dart';
6+
import 'package:path/path.dart' as p;
7+
8+
import 'repository_package.dart';
9+
10+
/// The state of a package on disk relative to git state.
11+
@immutable
12+
class PackageChangeState {
13+
/// Creates a new immutable state instance.
14+
const PackageChangeState({
15+
required this.hasChanges,
16+
required this.hasChangelogChange,
17+
required this.needsVersionChange,
18+
});
19+
20+
/// True if there are any changes to files in the package.
21+
final bool hasChanges;
22+
23+
/// True if the package's CHANGELOG.md has been changed.
24+
final bool hasChangelogChange;
25+
26+
/// True if any changes in the package require a version change according
27+
/// to repository policy.
28+
final bool needsVersionChange;
29+
}
30+
31+
/// Checks [package] against [changedPaths] to determine what changes it has
32+
/// and how those changes relate to repository policy about CHANGELOG and
33+
/// version updates.
34+
///
35+
/// [changedPaths] should be a list of POSIX-style paths from a common root,
36+
/// and [relativePackagePath] should be the path to [package] from that same
37+
/// root. Commonly these will come from `gitVersionFinder.getChangedFiles()`
38+
/// and `getRelativePoixPath(package.directory, gitDir.path)` respectively;
39+
/// they are arguments mainly to allow for caching the changed paths for an
40+
/// entire command run.
41+
PackageChangeState checkPackageChangeState(
42+
RepositoryPackage package, {
43+
required List<String> changedPaths,
44+
required String relativePackagePath,
45+
}) {
46+
final String packagePrefix = relativePackagePath.endsWith('/')
47+
? relativePackagePath
48+
: '$relativePackagePath/';
49+
50+
bool hasChanges = false;
51+
bool hasChangelogChange = false;
52+
bool needsVersionChange = false;
53+
for (final String path in changedPaths) {
54+
// Only consider files within the package.
55+
if (!path.startsWith(packagePrefix)) {
56+
continue;
57+
}
58+
final String packageRelativePath = path.substring(packagePrefix.length);
59+
hasChanges = true;
60+
61+
final List<String> components = p.posix.split(packageRelativePath);
62+
if (components.isEmpty) {
63+
continue;
64+
}
65+
final bool isChangelog = components.first == 'CHANGELOG.md';
66+
if (isChangelog) {
67+
hasChangelogChange = true;
68+
}
69+
70+
if (!needsVersionChange &&
71+
!isChangelog &&
72+
// One of a few special files example will be shown on pub.dev, but for
73+
// anything else in the example publishing has no purpose.
74+
!(components.first == 'example' &&
75+
!<String>{'main.dart', 'readme.md', 'example.md'}
76+
.contains(components.last.toLowerCase())) &&
77+
// Changes to tests don't need to be published.
78+
!components.contains('test') &&
79+
!components.contains('androidTest') &&
80+
!components.contains('RunnerTests') &&
81+
!components.contains('RunnerUITests') &&
82+
// The top-level "tool" directory is for non-client-facing utility code,
83+
// so doesn't need to be published.
84+
components.first != 'tool' &&
85+
// Ignoring lints doesn't affect clients.
86+
!components.contains('lint-baseline.xml')) {
87+
needsVersionChange = true;
88+
}
89+
}
90+
91+
return PackageChangeState(
92+
hasChanges: hasChanges,
93+
hasChangelogChange: hasChangelogChange,
94+
needsVersionChange: needsVersionChange);
95+
}

script/tool/lib/src/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import 'pubspec_check_command.dart';
2929
import 'readme_check_command.dart';
3030
import 'test_command.dart';
3131
import 'update_excerpts_command.dart';
32+
import 'update_release_info_command.dart';
3233
import 'version_check_command.dart';
3334
import 'xcode_analyze_command.dart';
3435

@@ -70,6 +71,7 @@ void main(List<String> args) {
7071
..addCommand(ReadmeCheckCommand(packagesDir))
7172
..addCommand(TestCommand(packagesDir))
7273
..addCommand(UpdateExcerptsCommand(packagesDir))
74+
..addCommand(UpdateReleaseInfoCommand(packagesDir))
7375
..addCommand(VersionCheckCommand(packagesDir))
7476
..addCommand(XcodeAnalyzeCommand(packagesDir));
7577

0 commit comments

Comments
 (0)