Skip to content

Commit

Permalink
Added publish command --noCommit option
Browse files Browse the repository at this point in the history
Resolves #32
  • Loading branch information
jakubmeysner committed May 1, 2024
1 parent cf90cff commit 20d34dc
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 68 deletions.
26 changes: 26 additions & 0 deletions MSStore.CLI.UnitTests/PublishCommandUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,31 @@ public async Task PublishCommandForMSIXAppsShouldSucceed()
result.Should().Contain("Submission commit success! Here is some data:");
result.Should().Contain("test.msix");
}

[TestMethod]
public async Task PublishCommandForMSIXAppsWithNoCommitShouldNotCommit()
{
var path = CopyFilesRecursively("MSIXProject");

var msixPath = Path.Combine(path, "test.msix");

AddDefaultFakeSuccessfulSubmission();

var result = await ParseAndInvokeAsync(
new string[]
{
"publish",
msixPath,
"--appId",
FakeApps[0].Id!,
"--verbose",
"--noCommit"
});

ZipFileManager
.Verify(x => x.ExtractZip(It.IsAny<string>(), It.IsAny<string>()), Times.Never);

result.Should().Contain("Skipping submission commit.");
}
}
}
50 changes: 39 additions & 11 deletions MSStore.CLI/Commands/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,30 @@ bool IsUri()
});

Output = new Option<DirectoryInfo?>(
aliases: new string[] { "--output", "-o" },
aliases: new string[]
{
"--output",
"-o"
},
description: "The output directory where the packaged app will be stored. If not provided, the default directory for each different type of app will be used.");

Arch = new Option<IEnumerable<BuildArch>>(
aliases: new string[] { "--arch", "-a" },
aliases: new string[]
{
"--arch",
"-a"
},
description: "The architecture(s) to build for. If not provided, the default architecture for the current OS, and project type, will be used.")
{
AllowMultipleArgumentsPerToken = true,
};

Version = new Option<Version?>(
aliases: new string[] { "--version", "-ver" },
aliases: new string[]
{
"--version",
"-ver"
},
parseArgument: result =>
{
var version = result.Tokens.Single().Value;
Expand All @@ -99,19 +111,29 @@ public InitCommand()
AddArgument(PathOrUrl);

var publisherDisplayName = new Option<string>(
aliases: new string[] { "--publisherDisplayName", "-n" },
aliases: new string[]
{
"--publisherDisplayName",
"-n"
},
description: "The Publisher Display Name used to configure the application. If provided, avoids an extra APIs call.");

AddOption(publisherDisplayName);

var package = new Option<bool>(
aliases: new string[] { "--package" },
aliases: new string[]
{
"--package"
},
description: "If supported by the app type, automatically packs the project.");

AddOption(package);

var publish = new Option<bool>(
aliases: new string[] { "--publish" },
aliases: new string[]
{
"--publish"
},
description: "If supported by the app type, automatically publishes the project. Implies '--package true'");

AddOption(publish);
Expand Down Expand Up @@ -187,9 +209,15 @@ public async Task<int> InvokeAsync(InvocationContext context)

var props = new Dictionary<string, string>
{
{ "withPDN", (PublisherDisplayName != null).ToString() },
{ "Package", (Package == true).ToString() },
{ "Publish", (Publish == true).ToString() }
{
"withPDN", (PublisherDisplayName != null).ToString()
},
{
"Package", (Package == true).ToString()
},
{
"Publish", (Publish == true).ToString()
}
};

if (configurator == null)
Expand Down Expand Up @@ -356,7 +384,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
return await _telemetryClient.TrackCommandEventAsync<Handler>(-5, props, ct);
}

result = await projectPublisher.PublishAsync(PathOrUrl, app, outputDirectory, storePackagedAPI, ct);
result = await projectPublisher.PublishAsync(PathOrUrl, app, outputDirectory, false, storePackagedAPI, ct);
}

return await _telemetryClient.TrackCommandEventAsync<Handler>(result, props, ct);
Expand Down Expand Up @@ -437,4 +465,4 @@ private async Task OpenMicrosoftStoreRegistrationPageAsync(CancellationToken ct)
}
}
}
}
}
29 changes: 25 additions & 4 deletions MSStore.CLI/Commands/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public PublishCommand()
AddArgument(InitCommand.PathOrUrl);

var inputDirectory = new Option<DirectoryInfo?>(
aliases: new string[] { "--inputDirectory", "-i" },
aliases: new string[]
{
"--inputDirectory",
"-i"
},
description: "The directory where the '.msix' or '.msixupload' file to be used for the publishing command. If not provided, the cli will try to find the best candidate based on the 'pathOrUrl' argument.",
parseArgument: result =>
{
Expand All @@ -50,10 +54,25 @@ public PublishCommand()
AddOption(inputDirectory);

var appIdOption = new Option<string>(
aliases: new string[] { "--appId", "-id" },
aliases: new string[]
{
"--appId",
"-id"
},
description: "Specifies the Application Id. Only needed if the project has not been initialized before with the 'init' command.");

AddOption(appIdOption);

var noCommitOption = new Option<bool>(
aliases: new string[]
{
"--noCommit",
"-nc"
},
description: "Disables committing the submission, keeping it in draft state.",
getDefaultValue: () => false);

AddOption(noCommitOption);
}

public new class Handler : ICommandHandler
Expand All @@ -69,6 +88,8 @@ public new class Handler : ICommandHandler

public DirectoryInfo? InputDirectory { get; set; } = null!;

public bool NoCommit { get; set; }

public Handler(
IProjectConfiguratorFactory projectConfiguratorFactory,
IStoreAPIFactory storeAPIFactory,
Expand Down Expand Up @@ -135,8 +156,8 @@ public async Task<int> InvokeAsync(InvocationContext context)
}

return await _telemetryClient.TrackCommandEventAsync<Handler>(
await projectPublisher.PublishAsync(PathOrUrl, app, InputDirectory, storePackagedAPI, ct), props, ct);
await projectPublisher.PublishAsync(PathOrUrl, app, InputDirectory, NoCommit, storePackagedAPI, ct), props, ct);
}
}
}
}
}
47 changes: 32 additions & 15 deletions MSStore.CLI/Helpers/IStorePackagedAPIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ private static async IAsyncEnumerable<DevCenterSubmissionStatusResponse> Enumera
yield return submissionStatus;
}
while ("CommitStarted".Equals(submissionStatus.Status, StringComparison.Ordinal)
&& submissionStatus.StatusDetails?.Errors.IsNullOrEmpty() == true
&& submissionStatus.StatusDetails?.CertificationReports.IsNullOrEmpty() == true);
&& submissionStatus.StatusDetails?.Errors.IsNullOrEmpty() == true
&& submissionStatus.StatusDetails?.CertificationReports.IsNullOrEmpty() == true);
}

public static async Task<DevCenterSubmissionStatusResponse?> PollSubmissionStatusAsync(this IStorePackagedAPI storePackagedAPI, string productId, string submissionId, bool waitFirst, ILogger? logger, CancellationToken ct = default)
Expand Down Expand Up @@ -165,7 +165,7 @@ public static async Task<int> HandleLastSubmissionStatusAsync(this IStorePackage
await browserLauncher.OpenBrowserAsync($"https://partner.microsoft.com/dashboard/products/{productId}/submissions/{submissionId}/ageratings", true, ct);
}
else if (lastSubmissionStatus.StatusDetails?.Errors?.Count == 1 &&
error?.Code == "InvalidState")
error?.Code == "InvalidState")
{
AnsiConsole.WriteLine("Submission has failed. Submission has active validation errors which cannot be exposed via API.");

Expand Down Expand Up @@ -291,7 +291,22 @@ public static async Task<bool> DeleteSubmissionAsync(this IStorePackagedAPI stor
return application;
}

public static async Task<int> PublishAsync(this IStorePackagedAPI storePackagedAPI, DevCenterApplication app, FirstSubmissionDataCallback firstSubmissionDataCallback, AllowTargetFutureDeviceFamily[] allowTargetFutureDeviceFamilies, DirectoryInfo output, IEnumerable<FileInfo> input, IBrowserLauncher _browserLauncher, IConsoleReader consoleReader, IZipFileManager zipFileManager, IFileDownloader fileDownloader, IAzureBlobManager azureBlobManager, IEnvironmentInformationService environmentInformationService, ILogger logger, CancellationToken ct)
public static async Task<int> PublishAsync(
this IStorePackagedAPI storePackagedAPI,
DevCenterApplication app,
FirstSubmissionDataCallback firstSubmissionDataCallback,
AllowTargetFutureDeviceFamily[] allowTargetFutureDeviceFamilies,
DirectoryInfo output,
IEnumerable<FileInfo> input,
bool noCommit,
IBrowserLauncher _browserLauncher,
IConsoleReader consoleReader,
IZipFileManager zipFileManager,
IFileDownloader fileDownloader,
IAzureBlobManager azureBlobManager,
IEnvironmentInformationService environmentInformationService,
ILogger logger,
CancellationToken ct)
{
if (app?.Id == null)
{
Expand Down Expand Up @@ -440,6 +455,12 @@ public static async Task<int> PublishAsync(this IStorePackagedAPI storePackagedA
return -1;
}

if (noCommit)
{
AnsiConsole.WriteLine("Skipping submission commit.");
return 0;
}

var submissionCommit = await storePackagedAPI.CommitSubmissionAsync(app.Id, submission.Id, ct);

if (submissionCommit == null)
Expand Down Expand Up @@ -506,8 +527,7 @@ public static async Task<int> PublishAsync(this IStorePackagedAPI storePackagedA
var newApplicationPackage = new ApplicationPackage
{
FileStatus = FileStatus.PendingUpload,
FileName = file.Name
FileStatus = FileStatus.PendingUpload, FileName = file.Name
};
submission.ApplicationPackages.Add(newApplicationPackage);
Expand All @@ -525,9 +545,9 @@ public static async Task<int> PublishAsync(this IStorePackagedAPI storePackagedA
if (listing.Value?.BaseListing?.Images?.Count > 0)
{
var imagesToDownload = listing.Value.BaseListing.Images.Where(i =>
i.FileStatus == FileStatus.PendingUpload &&
i.FileName != null &&
i.FileName.StartsWith("http", StringComparison.OrdinalIgnoreCase));
i.FileStatus == FileStatus.PendingUpload &&
i.FileName != null &&
i.FileName.StartsWith("http", StringComparison.OrdinalIgnoreCase));
if (imagesToDownload.Any())
{
Expand Down Expand Up @@ -674,8 +694,7 @@ private static async Task FulfillApplicationAsync(DevCenterApplication app, DevC
{
BaseListing = new BaseListing
{
Title = app.PrimaryName,
Description = submissionData.Description,
Title = app.PrimaryName, Description = submissionData.Description,
}
};

Expand All @@ -687,9 +706,7 @@ private static async Task FulfillApplicationAsync(DevCenterApplication app, DevC
{
listing.BaseListing.Images.Add(new Image
{
FileName = image.FileName,
FileStatus = FileStatus.PendingUpload,
ImageType = image.ImageType.ToString()
FileName = image.FileName, FileStatus = FileStatus.PendingUpload, ImageType = image.ImageType.ToString()
});
}
}
Expand Down Expand Up @@ -722,4 +739,4 @@ void UpdateIfNotSet(AllowTargetFutureDeviceFamily allowTargetFutureDeviceFamily)
UpdateIfNotSet(AllowTargetFutureDeviceFamily.Xbox);
}
}
}
}
Loading

0 comments on commit 20d34dc

Please sign in to comment.