Skip to content
Merged
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
18 changes: 15 additions & 3 deletions src/WingetCreateCLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ protected static string SaveManifestDirToLocalPath(
/// Saves the manifests to a randomly generated directory in the %TEMP% folder and validates them, printing the results to console.
/// </summary>
/// <param name="manifests">Manifests object model.</param>
/// <param name="format">Format of the serialized manifest. </param>
/// <returns>A boolean value indicating whether validation of the manifests was successful.</returns>
protected static bool ValidateManifestsInTempDir(Manifests manifests)
protected static bool ValidateManifestsInTempDir(Manifests manifests, ManifestFormat format)
{
string versionManifestFileName = Manifests.GetFileName(manifests.VersionManifest, Extension);
string installerManifestFileName = Manifests.GetFileName(manifests.InstallerManifest, Extension);
Expand All @@ -236,7 +237,7 @@ protected static bool ValidateManifestsInTempDir(Manifests manifests)
File.WriteAllText(Path.Combine(randomDirPath, localeManifestFileName), localeManifest.ToManifestString());
}

bool result = ValidateManifest(randomDirPath);
bool result = ValidateManifest(randomDirPath, format);
Directory.Delete(randomDirPath, true);
return result;
}
Expand Down Expand Up @@ -382,9 +383,20 @@ protected static async Task<string> DownloadPackageFile(string installerUrl)
/// Utilizes WingetUtil to validate a specified manifest.
/// </summary>
/// <param name="manifestPath"> Path to the manifest file to be validated. </param>
/// <param name="format"> Format of the manifest file. </param>"
/// <returns>Bool indicating the validity of the manifest file. </returns>
protected static bool ValidateManifest(string manifestPath)
protected static bool ValidateManifest(string manifestPath, ManifestFormat format)
{
bool skipValidation = format != ManifestFormat.Yaml;

// Skip validation because of https://github.com/microsoft/winget-cli/issues/5336
// More discussion in the PR https://github.com/microsoft/winget-create/pull/593
if (skipValidation)
{
Logger.WarnLocalized(nameof(Resources.SkippingManifestValidation_Message));
return true;
}

(bool success, string message) = WinGetUtil.ValidateManifest(manifestPath);

if (success)
Expand Down
2 changes: 1 addition & 1 deletion src/WingetCreateCLI/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public override async Task<bool> Execute()
ShiftInstallerFieldsToRootLevel(manifests.InstallerManifest);
RemoveEmptyStringAndListFieldsInManifests(manifests);
DisplayManifestPreview(manifests);
isManifestValid = ValidateManifestsInTempDir(manifests);
isManifestValid = ValidateManifestsInTempDir(manifests, this.Format);
}
while (Prompt.Confirm(Resources.ConfirmManifestCreation_Message));

Expand Down
4 changes: 2 additions & 2 deletions src/WingetCreateCLI/Commands/NewLocaleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public override async Task<bool> Execute()
{
LocaleManifest newlocale = this.GenerateLocaleManifest(originalManifests, referenceLocaleManifest);
Console.WriteLine();
ValidateManifestsInTempDir(originalManifests);
ValidateManifestsInTempDir(originalManifests, this.Format);
originalManifests.LocaleManifests.Add(newlocale);
newLocales.Add(newlocale);
}
Expand All @@ -241,7 +241,7 @@ public override async Task<bool> Execute()

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

if (ValidateManifest(manifestDirectoryPath))
if (ValidateManifest(manifestDirectoryPath, this.Format))
{
if (Prompt.Confirm(Resources.ConfirmGitHubSubmitManifest_Message))
{
Expand Down
4 changes: 2 additions & 2 deletions src/WingetCreateCLI/Commands/SubmitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private async Task<bool> SubmitManifest()
string expandedPath = System.Environment.ExpandEnvironmentVariables(this.Path);

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

return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion);
}
else if (Directory.Exists(expandedPath) && ValidateManifest(expandedPath))
else if (Directory.Exists(expandedPath) && ValidateManifest(expandedPath, this.Format))
{
List<string> manifestContents = Directory.GetFiles(expandedPath).Select(f => File.ReadAllText(f)).ToList();
Manifests manifests = Serialization.DeserializeManifestContents(manifestContents);
Expand Down
11 changes: 6 additions & 5 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ await this.UpdateManifestsInteractively(initialManifests) :

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

if (ValidateManifest(manifestDirectoryPath))
if (ValidateManifest(manifestDirectoryPath, this.Format))
{
if (this.SubmitToGitHub)
{
Expand Down Expand Up @@ -617,6 +617,7 @@ private static Manifests ConvertSingletonToMultifileManifest(WingetCreateCore.Mo
cfg.CreateMap<WingetCreateCore.Models.Singleton.Files, WingetCreateCore.Models.Installer.Files>();
cfg.CreateMap<WingetCreateCore.Models.Singleton.InstallationMetadata, WingetCreateCore.Models.Installer.InstallationMetadata>();
cfg.CreateMap<WingetCreateCore.Models.Singleton.Icon, WingetCreateCore.Models.DefaultLocale.Icon>();
cfg.CreateMap<WingetCreateCore.Models.Singleton.Authentication, WingetCreateCore.Models.Installer.Authentication>();
});
var mapper = config.CreateMapper();

Expand Down Expand Up @@ -686,7 +687,7 @@ private static bool VerifyUpdatedInstallerHash(Manifests oldManifest, InstallerM
return newHashes.Except(oldHashes).Any();
}

private static void DisplayManifestsAsMenuSelection(Manifests manifests)
private static void DisplayManifestsAsMenuSelection(Manifests manifests, ManifestFormat format)
{
Console.Clear();
string versionFileName = Manifests.GetFileName(manifests.VersionManifest, Extension);
Expand All @@ -708,7 +709,7 @@ private static void DisplayManifestsAsMenuSelection(Manifests manifests)
}

selectionList.Add(Resources.Done_MenuItem);
ValidateManifestsInTempDir(manifests);
ValidateManifestsInTempDir(manifests, format);
var selectedItem = Prompt.Select(Resources.SelectManifestToEdit_Message, selectionList);

if (selectedItem == versionManifestMenuItem)
Expand Down Expand Up @@ -955,13 +956,13 @@ private async Task<Manifests> UpdateManifestsInteractively(Manifests manifests)

this.AddVersionSpecificMetadata(manifests);
DisplayManifestPreview(manifests);
ValidateManifestsInTempDir(manifests);
ValidateManifestsInTempDir(manifests, this.Format);
}
while (Prompt.Confirm(Resources.DiscardUpdateAndStartOver_Message));

if (Prompt.Confirm(Resources.EditManifests_Message))
{
DisplayManifestsAsMenuSelection(manifests);
DisplayManifestsAsMenuSelection(manifests, this.Format);
}

if (!this.SubmitToGitHub)
Expand Down
4 changes: 2 additions & 2 deletions src/WingetCreateCLI/Commands/UpdateLocaleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public override async Task<bool> Execute()

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

if (ValidateManifest(manifestDirectoryPath))
if (ValidateManifest(manifestDirectoryPath, this.Format))
{
if (Prompt.Confirm(Resources.ConfirmGitHubSubmitManifest_Message))
{
Expand Down Expand Up @@ -281,7 +281,7 @@ private Tuple<DefaultLocaleManifest, List<LocaleManifest>> PromptAndUpdateExisti
}

Console.WriteLine();
ValidateManifestsInTempDir(manifests);
ValidateManifestsInTempDir(manifests, this.Format);
}
while (Prompt.Confirm(Resources.UpdateAnotherLocale_Message));

Expand Down
15 changes: 14 additions & 1 deletion src/WingetCreateCLI/PromptHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,20 @@ public static void PromptPropertyAndSetValue<T>(object model, string memberName,
{
Type instanceType = typeof(T);
string message = string.Format(Resources.FieldValueIs_Message, memberName);
Console.WriteLine(Resources.ResourceManager.GetString($"{memberName}_KeywordDescription"));

// TODO: Remove when updating the code to handle property name collisions.
// The proper way to handle this may be to append the model information
// something like "{modelName}_{propertyName}_KeywordDescription" e.g. "Installers_Scope_KeywordDescription" &
// "Installers_Authentication_MicrosoftEntraIdAuthenticationInfo_Scope_KeywordDescription" and updating all resource
// strings to follow this convention.
if (model.GetType() == typeof(MicrosoftEntraIdAuthenticationInfo) && memberName == "Scope")
{
Console.WriteLine(Resources.MicrosoftEntraIdAuthenticationInfo_Scope_KeywordDescription);
}
else
{
Console.WriteLine(Resources.ResourceManager.GetString($"{memberName}_KeywordDescription"));
}

if (instanceType == typeof(object))
{
Expand Down
54 changes: 54 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1406,4 +1406,22 @@ Warning: Using this argument may result in the token being logged. Consider an a
<data name="BranchMergeConflict_Message" xml:space="preserve">
<value>The forked repository could not be synced with the upstream commits due to a merge conflict. Resolve conflicts manually and try again.</value>
</data>
<data name="AuthenticationType_KeywordDescription" xml:space="preserve">
<value>The type of authentication to use</value>
</data>
<data name="Resource_KeywordDescription" xml:space="preserve">
Comment thread
yao-msft marked this conversation as resolved.
<value>The resource to use for Microsoft Entra Id authentication</value>
</data>
<data name="MicrosoftEntraIdAuthenticationInfo_KeywordDescription" xml:space="preserve">
<value>Information required for Microsoft Entra Id authentication</value>
</data>
<data name="Authentication_KeywordDescription" xml:space="preserve">
<value>Authentication information for secured private sources</value>
</data>
<data name="SkippingManifestValidation_Message" xml:space="preserve">
<value>Skipping manifest validation. The CLI can only validate YAML format. Validate output manually before submission.</value>
</data>
<data name="MicrosoftEntraIdAuthenticationInfo_Scope_KeywordDescription" xml:space="preserve">
<value>The scope value for Microsoft Entra Id authentication</value>
</data>
</root>
2 changes: 1 addition & 1 deletion src/WingetCreateCLI/WingetCreateCLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
<AssemblyName>WingetCreateCLI</AssemblyName>
<RootNamespace>Microsoft.WingetCreateCLI</RootNamespace>
<Version>1.9</Version>
<Version>1.10</Version>
<Platforms>x64;x86</Platforms>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
6 changes: 3 additions & 3 deletions src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public GitHub(string githubApiToken, string wingetRepoOwner, string wingetRepo)
this.github = new GitHubClient(new ProductHeaderValue(UserAgentName));
if (githubApiToken != null)
{
this.github.Credentials = new Credentials(githubApiToken, AuthenticationType.Bearer);
this.github.Credentials = new Credentials(githubApiToken, Octokit.AuthenticationType.Bearer);
}
}

Expand All @@ -62,7 +62,7 @@ public static async Task<string> GetGitHubAppInstallationAccessToken(string gitH
string jwtToken = GetJwtToken(gitHubAppPrivateKeyPem, gitHubAppId);

var github = new GitHubClient(new ProductHeaderValue(UserAgentName));
github.Credentials = new Credentials(jwtToken, AuthenticationType.Bearer);
github.Credentials = new Credentials(jwtToken, Octokit.AuthenticationType.Bearer);

var installation = await github.GitHubApps.GetRepositoryInstallationForCurrent(wingetRepoOwner, wingetRepo);
var response = await github.GitHubApps.CreateInstallationToken(installation.Id);
Expand Down Expand Up @@ -243,7 +243,7 @@ public async Task<string> FindPackageId(string packageId)
public async Task<bool> PopulateGitHubMetadata(Manifests manifests, string serializerFormat)
{
// Only populate metadata if we have a valid GitHub token.
if (this.github.Credentials.AuthenticationType != AuthenticationType.Anonymous)
if (this.github.Credentials.AuthenticationType != Octokit.AuthenticationType.Anonymous)
{
return await GitHubManifestMetadata.PopulateManifestMetadata(manifests, serializerFormat, this.github);
}
Expand Down
7 changes: 4 additions & 3 deletions src/WingetCreateCore/Models/DefaultLocaleManifestModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public partial class Icon
/// <summary>
/// The url of the hosted icon file
/// </summary>
[Newtonsoft.Json.JsonProperty("IconUrl", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonProperty("IconUrl", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
[System.ComponentModel.DataAnnotations.StringLength(2048)]
[System.ComponentModel.DataAnnotations.RegularExpression(@"^([Hh][Tt][Tt][Pp][Ss]?)://.+$")]
public string IconUrl { get; set; }
Expand Down Expand Up @@ -132,7 +133,7 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
}

/// <summary>
/// A representation of a multiple-file manifest representing a default app metadata in the OWC. v1.9.0
/// A representation of a multiple-file manifest representing a default app metadata in the OWC. v1.10.0
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "11.0.0.0 (Newtonsoft.Json v13.0.0.0)")]
public partial class DefaultLocaleManifest
Expand Down Expand Up @@ -334,7 +335,7 @@ public partial class DefaultLocaleManifest
[Newtonsoft.Json.JsonProperty("ManifestVersion", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
[System.ComponentModel.DataAnnotations.RegularExpression(@"^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(\.(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){2}$")]
public string ManifestVersion { get; set; } = "1.9.0";
public string ManifestVersion { get; set; } = "1.10.0";



Expand Down
Loading
Loading