Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Apple app bundle signing for already archived payloads #7864

Merged
merged 22 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ca481ec
Refactor profile provider to make space for zip
premun Sep 8, 2021
633f0a3
Inject provisioning profiles into app bundles
premun Sep 8, 2021
c4e8296
Refactor E2E project names
premun Sep 8, 2021
c0621a6
Add new tests that archive 2 app bundles
premun Sep 8, 2021
df138fd
Force LF
premun Sep 8, 2021
4e6dc33
Fix injection to run
premun Sep 8, 2021
f25a783
Create `sign()` in bash
premun Sep 8, 2021
77c494e
Sign the apps
premun Sep 8, 2021
e9389e6
Do not copy zip archives, and inject into payload at the end
premun Sep 9, 2021
b79d24a
Copy archive only when needed
premun Sep 9, 2021
f575632
Make test app a top-level dir in the archive
premun Sep 9, 2021
7eb607a
Overwrite when copying
premun Sep 9, 2021
0d21177
Download pre-archived apps
premun Sep 9, 2021
b719713
Rename build stages from iOS to Apple
premun Sep 9, 2021
db42ed1
Merge remote-tracking branch 'dotnet/main' into prvysoky/injecting-pr…
premun Sep 10, 2021
4b26722
Rename E2E tests names even more (drop UnitTest)
premun Sep 13, 2021
e24b106
Rename E2E tests names even more (drop UnitTest)
premun Sep 13, 2021
7a67d07
Merge remote-tracking branch 'dotnet/main' into prvysoky/injecting-pr…
premun Sep 13, 2021
2986e25
Merge remote-tracking branch 'dotnet/main' into prvysoky/injecting-pr…
premun Sep 13, 2021
f5a6d8c
Merge remote-tracking branch 'dotnet/main' into prvysoky/injecting-pr…
premun Sep 14, 2021
685234e
Merge remote-tracking branch 'dotnet/main' into prvysoky/injecting-pr…
premun Sep 15, 2021
6fcc812
Rename Tests file because of some magic that makes it use NET 4.0
premun Sep 15, 2021
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
12 changes: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ stages:
-ci
-restore
-test
-projects $(Build.SourcesDirectory)/tests/UnitTests.XHarness.iOS.Simulator.proj
/bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/UnitTests.XHarness.iOS.Simulator.binlog
-projects $(Build.SourcesDirectory)/tests/UnitTests.XHarness.Apple.Simulator.proj
/bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/UnitTests.XHarness.Apple.Simulator.binlog
/p:RestoreUsingNuGetTargets=false
displayName: XHarness iOS Simulator Helix Testing
displayName: XHarness Apple Simulator Helix Testing
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
HelixAccessToken: ''
Expand All @@ -209,10 +209,10 @@ stages:
-ci
-restore
-test
-projects $(Build.SourcesDirectory)/tests/UnitTests.XHarness.iOS.Device.proj
/bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/Helix.XHarness.iOS.Device.binlog
-projects $(Build.SourcesDirectory)/tests/UnitTests.XHarness.Apple.Device.proj
/bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/Helix.XHarness.Apple.Device.binlog
/p:RestoreUsingNuGetTargets=false
displayName: XHarness iOS Device Helix Testing
displayName: XHarness Apple Device Helix Testing
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
HelixAccessToken: ''
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Microsoft.Arcade.Common/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void WriteToFile(string path, string content)
File.WriteAllText(path, content);
}

public void FileCopy(string sourceFileName, string destFileName) => File.Copy(sourceFileName, destFileName);
public void CopyFile(string sourceFileName, string destFileName, bool overwrite = false) => File.Copy(sourceFileName, destFileName, overwrite);

public Stream GetFileStream(string path, FileMode mode, FileAccess access) => new FileStream(path, mode, access);

Expand Down
4 changes: 2 additions & 2 deletions src/Common/Microsoft.Arcade.Common/IFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable
using System.IO;

#nullable enable
namespace Microsoft.Arcade.Common
{
public interface IFileSystem
Expand All @@ -28,7 +28,7 @@ public interface IFileSystem

void DeleteFile(string path);

void FileCopy(string sourceFileName, string destFileName);
void CopyFile(string sourceFileName, string destFileName, bool overwrite = false);

Stream GetFileStream(string path, FileMode mode, FileAccess access);

Expand Down
8 changes: 8 additions & 0 deletions src/Common/Microsoft.Arcade.Common/IZipArchiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;

namespace Microsoft.Arcade.Common
{
public interface IZipArchiveManager
{
/// <summary>
/// Opens a given archive.
/// </summary>
/// <param name="archivePath">Path to the zip archive</param>
/// <param name="mode">Access mode</param>
ZipArchive OpenArchive(string archivePath, ZipArchiveMode mode);

/// <summary>
/// Loads an embedded resource and adds it to a target archive.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Common/Microsoft.Arcade.Common/ZipArchiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Microsoft.Arcade.Common
{
public class ZipArchiveManager : IZipArchiveManager
{
public ZipArchive OpenArchive(string archivePath, ZipArchiveMode mode)
=> ZipFile.Open(archivePath, mode);

public async Task AddResourceFileToArchive<TAssembly>(string archivePath, string resourceName, string targetFileName = null)
{
using Stream fileStream = GetResourceFileContent<TAssembly>(resourceName);
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Microsoft.Arcade.Test.Common/MockFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void DeleteFile(string path)

public void WriteToFile(string path, string content) => Files[path] = content;

public void FileCopy(string sourceFileName, string destFileName) => Files[destFileName] = Files[sourceFileName];
public void CopyFile(string sourceFileName, string destFileName, bool overwrite = false) => Files[destFileName] = Files[sourceFileName];

public Stream GetFileStream(string path, FileMode mode, FileAccess access)
=> FileExists(path) ? new MemoryStream() : new MockFileStream(this, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void AppleXHarnessWorkItemIsCreated()
command.Should().Contain("--launch-timeout \"00:02:33\"");

_profileProvider
.Verify(x => x.AddProfilesToBundles(It.Is<ITaskItem[]>(bundles => bundles.Any(b => b.ItemSpec == "/apps/System.Foo.app"))), Times.Once);
.Verify(x => x.AddProfileToPayload(payloadArchive, "ios-device_13.5"), Times.Once);
_zipArchiveManager
.Verify(x => x.ArchiveDirectory("/apps/System.Foo.app", payloadArchive, true), Times.Once);
_zipArchiveManager
Expand Down Expand Up @@ -238,7 +238,7 @@ public void ZippedAppIsProvided()
command.Should().Contain("--launch-timeout \"00:02:33\"");

_profileProvider
.Verify(x => x.AddProfilesToBundles(It.Is<ITaskItem[]>(bundles => bundles.Any(b => b.ItemSpec == "/apps/System.Foo.zip"))), Times.Once);
.Verify(x => x.AddProfileToPayload(payloadArchive, "ios-device_13.5"), Times.Once);
_zipArchiveManager
.Verify(x => x.ArchiveDirectory("/apps/System.Foo.app", payloadArchive, true), Times.Never);
_zipArchiveManager
Expand Down

This file was deleted.

19 changes: 16 additions & 3 deletions src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAppleWorkItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public bool ExecuteTask(
IZipArchiveManager zipArchiveManager,
IFileSystem fileSystem)
{
provisioningProfileProvider.AddProfilesToBundles(AppBundles);
var tasks = AppBundles.Select(bundle => PrepareWorkItem(zipArchiveManager, fileSystem, bundle));
var tasks = AppBundles.Select(bundle => PrepareWorkItem(zipArchiveManager, fileSystem, provisioningProfileProvider, bundle));

WorkItems = Task.WhenAll(tasks).GetAwaiter().GetResult().Where(wi => wi != null).ToArray();

Expand All @@ -89,6 +88,7 @@ public bool ExecuteTask(
private async Task<ITaskItem> PrepareWorkItem(
IZipArchiveManager zipArchiveManager,
IFileSystem fileSystem,
IProvisioningProfileProvider provisioningProfileProvider,
ITaskItem appBundleItem)
{
var (workItemName, appFolderPath) = GetNameAndPath(appBundleItem, MetadataNames.AppBundlePath, fileSystem);
Expand All @@ -107,6 +107,17 @@ private async Task<ITaskItem> PrepareWorkItem(
Log.LogError($"App bundle not found in {appFolderPath}");
return null;
}

// If we are re-using one .zip for multiple work items, we need to copy it to a new location
// because we will be changing the contents (we assume we don't mind otherwise)
if (isAlreadyArchived && appBundleItem.TryGetMetadata(MetadataNames.AppBundlePath, out string metadata) && !string.IsNullOrEmpty(metadata))
{
string appFolderDirectory = fileSystem.GetDirectoryName(appFolderPath);
string fileName = $"xharness-payload-{workItemName.ToLowerInvariant()}.zip";
premun marked this conversation as resolved.
Show resolved Hide resolved
string archiveCopyPath = fileSystem.PathCombine(appFolderDirectory, fileName);
fileSystem.CopyFile(appFolderPath, archiveCopyPath, overwrite: true);
appFolderPath = archiveCopyPath;
}

var (testTimeout, workItemTimeout, expectedExitCode, customCommands) = ParseMetadata(appBundleItem);

Expand Down Expand Up @@ -142,7 +153,7 @@ private async Task<ITaskItem> PrepareWorkItem(

if (includesTestRunner && expectedExitCode != 0 && customCommands != null)
{
Log.LogWarning("The ExpectedExitCode property is ignored in the `apple test` scenario");
Log.LogWarning($"The {MetadataName.ExpectedExitCode} property is ignored in the `apple test` scenario");
}

bool resetSimulator = false;
Expand Down Expand Up @@ -172,6 +183,8 @@ private async Task<ITaskItem> PrepareWorkItem(
customCommands,
new[] { EntryPointScript, RunnerScript });

provisioningProfileProvider.AddProfileToPayload(payloadArchivePath, target);

return CreateTaskItem(workItemName, payloadArchivePath, helixCommand, workItemTimeout);
}

Expand Down
Loading