[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[tools] Add update-release-info (#5643)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan committed May 18, 2022
1 parent 4660811 commit 4ed29be
Show file tree
Hide file tree
Showing 10 changed files with 1,238 additions and 40 deletions.
4 changes: 3 additions & 1 deletion script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 0.8.6

- Adds `update-release-info` to apply changelog and optional version changes
across multiple packages.
- Fixes changelog validation when reverting to a `NEXT` state.
- Fixes multiplication of `--force` flag when publishing multiple packages.
- Adds minimum deployment target flags to `xcode-analyze` to allow
Expand Down
25 changes: 25 additions & 0 deletions script/tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart update-excerpts --packages plugin_name
```

### Update CHANGELOG and Version

`update-release-info` will automatically update the version and `CHANGELOG.md`
following standard repository style and practice. It can be used for
single-package updates to handle the details of getting the `CHANGELOG.md`
format correct, but is especially useful for bulk updates across multiple packages.

For instance, if you add a new analysis option that requires production
code changes across many packages:

```sh
cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart update-release-info \
--version=minimal \
--changelog="Fixes violations of new analysis option some_new_option."
```

The `minimal` option for `--version` will skip unchanged packages, and treat
each changed package as either `bugfix` or `next` depending on the files that
have changed in that package, so it is often the best choice for a bulk change.

For cases where you know the change time, `minor` or `bugfix` will make the
corresponding version bump, or `next` will update only `CHANGELOG.md` without
changing the version.

### Publish a Release

**Releases are automated for `flutter/plugins` and `flutter/packages`.**
Expand Down
95 changes: 95 additions & 0 deletions script/tool/lib/src/common/package_state_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;

import 'repository_package.dart';

/// The state of a package on disk relative to git state.
@immutable
class PackageChangeState {
/// Creates a new immutable state instance.
const PackageChangeState({
required this.hasChanges,
required this.hasChangelogChange,
required this.needsVersionChange,
});

/// True if there are any changes to files in the package.
final bool hasChanges;

/// True if the package's CHANGELOG.md has been changed.
final bool hasChangelogChange;

/// True if any changes in the package require a version change according
/// to repository policy.
final bool needsVersionChange;
}

/// Checks [package] against [changedPaths] to determine what changes it has
/// and how those changes relate to repository policy about CHANGELOG and
/// version updates.
///
/// [changedPaths] should be a list of POSIX-style paths from a common root,
/// and [relativePackagePath] should be the path to [package] from that same
/// root. Commonly these will come from `gitVersionFinder.getChangedFiles()`
/// and `getRelativePoixPath(package.directory, gitDir.path)` respectively;
/// they are arguments mainly to allow for caching the changed paths for an
/// entire command run.
PackageChangeState checkPackageChangeState(
RepositoryPackage package, {
required List<String> changedPaths,
required String relativePackagePath,
}) {
final String packagePrefix = relativePackagePath.endsWith('/')
? relativePackagePath
: '$relativePackagePath/';

bool hasChanges = false;
bool hasChangelogChange = false;
bool needsVersionChange = false;
for (final String path in changedPaths) {
// Only consider files within the package.
if (!path.startsWith(packagePrefix)) {
continue;
}
final String packageRelativePath = path.substring(packagePrefix.length);
hasChanges = true;

final List<String> components = p.posix.split(packageRelativePath);
if (components.isEmpty) {
continue;
}
final bool isChangelog = components.first == 'CHANGELOG.md';
if (isChangelog) {
hasChangelogChange = true;
}

if (!needsVersionChange &&
!isChangelog &&
// One of a few special files example will be shown on pub.dev, but for
// anything else in the example publishing has no purpose.
!(components.first == 'example' &&
!<String>{'main.dart', 'readme.md', 'example.md'}
.contains(components.last.toLowerCase())) &&
// Changes to tests don't need to be published.
!components.contains('test') &&
!components.contains('androidTest') &&
!components.contains('RunnerTests') &&
!components.contains('RunnerUITests') &&
// The top-level "tool" directory is for non-client-facing utility code,
// so doesn't need to be published.
components.first != 'tool' &&
// Ignoring lints doesn't affect clients.
!components.contains('lint-baseline.xml')) {
needsVersionChange = true;
}
}

return PackageChangeState(
hasChanges: hasChanges,
hasChangelogChange: hasChangelogChange,
needsVersionChange: needsVersionChange);
}
2 changes: 2 additions & 0 deletions script/tool/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'pubspec_check_command.dart';
import 'readme_check_command.dart';
import 'test_command.dart';
import 'update_excerpts_command.dart';
import 'update_release_info_command.dart';
import 'version_check_command.dart';
import 'xcode_analyze_command.dart';

Expand Down Expand Up @@ -70,6 +71,7 @@ void main(List<String> args) {
..addCommand(ReadmeCheckCommand(packagesDir))
..addCommand(TestCommand(packagesDir))
..addCommand(UpdateExcerptsCommand(packagesDir))
..addCommand(UpdateReleaseInfoCommand(packagesDir))
..addCommand(VersionCheckCommand(packagesDir))
..addCommand(XcodeAnalyzeCommand(packagesDir));

Expand Down
Loading

0 comments on commit 4ed29be

Please sign in to comment.