Skip to content

Commit

Permalink
Merge branch 'main' into displayVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
ryfu-msft authored Jul 3, 2024
2 parents d8caf81 + 8725a01 commit cc68297
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 53 deletions.
6 changes: 3 additions & 3 deletions pipelines/azure-pipelines.loc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ extends:
variables:
skipComponentGovernanceDetection: true
steps:
- task: MicrosoftTDBuild.tdbuild-task.tdbuild-task.TouchdownBuildTask@1
- task: TouchdownBuildTask@4
displayName: Send resources to Touchdown Build
inputs:
teamId: 25160
authId: cd9fc0c7-0aaa-461f-a098-6c97c3b1cfb1
authKey: $(LocServiceKey)
authType: FederatedIdentity
FederatedIdentityServiceConnection: WingetCreateTDBuild
isPreview: false
relativePathRoot: src\WingetCreateCLI\Properties
resourceFilePath: "*.resx"
Expand Down
5 changes: 4 additions & 1 deletion src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ private async Task<Manifests> UpdateManifestsInteractively(Manifests manifests)
manifests.InstallerManifest.Installers = originalManifest.CloneInstallers();
await this.UpdateInstallersInteractively(manifests.InstallerManifest.Installers);
ShiftInstallerFieldsToRootLevel(manifests.InstallerManifest);
ResetVersionSpecificFields(manifests);
DisplayManifestPreview(manifests);
ValidateManifestsInTempDir(manifests);
}
Expand Down Expand Up @@ -928,6 +929,7 @@ private async Task UpdateSingleInstallerInteractively(Installer installer)
string url = Prompt.Input<string>(Resources.NewInstallerUrl_Message, null, null, new[] { FieldValidation.ValidateProperty(newInstaller, nameof(Installer.InstallerUrl)) });

string packageFile = await DownloadPackageFile(url);
string archivePath = null;

if (string.IsNullOrEmpty(packageFile))
{
Expand All @@ -936,6 +938,7 @@ private async Task UpdateSingleInstallerInteractively(Installer installer)

if (packageFile.IsZipFile())
{
archivePath = packageFile;
string extractDirectory = ExtractArchiveAndRetrieveDirectoryPath(packageFile);
bool isRelativePathNull = false;

Expand All @@ -958,7 +961,7 @@ private async Task UpdateSingleInstallerInteractively(Installer installer)
packageFile = Path.Combine(extractDirectory, installer.NestedInstallerFiles.First().RelativeFilePath);
}

if (!PackageParser.ParsePackageAndUpdateInstallerNode(installer, packageFile, url))
if (!PackageParser.ParsePackageAndUpdateInstallerNode(installer, packageFile, url, archivePath))
{
Logger.ErrorLocalized(nameof(Resources.PackageParsing_Error), url);
Console.WriteLine();
Expand Down
21 changes: 14 additions & 7 deletions src/WingetCreateCore/Common/PackageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,22 @@ public static void UpdateInstallerNodesAsync(List<InstallerMetadata> installerMe
/// Parses the package for relevant metadata and and updates the metadata of the provided installer node.
/// </summary>
/// <param name="installer">Installer node.</param>
/// <param name="path">Path to package file.</param>
/// <param name="filePath">Path to package file.</param>
/// <param name="url">Installer url.</param>
/// <param name="archivePath">Path to archive file containing the installer. Required if the installer type is Zip.</param>
/// <returns>Boolean indicating whether the package parse was successful.</returns>
public static bool ParsePackageAndUpdateInstallerNode(Installer installer, string path, string url)
public static bool ParsePackageAndUpdateInstallerNode(Installer installer, string filePath, string url, string archivePath = null)
{
// Guard clause to ensure that the archivePath is provided if the installer type is Zip.
if (installer.InstallerType == InstallerType.Zip && string.IsNullOrEmpty(archivePath))
{
return false;
}

List<Installer> newInstallers = new List<Installer>();
bool parseResult = ParseExeInstallerType(path, installer, newInstallers) ||
ParseMsix(path, installer, null, newInstallers) ||
ParseMsi(path, installer, null, newInstallers);
bool parseResult = ParseExeInstallerType(filePath, installer, newInstallers) ||
ParseMsix(filePath, installer, null, newInstallers) ||
ParseMsi(filePath, installer, null, newInstallers);

if (!parseResult || !newInstallers.Any())
{
Expand All @@ -315,11 +322,11 @@ public static bool ParsePackageAndUpdateInstallerNode(Installer installer, strin
else
{
// For a single installer, detect the architecture. If no architecture is detected, default to architecture from existing manifest.
newInstaller.Architecture = GetArchFromUrl(url) ?? GetMachineType(path)?.ToString().ToEnumOrDefault<Architecture>() ?? installer.Architecture;
newInstaller.Architecture = GetArchFromUrl(url) ?? GetMachineType(filePath)?.ToString().ToEnumOrDefault<Architecture>() ?? installer.Architecture;
}

newInstaller.InstallerUrl = url;
newInstaller.InstallerSha256 = GetFileHash(path);
newInstaller.InstallerSha256 = string.IsNullOrEmpty(archivePath) ? GetFileHash(filePath) : GetFileHash(archivePath);
UpdateInstallerMetadata(installer, newInstallers.First());
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/WingetCreateCore/WingetCreateCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Octokit" Version="9.1.2" />
<PackageReference Include="Vestris.ResourceLib" Version="2.1.0" />
<PackageReference Include="WiX" Version="3.14.0" />
<PackageReference Include="Vestris.ResourceLib" Version="2.2.0" />
<PackageReference Include="WiX" Version="3.14.1" />
<PackageReference Include="YamlDotNet" Version="15.1.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Installers:
InstallerType: exe
InstallerSha256: A7803233EEDB6A4B59B3024CCF9292A6FFFB94507DC998AA67C5B745D197A5DC
ProductCode: FakeProductCode
PackageFamilyName: FakePackageFamilyName
PackageFamilyName: Fake.PackageFamilyName_8wekyb3d8bbwe
Platform:
- Windows.Desktop
PackageLocale: en-US
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace Microsoft.WingetCreateUnitTests
{
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using AutoMapper;
using Microsoft.WingetCreateCore;
Expand Down Expand Up @@ -157,13 +159,47 @@ public void ParseAndUpdateInstaller()
WingetCreateCore.Models.Singleton.Installer initialInstaller = initialManifests.SingletonManifest.Installers.First();
Installer installer = ConvertSingletonInstaller(initialInstaller);

PackageParser.ParsePackageAndUpdateInstallerNode(installer, testMsiInstallerPath, installer.InstallerUrl);
bool result = PackageParser.ParsePackageAndUpdateInstallerNode(installer, testMsiInstallerPath, installer.InstallerUrl);
ClassicAssert.IsTrue(result, "ParsePackageAndUpdateInstallerNode should return true.");
ClassicAssert.AreEqual(InstallerType.Msi, installer.InstallerType, "InstallerType should be updated.");
ClassicAssert.AreEqual(initialInstaller.Architecture.ToEnumAttributeValue(), installer.Architecture.ToEnumAttributeValue(), "Architecture should not change.");
ClassicAssert.AreNotEqual(initialInstaller.InstallerSha256, installer.InstallerSha256, "InstallerSha256 should be updated.");
ClassicAssert.AreEqual("{E2650EFC-DCD3-4FAA-BBAC-FD1812B03A61}", installer.ProductCode, "ProductCode should be updated");
}

/// <summary>
/// Validates that the ParsePackageAndUpdateInstallerNode function works as expected for a zip installer.
/// </summary>
[Test]
public void ParseAndUpdateZipInstaller()
{
var testZipInstaller = TestUtils.MockDownloadFile(TestConstants.TestZipInstaller);
Assert.That(testZipInstaller, Is.Not.Null.And.Not.Empty);
string extractDirectory = Path.Combine(PackageParser.InstallerDownloadPath, Path.GetFileNameWithoutExtension(testZipInstaller));

try
{
ZipFile.ExtractToDirectory(testZipInstaller, extractDirectory, true);
}
catch (Exception e)
{
ClassicAssert.Fail($"Failed to extract the zip file: {e.Message}");
}

List<string> initialManifestContent = TestUtils.GetInitialManifestContent($"TestPublisher.ZipWithExe.yaml");
Manifests initialManifests = Serialization.DeserializeManifestContents(initialManifestContent);
WingetCreateCore.Models.Singleton.Installer initialInstaller = initialManifests.SingletonManifest.Installers.First();
Installer installer = ConvertSingletonInstaller(initialInstaller);
string nestedInstallerPath = Path.Combine(extractDirectory, installer.NestedInstallerFiles.First().RelativeFilePath);

bool result = PackageParser.ParsePackageAndUpdateInstallerNode(installer, nestedInstallerPath, installer.InstallerUrl, testZipInstaller);
ClassicAssert.IsTrue(result, "ParsePackageAndUpdateInstallerNode should return true.");
ClassicAssert.AreEqual(InstallerType.Zip, installer.InstallerType, "InstallerType should not change");
ClassicAssert.AreEqual(initialInstaller.Architecture.ToEnumAttributeValue(), installer.Architecture.ToEnumAttributeValue(), "Architecture should not change.");
ClassicAssert.AreNotEqual(initialInstaller.InstallerSha256, installer.InstallerSha256, "InstallerSha256 should be updated");
ClassicAssert.AreEqual(installer.InstallerSha256, PackageParser.GetFileHash(testZipInstaller), "InstallSha256 should match the hash of the zip file");
}

/// <summary>
/// Converts the SingletonManifest Installer object model to the InstallerManifest Installer object model.
/// </summary>
Expand All @@ -175,6 +211,7 @@ private static Installer ConvertSingletonInstaller(WingetCreateCore.Models.Singl
{
cfg.AllowNullCollections = true;
cfg.CreateMap<WingetCreateCore.Models.Singleton.Dependencies, WingetCreateCore.Models.Installer.Dependencies>();
cfg.CreateMap<WingetCreateCore.Models.Singleton.NestedInstallerFile, WingetCreateCore.Models.Installer.NestedInstallerFile>();
cfg.CreateMap<WingetCreateCore.Models.Singleton.Installer, WingetCreateCore.Models.Installer.Installer>();
cfg.CreateMap<WingetCreateCore.Models.Singleton.InstallerSwitches, WingetCreateCore.Models.Installer.InstallerSwitches>();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,22 @@ public void TearDown()
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Test]
public async Task UpdateCommandGitHubManifestTest()
public async Task UpdateAndVerifyManifestsCreated()
{
string installerUrl = $"https://fakedomain.com/{TestConstants.TestExeInstaller}";
TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);

string packageIdentifier = "TestPublisher.SingleExe";
string version = "1.2.3.4";
(UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData(TestConstants.TestPackageIdentifier, version, this.tempPath, null);
(UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData(packageIdentifier, version, this.tempPath, new[] { $"{installerUrl}" });
var updatedManifests = await command.ExecuteManifestUpdate(initialManifestContent, this.testCommandEvent);
ClassicAssert.IsTrue(updatedManifests, "Command should have succeeded");

string manifestDir = Utils.GetAppManifestDirPath(TestConstants.TestPackageIdentifier, version);
string manifestDir = Utils.GetAppManifestDirPath(packageIdentifier, version);
var updatedManifestContents = Directory.GetFiles(Path.Combine(this.tempPath, manifestDir)).Select(f => File.ReadAllText(f));
ClassicAssert.IsTrue(updatedManifestContents.Any(), "Updated manifests were not created successfully");
Manifests manifestsToValidate = Serialization.DeserializeManifestContents(updatedManifestContents);
ClassicAssert.AreEqual(version, manifestsToValidate.VersionManifest.PackageVersion, $"Failed to update version of {TestConstants.TestPackageIdentifier}");
ClassicAssert.AreEqual(version, manifestsToValidate.VersionManifest.PackageVersion, $"Failed to update version of {packageIdentifier}");
}

/// <summary>
Expand Down Expand Up @@ -765,7 +769,7 @@ public async Task UpdatePreservesExistingValues()
ClassicAssert.IsNotNull(updatedManifests, "Command should have succeeded");
var updatedInstallerManifest = updatedManifests.InstallerManifest;
ClassicAssert.AreEqual("FakeProductCode", updatedInstallerManifest.ProductCode, "Existing value for ProductCode was overwritten.");
ClassicAssert.AreEqual("FakePackageFamilyName", updatedInstallerManifest.PackageFamilyName, "Existing value for PackageFamilyName was overwritten.");
ClassicAssert.AreEqual("Fake.PackageFamilyName_8wekyb3d8bbwe", updatedInstallerManifest.PackageFamilyName, "Existing value for PackageFamilyName was overwritten.");
ClassicAssert.IsNotNull(updatedInstallerManifest.Platform, "Existing value for Platform was overwritten.;");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@
<None Update="Resources\WingetCreateE2E.Yaml.MsiTest.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\TestPublisher.TestApp.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\TestPublisher.MultipleInstallerApp.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit cc68297

Please sign in to comment.