Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/src/chocolatey.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>(
() => 'https://github.com/${githubRepo.value}',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user hasn't set chocolateyRepoUrl, they may be confused by the fact that they get an error about GitHub even if they aren't using GitHub deployment at all. It's probably better to explicitly fail with a message that says "pkg.chocolateyRepoUrl or pkg.githubRepo must be set to deploy to Chocolatey." Same for chocolateyReleaseUrl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nex3 I have limited time, but I would love to finish this out over this weekend. Do you mind pointing me at some examples of these tests as I am still becoming familiar with the inner workings of the package?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub configuration tests are a pretty good place to look:

group("repo name", () {

);

/// 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<String>(() =>
'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.
Expand Down Expand Up @@ -212,6 +228,8 @@ Future<void> _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)
Expand Down Expand Up @@ -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;
}
26 changes: 23 additions & 3 deletions test/chocolatey_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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("}");

Expand Down