-
Notifications
You must be signed in to change notification settings - Fork 351
/
double_check.dart
51 lines (42 loc) · 1.6 KB
/
double_check.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2019 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'dart:io';
import 'package:cli_pkg/cli_pkg.dart' as pkg;
import 'package:grinder/grinder.dart';
import 'package:path/path.dart' as p;
import 'package:pub_api_client/pub_api_client.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:sass/src/utils.dart';
import 'utils.dart';
@Task('Verify that the package is in a good state to release.')
Future<void> doubleCheckBeforeRelease() async {
var ref = environment("GITHUB_REF");
if (ref != "refs/tags/${pkg.version}") {
fail("GITHUB_REF $ref is different than pubspec version ${pkg.version}.");
}
if (listEquals(pkg.version.preRelease, ["dev"])) {
fail("${pkg.version} is a dev release.");
}
var versionHeader =
RegExp("^## ${RegExp.escape(pkg.version.toString())}\$", multiLine: true);
if (!File("CHANGELOG.md").readAsStringSync().contains(versionHeader)) {
fail("There's no CHANGELOG entry for ${pkg.version}.");
}
var client = PubClient();
try {
for (var dir in [
".",
...Directory("pkg").listSync().map((entry) => entry.path)
]) {
var pubspec = Pubspec.parse(File("$dir/pubspec.yaml").readAsStringSync(),
sourceUrl: p.toUri("$dir/pubspec.yaml"));
var package = await client.packageInfo(pubspec.name);
if (pubspec.version == package.latestPubspec.version) {
fail("${pubspec.name} ${pubspec.version} has already been released!");
}
}
} finally {
client.close();
}
}