Skip to content

Commit f48d8b7

Browse files
committed
skip validation for non-yaml format
1 parent a8df559 commit f48d8b7

File tree

9 files changed

+66
-25
lines changed

9 files changed

+66
-25
lines changed

src/WingetCreateCLI/Commands/BaseCommand.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ protected static string SaveManifestDirToLocalPath(
216216
/// Saves the manifests to a randomly generated directory in the %TEMP% folder and validates them, printing the results to console.
217217
/// </summary>
218218
/// <param name="manifests">Manifests object model.</param>
219+
/// <param name="format">Format of the serialized manifest. </param>
219220
/// <returns>A boolean value indicating whether validation of the manifests was successful.</returns>
220-
protected static bool ValidateManifestsInTempDir(Manifests manifests)
221+
protected static bool ValidateManifestsInTempDir(Manifests manifests, ManifestFormat format)
221222
{
222223
string versionManifestFileName = Manifests.GetFileName(manifests.VersionManifest, Extension);
223224
string installerManifestFileName = Manifests.GetFileName(manifests.InstallerManifest, Extension);
@@ -236,7 +237,7 @@ protected static bool ValidateManifestsInTempDir(Manifests manifests)
236237
File.WriteAllText(Path.Combine(randomDirPath, localeManifestFileName), localeManifest.ToManifestString());
237238
}
238239

239-
bool result = ValidateManifest(randomDirPath);
240+
bool result = ValidateManifest(randomDirPath, format);
240241
Directory.Delete(randomDirPath, true);
241242
return result;
242243
}
@@ -382,9 +383,18 @@ protected static async Task<string> DownloadPackageFile(string installerUrl)
382383
/// Utilizes WingetUtil to validate a specified manifest.
383384
/// </summary>
384385
/// <param name="manifestPath"> Path to the manifest file to be validated. </param>
386+
/// <param name="format"> Format of the manifest file. </param>"
385387
/// <returns>Bool indicating the validity of the manifest file. </returns>
386-
protected static bool ValidateManifest(string manifestPath)
388+
protected static bool ValidateManifest(string manifestPath, ManifestFormat format)
387389
{
390+
bool skipValidation = format != ManifestFormat.Yaml;
391+
392+
if (skipValidation)
393+
{
394+
Logger.WarnLocalized(nameof(Resources.SkippingManifestValidation_Message));
395+
return true;
396+
}
397+
388398
(bool success, string message) = WinGetUtil.ValidateManifest(manifestPath);
389399

390400
if (success)

src/WingetCreateCLI/Commands/NewCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public override async Task<bool> Execute()
261261
ShiftInstallerFieldsToRootLevel(manifests.InstallerManifest);
262262
RemoveEmptyStringAndListFieldsInManifests(manifests);
263263
DisplayManifestPreview(manifests);
264-
isManifestValid = ValidateManifestsInTempDir(manifests);
264+
isManifestValid = ValidateManifestsInTempDir(manifests, this.Format);
265265
}
266266
while (Prompt.Confirm(Resources.ConfirmManifestCreation_Message));
267267

src/WingetCreateCLI/Commands/NewLocaleCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public override async Task<bool> Execute()
224224
{
225225
LocaleManifest newlocale = this.GenerateLocaleManifest(originalManifests, referenceLocaleManifest);
226226
Console.WriteLine();
227-
ValidateManifestsInTempDir(originalManifests);
227+
ValidateManifestsInTempDir(originalManifests, this.Format);
228228
originalManifests.LocaleManifests.Add(newlocale);
229229
newLocales.Add(newlocale);
230230
}
@@ -241,7 +241,7 @@ public override async Task<bool> Execute()
241241

242242
string manifestDirectoryPath = SaveManifestDirToLocalPath(originalManifests, this.OutputDir);
243243

244-
if (ValidateManifest(manifestDirectoryPath))
244+
if (ValidateManifest(manifestDirectoryPath, this.Format))
245245
{
246246
if (Prompt.Confirm(Resources.ConfirmGitHubSubmitManifest_Message))
247247
{

src/WingetCreateCLI/Commands/SubmitCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private async Task<bool> SubmitManifest()
112112
string expandedPath = System.Environment.ExpandEnvironmentVariables(this.Path);
113113

114114
// TODO: Remove singleton support.
115-
if (File.Exists(expandedPath) && ValidateManifest(expandedPath))
115+
if (File.Exists(expandedPath) && ValidateManifest(expandedPath, this.Format))
116116
{
117117
Manifests manifests = new Manifests();
118118
manifests.SingletonManifest = Serialization.DeserializeFromPath<SingletonManifest>(expandedPath);
@@ -124,7 +124,7 @@ private async Task<bool> SubmitManifest()
124124

125125
return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion);
126126
}
127-
else if (Directory.Exists(expandedPath) && ValidateManifest(expandedPath))
127+
else if (Directory.Exists(expandedPath) && ValidateManifest(expandedPath, this.Format))
128128
{
129129
List<string> manifestContents = Directory.GetFiles(expandedPath).Select(f => File.ReadAllText(f)).ToList();
130130
Manifests manifests = Serialization.DeserializeManifestContents(manifestContents);

src/WingetCreateCLI/Commands/UpdateCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ await this.UpdateManifestsInteractively(initialManifests) :
274274

275275
string manifestDirectoryPath = SaveManifestDirToLocalPath(updatedManifests, this.OutputDir);
276276

277-
if (ValidateManifest(manifestDirectoryPath))
277+
if (ValidateManifest(manifestDirectoryPath, this.Format))
278278
{
279279
if (this.SubmitToGitHub)
280280
{
@@ -687,7 +687,7 @@ private static bool VerifyUpdatedInstallerHash(Manifests oldManifest, InstallerM
687687
return newHashes.Except(oldHashes).Any();
688688
}
689689

690-
private static void DisplayManifestsAsMenuSelection(Manifests manifests)
690+
private static void DisplayManifestsAsMenuSelection(Manifests manifests, ManifestFormat format)
691691
{
692692
Console.Clear();
693693
string versionFileName = Manifests.GetFileName(manifests.VersionManifest, Extension);
@@ -709,7 +709,7 @@ private static void DisplayManifestsAsMenuSelection(Manifests manifests)
709709
}
710710

711711
selectionList.Add(Resources.Done_MenuItem);
712-
ValidateManifestsInTempDir(manifests);
712+
ValidateManifestsInTempDir(manifests, format);
713713
var selectedItem = Prompt.Select(Resources.SelectManifestToEdit_Message, selectionList);
714714

715715
if (selectedItem == versionManifestMenuItem)
@@ -956,13 +956,13 @@ private async Task<Manifests> UpdateManifestsInteractively(Manifests manifests)
956956

957957
this.AddVersionSpecificMetadata(manifests);
958958
DisplayManifestPreview(manifests);
959-
ValidateManifestsInTempDir(manifests);
959+
ValidateManifestsInTempDir(manifests, this.Format);
960960
}
961961
while (Prompt.Confirm(Resources.DiscardUpdateAndStartOver_Message));
962962

963963
if (Prompt.Confirm(Resources.EditManifests_Message))
964964
{
965-
DisplayManifestsAsMenuSelection(manifests);
965+
DisplayManifestsAsMenuSelection(manifests, this.Format);
966966
}
967967

968968
if (!this.SubmitToGitHub)

src/WingetCreateCLI/Commands/UpdateLocaleCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public override async Task<bool> Execute()
172172

173173
string manifestDirectoryPath = SaveManifestDirToLocalPath(originalManifests, this.OutputDir);
174174

175-
if (ValidateManifest(manifestDirectoryPath))
175+
if (ValidateManifest(manifestDirectoryPath, this.Format))
176176
{
177177
if (Prompt.Confirm(Resources.ConfirmGitHubSubmitManifest_Message))
178178
{
@@ -281,7 +281,7 @@ private Tuple<DefaultLocaleManifest, List<LocaleManifest>> PromptAndUpdateExisti
281281
}
282282

283283
Console.WriteLine();
284-
ValidateManifestsInTempDir(manifests);
284+
ValidateManifestsInTempDir(manifests, this.Format);
285285
}
286286
while (Prompt.Confirm(Resources.UpdateAnotherLocale_Message));
287287

src/WingetCreateCLI/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WingetCreateCLI/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,4 +1418,7 @@ Warning: Using this argument may result in the token being logged. Consider an a
14181418
<data name="Authentication_KeywordDescription" xml:space="preserve">
14191419
<value>Authentication information for Entra Id secured private sources</value>
14201420
</data>
1421+
<data name="SkippingManifestValidation_Message" xml:space="preserve">
1422+
<value>Skipping manifest validation. The CLI can only validate YAML format. Validate output manually before submission.</value>
1423+
</data>
14211424
</root>

src/WingetCreateTests/WingetCreateTests/E2ETests/E2ETests.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.WingetCreateE2ETests
99
using Microsoft.WingetCreateCLI.Commands;
1010
using Microsoft.WingetCreateCLI.Logging;
1111
using Microsoft.WingetCreateCLI.Models.Settings;
12+
using Microsoft.WingetCreateCLI.Properties;
1213
using Microsoft.WingetCreateCore;
1314
using Microsoft.WingetCreateCore.Common;
1415
using Microsoft.WingetCreateTests;
@@ -27,6 +28,7 @@ public class E2ETests : GitHubTestsBase
2728
{
2829
private const string PackageVersion = "1.2.3.4";
2930
private GitHub gitHub;
31+
private StringWriter sw;
3032

3133
/// <summary>
3234
/// One-time function that runs at the beginning of this test class.
@@ -37,6 +39,8 @@ public void Setup()
3739
Logger.Initialize();
3840
this.gitHub = new GitHub(this.GitHubApiKey, this.WingetPkgsTestRepoOwner, this.WingetPkgsTestRepo);
3941
TestUtils.InitializeMockDownload();
42+
this.sw = new StringWriter();
43+
Console.SetOut(this.sw);
4044
}
4145

4246
/// <summary>
@@ -54,12 +58,12 @@ public void Setup()
5458
[TestCase(TestConstants.YamlConstants.TestPortablePackageIdentifier, TestConstants.YamlConstants.TestPortableManifest, TestConstants.TestExeInstaller, TestConstants.YamlManifestFormat)]
5559
[TestCase(TestConstants.YamlConstants.TestZipPackageIdentifier, TestConstants.YamlConstants.TestZipManifest, TestConstants.TestZipInstaller, TestConstants.YamlManifestFormat)]
5660

57-
// JSON E2E Tests. Skipped because of https://github.com/microsoft/winget-cli/issues/5336
58-
[TestCase(TestConstants.JsonConstants.TestExePackageIdentifier, TestConstants.JsonConstants.TestExeManifest, TestConstants.TestExeInstaller, TestConstants.JsonManifestFormat, Ignore = "Fails WinGetUtil.WinGetValidateManifest in schema version 1.10.0+")]
59-
[TestCase(TestConstants.JsonConstants.TestMsiPackageIdentifier, TestConstants.JsonConstants.TestMsiManifest, TestConstants.TestMsiInstaller, TestConstants.JsonManifestFormat, Ignore = "Fails WinGetUtil.WinGetValidateManifest in schema version 1.10.0+")]
60-
[TestCase(TestConstants.JsonConstants.TestMultifileMsixPackageIdentifier, TestConstants.JsonConstants.TestMultifileMsixManifestDir, TestConstants.TestMsixInstaller, TestConstants.JsonManifestFormat, Ignore = "Fails WinGetUtil.WinGetValidateManifest in schema version 1.10.0+")]
61-
[TestCase(TestConstants.JsonConstants.TestPortablePackageIdentifier, TestConstants.JsonConstants.TestPortableManifest, TestConstants.TestExeInstaller, TestConstants.JsonManifestFormat, Ignore = "Fails WinGetUtil.WinGetValidateManifest in schema version 1.10.0+")]
62-
[TestCase(TestConstants.JsonConstants.TestZipPackageIdentifier, TestConstants.JsonConstants.TestZipManifest, TestConstants.TestZipInstaller, TestConstants.JsonManifestFormat, Ignore = "Fails WinGetUtil.WinGetValidateManifest in schema version 1.10.0+")]
61+
// JSON E2E Tests
62+
[TestCase(TestConstants.JsonConstants.TestExePackageIdentifier, TestConstants.JsonConstants.TestExeManifest, TestConstants.TestExeInstaller, TestConstants.JsonManifestFormat)]
63+
[TestCase(TestConstants.JsonConstants.TestMsiPackageIdentifier, TestConstants.JsonConstants.TestMsiManifest, TestConstants.TestMsiInstaller, TestConstants.JsonManifestFormat)]
64+
[TestCase(TestConstants.JsonConstants.TestMultifileMsixPackageIdentifier, TestConstants.JsonConstants.TestMultifileMsixManifestDir, TestConstants.TestMsixInstaller, TestConstants.JsonManifestFormat)]
65+
[TestCase(TestConstants.JsonConstants.TestPortablePackageIdentifier, TestConstants.JsonConstants.TestPortableManifest, TestConstants.TestExeInstaller, TestConstants.JsonManifestFormat)]
66+
[TestCase(TestConstants.JsonConstants.TestZipPackageIdentifier, TestConstants.JsonConstants.TestZipManifest, TestConstants.TestZipInstaller, TestConstants.JsonManifestFormat)]
6367

6468
public async Task SubmitAndUpdateInstaller(string packageId, string manifestName, string installerName, ManifestFormat format)
6569
{
@@ -86,6 +90,10 @@ private async Task RunSubmitAndUpdateFlow(string packageId, string manifestPath,
8690
OpenPRInBrowser = false,
8791
};
8892
ClassicAssert.IsTrue(await submitCommand.Execute(), "Command should have succeeded");
93+
this.AssertValidationOutput(format);
94+
95+
// Clear output for the next command
96+
this.sw.GetStringBuilder().Clear();
8997

9098
var mergeRetryPolicy = Policy
9199
.Handle<PullRequestNotMergeableException>()
@@ -115,11 +123,22 @@ await mergeRetryPolicy.ExecuteAsync(async () =>
115123
ClassicAssert.IsTrue(await updateCommand.LoadGitHubClient(), "Failed to create GitHub client");
116124
ClassicAssert.IsTrue(await updateCommand.Execute(), "Command should execute successfully");
117125

118-
string pathToValidate = Path.Combine(Directory.GetCurrentDirectory(), Utils.GetAppManifestDirPath(packageId, PackageVersion));
119-
(bool success, string message) = WinGetUtil.ValidateManifest(pathToValidate);
120-
ClassicAssert.IsTrue(success, message);
121-
126+
// Since SubmitToGitHub is true, the command will first validate the manifest & then submit the PR
127+
this.AssertValidationOutput(format);
122128
await this.gitHub.ClosePullRequest(updateCommand.PullRequestNumber);
123129
}
130+
131+
private void AssertValidationOutput(ManifestFormat format)
132+
{
133+
string output = this.sw.ToString();
134+
if (format == ManifestFormat.Yaml)
135+
{
136+
Assert.That(output, Does.Contain(string.Format(Resources.ManifestValidationSucceeded_Message, true)), "Manifest validation success message should be shown");
137+
}
138+
else
139+
{
140+
Assert.That(output, Does.Contain(Resources.SkippingManifestValidation_Message), "Skipping manifest validation message should be shown");
141+
}
142+
}
124143
}
125144
}

0 commit comments

Comments
 (0)