예제 #1
0
        public static async Task <TestParameters> GetAsync()
        {
            IConfiguration userSecrets = new ConfigurationBuilder()
                                         .AddUserSecrets <TestParameters>()
                                         .Build();

            string maestroBaseUri    = Environment.GetEnvironmentVariable("MAESTRO_BASEURI") ?? userSecrets["MAESTRO_BASEURI"] ?? "https://maestro-int.westus2.cloudapp.azure.com";
            string maestroToken      = Environment.GetEnvironmentVariable("MAESTRO_TOKEN") ?? userSecrets["MAESTRO_TOKEN"];
            string githubToken       = Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? userSecrets["GITHUB_TOKEN"];
            string darcPackageSource = Environment.GetEnvironmentVariable("DARC_PACKAGE_SOURCE");
            string azdoToken         = Environment.GetEnvironmentVariable("AZDO_TOKEN") ?? userSecrets["AZDO_TOKEN"];

            var testDir = TemporaryDirectory.Get();
            var testDirSharedWrapper = Shareable.Create(testDir);

            IMaestroApi maestroApi = maestroToken == null
                ? ApiFactory.GetAnonymous(maestroBaseUri)
                : ApiFactory.GetAuthenticated(maestroBaseUri, maestroToken);

            string darcVersion = await maestroApi.Assets.GetDarcVersionAsync();

            string dotnetExe = await TestHelpers.Which("dotnet");

            var toolInstallArgs = new List <string>
            {
                "tool", "install",
                "--tool-path", testDirSharedWrapper.Peek() !.Directory,
                "--version", darcVersion,
                "Microsoft.DotNet.Darc",
            };

            if (!string.IsNullOrEmpty(darcPackageSource))
            {
                toolInstallArgs.Add("--add-source");
                toolInstallArgs.Add(darcPackageSource);
            }
            await TestHelpers.RunExecutableAsync(dotnetExe, toolInstallArgs.ToArray());

            string darcExe = Path.Join(testDirSharedWrapper.Peek() !.Directory, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "darc.exe" : "darc");

            Assembly assembly  = typeof(TestParameters).Assembly;
            var      githubApi =
                new GitHubClient(
                    new ProductHeaderValue(assembly.GetName().Name, assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion),
                    new InMemoryCredentialStore(new Credentials(githubToken)));
            var azDoClient =
                new Microsoft.DotNet.DarcLib.AzureDevOpsClient(await TestHelpers.Which("git"), azdoToken, new NUnitLogger(), testDirSharedWrapper.TryTake() !.Directory);

            return(new TestParameters(darcExe, await TestHelpers.Which("git"), maestroBaseUri, maestroToken !, githubToken, maestroApi, githubApi, azDoClient, testDir, azdoToken));
        }
예제 #2
0
        public async Task <TemporaryDirectory> CloneRepositoryWithDarc(string repoName, string version, string reposToIgnore, bool includeToolset, int depth)
        {
            string sourceRepoUri = GetRepoUrl("dotnet", repoName);

            using var shareable = Shareable.Create(TemporaryDirectory.Get());
            string directory = shareable.Peek().Directory;

            string reposFolder  = Path.Join(directory, "cloned-repos");
            string gitDirFolder = Path.Join(directory, "git-dirs");

            // Clone repo
            await RunDarcAsync("clone", "--repo", sourceRepoUri, "--version", version, "--git-dir-folder", gitDirFolder, "--ignore-repos", reposToIgnore, "--repos-folder", reposFolder, "--depth", depth.ToString(), includeToolset? "--include-toolset" : "");

            return(shareable.TryTake() !);
        }
예제 #3
0
        public async Task <TemporaryDirectory> CloneAzDoRepositoryAsync(string repoName, string targetBranch)
        {
            using var shareable = Shareable.Create(TemporaryDirectory.Get());
            string directory = shareable.Peek() !.Directory;

            string authUrl = GetAzDoRepoAuthUrl(repoName);

            await RunGitAsync("clone", "--quiet", authUrl, directory).ConfigureAwait(false);

            using (ChangeDirectory(directory))
            {
                // The GitHubUser and AzDoUser have the same user name so this uses the existing parameter
                await RunGitAsync("config", "user.email", $"{_parameters.GitHubUser}@test.com").ConfigureAwait(false);
                await RunGitAsync("config", "user.name", _parameters.GitHubUser).ConfigureAwait(false);
            }


            return(shareable.TryTake() !);
        }
예제 #4
0
        public async Task <TemporaryDirectory> CloneRepositoryAsync(string org, string repository)
        {
            using var shareable = Shareable.Create(TemporaryDirectory.Get());
            string directory = shareable.Peek() !.Directory;

            string fetchUrl = GetRepoFetchUrl(org, repository);

            await RunGitAsync("clone", "--quiet", fetchUrl, directory).ConfigureAwait(false);

            using (ChangeDirectory(directory))
            {
                await RunGitAsync("config", "user.email", $"{_parameters.GitHubUser}@test.com").ConfigureAwait(false);
                await RunGitAsync("config", "user.name", _parameters.GitHubUser).ConfigureAwait(false);
                await RunGitAsync("config", "gc.auto", "0").ConfigureAwait(false);
                await RunGitAsync("config", "advice.detachedHead", "false").ConfigureAwait(false);
                await RunGitAsync("config", "color.ui", "false").ConfigureAwait(false);
            }

            return(shareable.TryTake() !);
        }