diff --git a/lib/src/chocolatey.dart b/lib/src/chocolatey.dart index 654d65a..233c8e4 100644 --- a/lib/src/chocolatey.dart +++ b/lib/src/chocolatey.dart @@ -15,6 +15,7 @@ import 'dart:convert'; import 'dart:io'; +import 'package:cli_pkg/cli_pkg.dart'; import 'package:grinder/grinder.dart'; import 'package:meta/meta.dart'; import 'package:path/path.dart' as p; @@ -86,6 +87,21 @@ String get chocolateyDartVersion { return result.toString(); } +/// The Chocolatey Repo Url +/// +/// This is used for the Chocolatey verification file. +/// It defaults to [githubRepo]. +final chocolateyRepoUrl = InternalConfigVariable.fn( + () => 'https://github.com/${githubRepo.value}', +); + +/// The Chocolatey Release URL +/// +/// This is the Release URL used for the verification file. +/// It defaults to https://github.com/[githubRepo]/releases/tag/[tag]. +final chocolateyReleaseUrl = InternalConfigVariable.fn(() => + 'https://github.com/${githubRepo.value}/releases/tag/${version.toString()}'); + /// The set of files to include directly in the Chocolatey package. /// /// This should be at least enough files to compile the package's executables. @@ -212,6 +228,8 @@ Future _build() async { writeString("build/chocolatey/tools/LICENSE.txt", await license); + writeString("build/chocolatey/tools/VERIFICATION.txt", _verificationFile); + writeString( 'build/chocolatey/tools/source/pubspec.yaml', json.encode(Map.of(rawPubspec) @@ -320,3 +338,41 @@ String _pathToElement(XmlNode? parent, String name) { return nesting.reversed.join(" > "); } + +// Generates verification file +String get _verificationFile { + final os = Platform.operatingSystem; + final osVersion = Platform.operatingSystemVersion; + final dartInfo = Platform.version; + final tag = version.toString(); + final repo = chocolateyRepoUrl.value; + final releaseUrl = chocolateyReleaseUrl.value; + + final dartVersion = dartInfo.split(' ')[0]; + final contents = '''VERIFICATION +Verification is intended to assist the Chocolatey moderators and community +in verifying that this package's contents are trustworthy. + +The executables in this package are built from source: + +Repository: $repo +Tag: $tag +Release URL: $releaseUrl + +On the following environment: + +* $os - $osVersion +* Dart - $dartInfo + +The following steps are used to build. +1. Install Dart (choco install dart-sdk --version $dartVersion) +2. git clone -b $tag $repo.git +3. Get project dependencies (dart pub get) in project root +4. Install Grinder (dart pub global activate grinder) +5. grind pkg-chocolatey-pack +6. Go to build/chocolatey + +'''; + + return contents; +} diff --git a/test/chocolatey_test.dart b/test/chocolatey_test.dart index 7ce1082..37a8f3f 100644 --- a/test/chocolatey_test.dart +++ b/test/chocolatey_test.dart @@ -16,13 +16,12 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'package:cli_pkg/src/chocolatey.dart'; +import 'package:cli_pkg/src/utils.dart'; import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; import 'package:xml/xml.dart' hide parse; -import 'package:cli_pkg/src/chocolatey.dart'; -import 'package:cli_pkg/src/utils.dart'; - import 'descriptor.dart' as d; import 'utils.dart'; @@ -183,6 +182,26 @@ void main() { .validate(); }); + test('the Verification file', () async { + await d.package(pubspec, _enableChocolatey(), [_nuspec()]).create(); + await (await grind(["pkg-chocolatey"])).shouldExit(0); + final version = dartVersion.isPreRelease ? "1.2.3-beta" : "1.2.3"; + await d + .file( + "my_app/build/chocolatey/tools/VERIFICATION.txt", + allOf([ + contains(Platform.version), + contains(Platform.operatingSystem), + contains(Platform.operatingSystemVersion), + contains(version), + contains('https://github.com/google/right'), + contains( + 'https://github.com/google/right/releases/tag/$version', + ), + ])) + .validate(); + }); + test("Dart", () async { await d.package(pubspec, _enableChocolatey(), [_nuspec()]).create(); await (await grind(["pkg-chocolatey"])).shouldExit(0); @@ -404,6 +423,7 @@ String _enableChocolatey({bool token = true}) { if (token) buffer.writeln('pkg.chocolateyToken.value = "tkn";'); buffer.writeln("pkg.addChocolateyTasks();"); + buffer.writeln('pkg.githubRepo.value = "google/right";'); buffer.writeln("grind(args);"); buffer.writeln("}");