private async Task <string> CreateZipArchiveOfPackageAsync(
            IZipArchiveManager zipArchiveManager,
            IFileSystem fileSystem,
            string workItemName,
            string fileToZip,
            string injectedCommands)
        {
            string fileName      = $"xharness-apk-payload-{workItemName.ToLowerInvariant()}.zip";
            string outputZipPath = fileSystem.PathCombine(fileSystem.GetDirectoryName(fileToZip), fileName);

            if (fileSystem.FileExists(outputZipPath))
            {
                Log.LogMessage($"Zip archive '{outputZipPath}' already exists, overwriting..");
                fileSystem.DeleteFile(outputZipPath);
            }

            zipArchiveManager.ArchiveFile(fileToZip, outputZipPath);

            // WorkItem payloads of APKs can be reused if sent to multiple queues at once,
            // so we'll always include both scripts (very small)
            await zipArchiveManager.AddResourceFileToArchive <CreateXHarnessAndroidWorkItems>(outputZipPath, ScriptNamespace + PosixAndroidWrapperScript, PosixAndroidWrapperScript);

            await zipArchiveManager.AddResourceFileToArchive <CreateXHarnessAndroidWorkItems>(outputZipPath, ScriptNamespace + NonPosixAndroidWrapperScript, NonPosixAndroidWrapperScript);

            await zipArchiveManager.AddContentToArchive(outputZipPath, CustomCommandsScript + (IsPosixShell ? ".sh" : ".ps1"), injectedCommands);

            return(outputZipPath);
        }
        private async Task <string> CreateZipArchiveOfFolder(
            IZipArchiveManager zipArchiveManager,
            IFileSystem fileSystem,
            string folderToZip,
            string injectedCommands)
        {
            if (!fileSystem.DirectoryExists(folderToZip))
            {
                Log.LogError($"Cannot find path containing app: '{folderToZip}'");
                return(string.Empty);
            }

            string appFolderDirectory = fileSystem.GetDirectoryName(folderToZip);
            string fileName           = $"xharness-app-payload-{fileSystem.GetFileName(folderToZip).ToLowerInvariant()}.zip";
            string outputZipPath      = fileSystem.PathCombine(appFolderDirectory, fileName);

            if (fileSystem.FileExists(outputZipPath))
            {
                Log.LogMessage($"Zip archive '{outputZipPath}' already exists, overwriting..");
                fileSystem.DeleteFile(outputZipPath);
            }

            zipArchiveManager.ArchiveDirectory(folderToZip, outputZipPath, true);

            Log.LogMessage($"Adding the XHarness job scripts into the payload archive");
            await zipArchiveManager.AddResourceFileToArchive <CreateXHarnessAppleWorkItems>(outputZipPath, ScriptNamespace + EntryPointScript, EntryPointScript);

            await zipArchiveManager.AddResourceFileToArchive <CreateXHarnessAppleWorkItems>(outputZipPath, ScriptNamespace + RunnerScript, RunnerScript);

            await zipArchiveManager.AddContentToArchive(outputZipPath, CustomCommandsScript + ".sh", injectedCommands);

            return(outputZipPath);
        }
예제 #3
0
        private async Task <string> CreateZipArchiveOfFolder(
            IZipArchiveManager zipArchiveManager,
            IFileSystem fileSystem,
            string workItemName,
            bool isAlreadyArchived,
            string folderToZip,
            string injectedCommands)
        {
            string appFolderDirectory = fileSystem.GetDirectoryName(folderToZip);
            string fileName           = $"xharness-app-payload-{workItemName.ToLowerInvariant()}.zip";
            string outputZipPath      = fileSystem.PathCombine(appFolderDirectory, fileName);

            if (fileSystem.FileExists(outputZipPath))
            {
                Log.LogMessage($"Zip archive '{outputZipPath}' already exists, overwriting..");
                fileSystem.DeleteFile(outputZipPath);
            }

            if (!isAlreadyArchived)
            {
                zipArchiveManager.ArchiveDirectory(folderToZip, outputZipPath, true);
            }
            else
            {
                Log.LogMessage($"App payload '{workItemName}` has already been zipped. Copying to '{outputZipPath}` instead");
                fileSystem.FileCopy(folderToZip, outputZipPath);
            }

            Log.LogMessage($"Adding the XHarness job scripts into the payload archive");
            await zipArchiveManager.AddResourceFileToArchive <CreateXHarnessAppleWorkItems>(outputZipPath, ScriptNamespace + EntryPointScript, EntryPointScript);

            await zipArchiveManager.AddResourceFileToArchive <CreateXHarnessAppleWorkItems>(outputZipPath, ScriptNamespace + RunnerScript, RunnerScript);

            await zipArchiveManager.AddContentToArchive(outputZipPath, CustomCommandsScript + ".sh", injectedCommands);

            return(outputZipPath);
        }