Ejemplo n.º 1
0
 private static void RenderArtifactContent(StringBuilder stringBuilder, ReleaseArtifact artifact)
 {
     stringBuilder.AppendLine();
     stringBuilder.AppendLine("Name | Containing Path | Version");
     stringBuilder.Append("-----|------|--------");
     foreach (var file in artifact.Files.OrderBy(f => f.RelativePath))
     {
         stringBuilder.AppendLine();
         stringBuilder.Append($"`{file.Name}` | /{file.RelativePath} | {file.Version ?? "-"}");
     }
 }
        public void StoreArtifact(ReleaseArtifact artifact)
        {
            var artifactPath = GenerateArtifactPath(
                artifact.ProductInformation.Identifier,
                artifact.ProductInformation.Os,
                artifact.ProductInformation.Architecture,
                artifact.ProductInformation.Version.ToString());

            var tmpDir = new DirectoryInfo(GenerateTemporaryPath());

            try
            {
                //Create the temporary directory
                if (!tmpDir.Exists)
                {
                    tmpDir.Create();
                }

                //Extract the payload to the temporary directory
                artifact.Payload.ExtractToDirectory(tmpDir.ToString());
                logger.LogDebug("The Artifact was successfully unpacked & stored to the temp directory");

                var artifactDirectory = new DirectoryInfo(artifactPath);

                //If the directory already exists, delete the old content in there
                if (artifactDirectory.Exists)
                {
                    logger.LogDebug("This path already exists! Old content will be deleted!");
                }
                else
                {
                    artifactDirectory.Create();
                }

                tmpDir.Move(artifactDirectory, true);

                logger.LogInformation("The Artifact was successfully stored");

                //Cleanup the tmp directory
                tmpDir.Parent.Delete(true);
            }
            catch (Exception e)
            {
                logger.LogCritical(e.Message);
                throw;
            }
        }
Ejemplo n.º 3
0
        private ReleaseArtifact GetArtifact(DirectoryPath directory, OutputWhitelist outputWhitelist)
        {
            var artifact = new ReleaseArtifact();
            var files    = ImmutableArray <ArtifactFile> .Empty;

            this.context.Log.Information($"Output white list includes {outputWhitelist.Include.Length} item(s)");
            foreach (var include in outputWhitelist.Include)
            {
                this.context.Log.Information($"Getting artifacts for include filter '{include}'");
                var artifactFiles =
                    this.context.GetFiles(directory + "/" + include)
                    .Select(filePath => this.GetArtifactFile(directory, filePath));
                files =
                    files.AddRange(
                        artifactFiles);
            }

            artifact.Files = files.ToList();
            return(artifact);
        }
Ejemplo n.º 4
0
        public void ConvertToReleaseArtifactTest()
        {
            //Setup
            using var stream = new MemoryStream(testFile);
            var testZip = new ZipArchive(stream);

            var expectedArtifact = new ReleaseArtifact
            {
                ProductInformation = new ProductInformation
                {
                    Identifier   = "product",
                    Version      = new ProductVersion("1.1"),
                    Os           = "ubuntu",
                    Architecture = "amd64"
                },
                Payload = testZip
            };

            var testArtifact = ReleaseArtifactMapper.ConvertToReleaseArtifact("product", "ubuntu",
                                                                              "amd64", "1.1", testZip);

            testArtifact.Should().BeEquivalentTo(expectedArtifact);
        }