Skip to content

Commit a65733e

Browse files
authored
tool: create tool to bump analysis version (#112)
1 parent e1af2b4 commit a65733e

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

CONTRIBUTING.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,20 @@ accepted.
4242

4343
Every snapshot of a version is saved on its own yaml file under the name pattern: `lib/analysis_options.<version>.yaml`.
4444

45-
To release a new version:
45+
### Release a new version
46+
47+
1. Run the `bump_version` script with the desired new version as an argument:
48+
49+
```sh
50+
dart tool/bump_version/main.dart <version>
51+
```
52+
53+
Where `<version>` is the new version to be released in the format `x.y.z`.
54+
55+
This script will:
56+
57+
- Copy the most recent yaml to a new one with the new desired version.
58+
- Include that file on the main yaml file `lib/analysis_options.yaml`.
4659

47-
1. Copy the most recent yaml to a new one with the new desired version.
48-
1. Include that file on the main yaml file `lib/analysis_options.yaml`.
4960
1. Update the `README.md` exclusion table, refer to the ["Exclusion Reason Table 🗞️👨‍⚖️"](tool/linter_rules/README.md#exclusion-reason-table-️️) documentation for more information.
5061
1. Open a pull request with the proposed changes.

tool/bump_version/main.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/// Bumps the version of the analysis options file.
2+
///
3+
/// This script will:
4+
/// - Copy the most recent yaml to a new one with the new desired version.
5+
/// - Include that file on the main yaml file `lib/analysis_options.yaml.
6+
///
7+
/// ## Usage
8+
///
9+
/// Run this script (from project root):
10+
///
11+
/// ```sh
12+
/// dart tool/bump_version/main.dart <new_version>
13+
/// ```
14+
///
15+
/// Where `<new_version>` is the new version to bump to in the format `x.y.z`.
16+
/// For example: `7.0.0`.
17+
library;
18+
19+
import 'dart:io';
20+
21+
/// A regular expression to match the latest analysis options version.
22+
///
23+
/// Given the following:
24+
///
25+
/// ```sh
26+
/// include: package:very_good_analysis/analysis_options.6.0.0.yaml
27+
/// ```
28+
///
29+
/// It is expected that the first matched group will be `6.0.0`.
30+
final _latestAnalysisVersionRegExp =
31+
RegExp(r'analysis_options\.(\d+\.\d+\.\d+)\.yaml');
32+
33+
void main(List<String> args) {
34+
final analysisOptionsFile = File('lib/analysis_options.yaml');
35+
final content = analysisOptionsFile.readAsStringSync();
36+
final latestVersion =
37+
_latestAnalysisVersionRegExp.firstMatch(content)?.group(1);
38+
39+
final latestAnalysisOptionsFile =
40+
File('lib/analysis_options.$latestVersion.yaml');
41+
42+
final newVersion = args[0];
43+
final newAnalysisOptionsFile = File('lib/analysis_options.$newVersion.yaml');
44+
latestAnalysisOptionsFile.copySync(newAnalysisOptionsFile.path);
45+
46+
final newContent = content.replaceFirst(
47+
_latestAnalysisVersionRegExp,
48+
'analysis_options.$newVersion.yaml',
49+
);
50+
analysisOptionsFile.writeAsStringSync(newContent);
51+
}

0 commit comments

Comments
 (0)