コード例 #1
0
ファイル: PushToBlobFeed.cs プロジェクト: ViktorHofer/arcade
        public bool ExecuteTask(IBuildModelFactory buildModelFactory,
                                IBlobArtifactModelFactory blobArtifactModelFactory,
                                IPackageArtifactModelFactory packageArtifactModelFactory)
        {
            _buildModelFactory           = buildModelFactory;
            _packageArtifactModelFactory = packageArtifactModelFactory;
            _blobArtifactModelFactory    = blobArtifactModelFactory;

            return(ExecuteAsync().GetAwaiter().GetResult());
        }
コード例 #2
0
 public BuildModelFactory(
     ISigningInformationModelFactory signingInformationModelFactory,
     IBlobArtifactModelFactory blobArtifactModelFactory,
     IPackageArtifactModelFactory packageArtifactModelFactory,
     IFileSystem fileSystem,
     TaskLoggingHelper logger)
 {
     _signingInformationModelFactory = signingInformationModelFactory;
     _blobArtifactModelFactory       = blobArtifactModelFactory;
     _packageArtifactModelFactory    = packageArtifactModelFactory;
     _fileSystem = fileSystem;
     _log        = logger;
 }
コード例 #3
0
        public bool ExecuteTask(IFileSystem fileSystem,
                                ISigningInformationModelFactory signingInformationModelFactory,
                                IBlobArtifactModelFactory blobArtifactModelFactory,
                                IPackageArtifactModelFactory packageArtifactModelFactory,
                                IBuildModelFactory buildModelFactory)
        {
            try
            {
                Log.LogMessage(MessageImportance.High, "Performing push to Azure DevOps artifacts storage.");

                if (!string.IsNullOrWhiteSpace(AssetsTemporaryDirectory))
                {
                    Log.LogMessage(MessageImportance.High, $"It's no longer necessary to specify a value for the {nameof(AssetsTemporaryDirectory)} property. " +
                                   $"Please consider patching your code to not use it.");
                }

                if (ItemsToPush == null)
                {
                    Log.LogError($"No items to push. Please check ItemGroup ItemsToPush.");
                }
                else
                {
                    IEnumerable <BlobArtifactModel>    blobArtifacts    = Enumerable.Empty <BlobArtifactModel>();
                    IEnumerable <PackageArtifactModel> packageArtifacts = Enumerable.Empty <PackageArtifactModel>();

                    var itemsToPushNoExcludes = ItemsToPush.
                                                Where(i => !string.Equals(i.GetMetadata("ExcludeFromManifest"), "true", StringComparison.OrdinalIgnoreCase));

                    if (PublishFlatContainer)
                    {
                        // Act as if %(PublishFlatContainer) were true for all items.
                        blobArtifacts = itemsToPushNoExcludes
                                        .Select(i => blobArtifactModelFactory.CreateBlobArtifactModel(i));
                        foreach (var blobItem in itemsToPushNoExcludes)
                        {
                            if (!fileSystem.FileExists(blobItem.ItemSpec))
                            {
                                Log.LogError($"Could not find file {blobItem.ItemSpec}.");
                                continue;
                            }

                            Log.LogMessage(MessageImportance.High,
                                           $"##vso[artifact.upload containerfolder=BlobArtifacts;artifactname=BlobArtifacts]{blobItem.ItemSpec}");
                        }
                    }
                    else
                    {
                        ITaskItem[] symbolItems = itemsToPushNoExcludes
                                                  .Where(i => i.ItemSpec.Contains("symbols.nupkg"))
                                                  .Select(i =>
                        {
                            string fileName = Path.GetFileName(i.ItemSpec);
                            i.SetMetadata("RelativeBlobPath", $"{AssetsVirtualDir}symbols/{fileName}");
                            return(i);
                        })
                                                  .ToArray();

                        var blobItems = itemsToPushNoExcludes
                                        .Where(i =>
                        {
                            var isFlatString = i.GetMetadata("PublishFlatContainer");
                            if (!string.IsNullOrEmpty(isFlatString) &&
                                bool.TryParse(isFlatString, out var isFlat))
                            {
                                return(isFlat);
                            }

                            return(false);
                        })
                                        .Union(symbolItems)
                                        .ToArray();

                        ITaskItem[] packageItems = itemsToPushNoExcludes
                                                   .Except(blobItems)
                                                   .ToArray();

                        foreach (var packagePath in packageItems)
                        {
                            if (!fileSystem.FileExists(packagePath.ItemSpec))
                            {
                                Log.LogError($"Could not find file {packagePath.ItemSpec}.");
                                continue;
                            }

                            Log.LogMessage(MessageImportance.High,
                                           $"##vso[artifact.upload containerfolder=PackageArtifacts;artifactname=PackageArtifacts]{packagePath.ItemSpec}");
                        }

                        foreach (var blobItem in blobItems)
                        {
                            if (!fileSystem.FileExists(blobItem.ItemSpec))
                            {
                                Log.LogError($"Could not find file {blobItem.ItemSpec}.");
                                continue;
                            }

                            Log.LogMessage(MessageImportance.High,
                                           $"##vso[artifact.upload containerfolder=BlobArtifacts;artifactname=BlobArtifacts]{blobItem.ItemSpec}");
                        }

                        packageArtifacts = packageItems.Select(packageArtifactModelFactory.CreatePackageArtifactModel);
                        blobArtifacts    = blobItems.Select(i => blobArtifactModelFactory.CreateBlobArtifactModel(i)).Where(blob => blob != null);
                    }

                    PublishingInfraVersion targetPublishingVersion = PublishingInfraVersion.Latest;

                    if (!string.IsNullOrEmpty(PublishingVersion))
                    {
                        if (!Enum.TryParse(PublishingVersion, ignoreCase: true, out targetPublishingVersion))
                        {
                            Log.LogError($"Could not parse publishing infra version '{PublishingVersion}'");
                        }
                    }

                    SigningInformationModel signingInformationModel = signingInformationModelFactory.CreateSigningInformationModelFromItems(
                        ItemsToSign, StrongNameSignInfo, FileSignInfo, FileExtensionSignInfo, CertificatesSignInfo, blobArtifacts, packageArtifacts);

                    buildModelFactory.CreateBuildManifest(
                        blobArtifacts,
                        packageArtifacts,
                        AssetManifestPath,
                        !string.IsNullOrEmpty(ManifestRepoName) ? ManifestRepoName : ManifestRepoUri,
                        ManifestBuildId,
                        ManifestBranch,
                        ManifestCommit,
                        ManifestBuildData,
                        IsStableBuild,
                        targetPublishingVersion,
                        IsReleaseOnlyPackageVersion,
                        signingInformationModel: signingInformationModel);

                    Log.LogMessage(MessageImportance.High,
                                   $"##vso[artifact.upload containerfolder=AssetManifests;artifactname=AssetManifests]{AssetManifestPath}");
                }
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true);
            }

            return(!Log.HasLoggedErrors);
        }