private static void PackageTest(BuildContextBase context, string packageToTest)
    {
        if (context.Version == null)
        {
            return;
        }

        var outputDirectory = Paths.Packages.Combine("test");

        context.NuGetInstall(packageToTest, new NuGetInstallSettings
        {
            Source = new[]
            {
                context.MakeAbsolute(Paths.Nuget).FullPath
            },
            ExcludeVersion  = true,
            Prerelease      = true,
            OutputDirectory = outputDirectory
        });

        var settings = new GitVersionSettings
        {
            OutputTypes = new HashSet <GitVersionOutput>
            {
                GitVersionOutput.Json
            },
            ToolPath = outputDirectory.Combine(packageToTest).Combine("tools").CombineWithFilePath("gitversion.exe").FullPath
        };
        var gitVersion = context.GitVersion(settings);

        Assert.Equal(context.Version.GitVersion.FullSemVer, gitVersion.FullSemVer);
    }
    private static FilePath GetArchiveOutputPath(BuildContextBase context, string runtime, PlatformFamily platform, DirectoryPath targetDir)
    {
        var ext      = platform == PlatformFamily.Windows ? "zip" : "tar.gz";
        var fileName = $"gitversion-{runtime}-{context.Version?.SemVersion}.{ext}".ToLower();

        return(targetDir.CombineWithFilePath(fileName));
    }
Exemple #3
0
    public static void DockerPushImage(this BuildContextBase context, DockerImage dockerImage)
    {
        var tags = context.GetDockerTags(dockerImage, dockerImage.Architecture);

        foreach (var tag in tags)
        {
            context.DockerPush(tag);
        }
    }
Exemple #4
0
    public static void DockerTestImage(this BuildContextBase context, DockerImage dockerImage)
    {
        var tags = context.GetDockerTags(dockerImage, dockerImage.Architecture);

        foreach (var tag in tags)
        {
            context.DockerTestRun(tag, dockerImage.Architecture, "/repo", "/showvariable", "FullSemver");
        }
    }
Exemple #5
0
    public static void DockerPushManifest(this BuildContextBase context, DockerImage dockerImage)
    {
        var manifestTags = context.GetDockerTags(dockerImage);

        foreach (var tag in manifestTags)
        {
            context.DockerManifestPush(tag);
        }
    }
Exemple #6
0
    private static void DockerTestRun(this BuildContextBase context, string image, Architecture arch, string command, params string[] args)
    {
        var settings = GetDockerRunSettings(context, arch);

        context.Information($"Testing image: {image}");
        var output = context.DockerRunImage(settings, image, command, args);

        context.Information("Output : " + output);

        Assert.Contains(context.Version?.GitVersion.FullSemVer, output);
    }
Exemple #7
0
    private static IEnumerable <string> GetDockerTags(this BuildContextBase context, DockerImage dockerImage, Architecture?arch = null)
    {
        var name            = dockerImage.DockerImageName();
        var distro          = dockerImage.Distro;
        var targetFramework = dockerImage.TargetFramework;

        if (context.Version == null)
        {
            return(Enumerable.Empty <string>());
        }
        var tags = new List <string>
        {
            $"{name}:{context.Version.Version}-{distro}-{targetFramework}",
            $"{name}:{context.Version.SemVersion}-{distro}-{targetFramework}",
        };

        if (distro == Constants.DockerDistroLatest && targetFramework == Constants.Version50)
        {
            tags.AddRange(new[]
            {
                $"{name}:{context.Version.Version}",
                $"{name}:{context.Version.SemVersion}",

                $"{name}:{context.Version.Version}-{distro}",
                $"{name}:{context.Version.SemVersion}-{distro}"
            });

            if (context.IsStableRelease)
            {
                tags.AddRange(new[]
                {
                    $"{name}:latest",
                    $"{name}:latest-{targetFramework}",
                    $"{name}:latest-{distro}",
                    $"{name}:latest-{distro}-{targetFramework}",
                });
            }
        }

        if (!arch.HasValue)
        {
            return(tags.Distinct());
        }

        var suffix = arch.Value.ToSuffix();

        return(tags.Select(x => $"{x}-{suffix}").Distinct());
    }
Exemple #8
0
    public static void DockerCreateManifest(this BuildContextBase context, DockerImage dockerImage, bool skipArm64Image)
    {
        var manifestTags = context.GetDockerTags(dockerImage);

        foreach (var tag in manifestTags)
        {
            var amd64Tag = $"{tag}-{Architecture.Amd64.ToSuffix()}";
            if (skipArm64Image)
            {
                context.DockerManifestCreate(tag, amd64Tag);
            }
            else
            {
                var arm64Tag = $"{tag}-{Architecture.Arm64.ToSuffix()}";
                context.DockerManifestCreate(tag, amd64Tag, arm64Tag);
            }
        }
    }
Exemple #9
0
    public static void DockerBuildImage(this BuildContextBase context, DockerImage dockerImage)
    {
        if (context.Version == null)
        {
            return;
        }

        var(distro, targetFramework, arch, registry, _) = dockerImage;

        context.Information($"Building image: {dockerImage}");

        var workDir = Paths.Src.Combine("Docker");
        var tags    = context.GetDockerTags(dockerImage, arch);

        var suffix    = arch.ToSuffix();
        var platforms = new List <string> {
            $"linux/{suffix}"
        };

        var buildSettings = new DockerImageBuildSettings
        {
            Rm       = true,
            Tag      = tags.ToArray(),
            File     = workDir.CombineWithFilePath("Dockerfile").FullPath,
            BuildArg = new[]
            {
                $"contentFolder=/content",
                $"REGISTRY={registry}",
                $"DOTNET_VERSION={targetFramework}",
                $"DISTRO={distro}",
                $"VERSION={context.Version.NugetVersion}"
            },
            Pull     = true,
            Platform = string.Join(",", platforms),
        };

        context.DockerBuild(buildSettings, workDir.ToString(), "--output type=docker");
    }
Exemple #10
0
    private static void PackageUsingNuspec(BuildContextBase context)
    {
        var cmdlineNuspecFile = Paths.Nuspec.CombineWithFilePath("GitVersion.CommandLine.nuspec");

        if (!context.FileExists(cmdlineNuspecFile))
        {
            return;
        }

        var artifactPath  = context.MakeAbsolute(Paths.ArtifactsBinCmdline).FullPath;
        var version       = context.Version;
        var gitVersion    = version?.GitVersion;
        var nugetSettings = new NuGetPackSettings
        {
            // KeepTemporaryNuSpecFile = true,
            Version           = version?.NugetVersion,
            NoPackageAnalysis = true,
            OutputDirectory   = Paths.Nuget,
            Repository        = new NuGetRepository
            {
                Branch = gitVersion?.BranchName,
                Commit = gitVersion?.Sha
            },
            Files = context.GetFiles(artifactPath + "/**/*.*")
                    .Select(file => new NuSpecContent {
                Source = file.FullPath, Target = file.FullPath.Replace(artifactPath, "")
            })
                    .Concat(context.GetFiles("docs/**/package_icon.png").Select(file => new NuSpecContent {
                Source = file.FullPath, Target = "package_icon.png"
            }))
                    .Concat(context.GetFiles("build/nuspec/README.md").Select(file => new NuSpecContent {
                Source = file.FullPath, Target = "README.md"
            }))
                    .ToArray()
        };

        context.NuGetPack(cmdlineNuspecFile, nugetSettings);
    }
Exemple #11
0
    private static DockerContainerRunSettings GetDockerRunSettings(this BuildContextBase context, Architecture arch)
    {
        var currentDir = context.MakeAbsolute(context.Directory("."));
        var root       = string.Empty;
        var settings   = new DockerContainerRunSettings
        {
            Rm     = true,
            Volume = new[]
            {
                $"{currentDir}:{root}/repo",
                $"{currentDir}/tests/scripts:{root}/scripts",
                $"{currentDir}/artifacts/packages/nuget:{root}/nuget",
                $"{currentDir}/artifacts/packages/native:{root}/native",
            },
            Platform = $"linux/{arch.ToString().ToLower()}"
        };

        if (context.IsAzurePipelineBuild)
        {
            settings.Env = new[]
            {
                "TF_BUILD=true",
                $"BUILD_SOURCEBRANCH={context.EnvironmentVariable("BUILD_SOURCEBRANCH")}"
            };
        }
        if (context.IsGitHubActionsBuild)
        {
            settings.Env = new[]
            {
                "GITHUB_ACTIONS=true",
                $"GITHUB_REF={context.EnvironmentVariable("GITHUB_REF")}"
            };
        }

        return(settings);
    }
Exemple #12
0
    public static void DockerTestArtifact(this BuildContextBase context, DockerImage dockerImage, string cmd)
    {
        var tag = $"{dockerImage.DockerImageName()}:{dockerImage.Distro}-sdk-{dockerImage.TargetFramework}";

        context.DockerTestRun(tag, dockerImage.Architecture, "sh", cmd);
    }