Exemplo n.º 1
0
        public async Task RunPreWatchdog(CancellationToken cancellationToken)
        {
            const string TestRefEnvVar = "TGS4_GITHUB_REF";
            var          envVar        = Environment.GetEnvironmentVariable(TestRefEnvVar);
            string       workingBranch = null;

            if (!String.IsNullOrWhiteSpace(envVar))
            {
                workingBranch = envVar;
                Console.WriteLine($"TEST: Set working branch to '{workingBranch}' from env var '{TestRefEnvVar}'");
            }

            if (workingBranch == null)
            {
                workingBranch = "master";
                Console.WriteLine($"TEST: Set working branch to default '{workingBranch}'");
            }

            var initalRepo = await repositoryClient.Read(cancellationToken);

            Assert.IsNotNull(initalRepo);
            Assert.IsNull(initalRepo.Origin);
            Assert.IsNull(initalRepo.Reference);
            Assert.IsNull(initalRepo.RevisionInformation);
            Assert.IsNull(initalRepo.ActiveJob);

            const string Origin       = "https://github.com/tgstation/tgstation-server";
            var          cloneRequest = new RepositoryCreateRequest
            {
                Origin    = new Uri(Origin),
                Reference = workingBranch,
            };

            var clone = await repositoryClient.Clone(cloneRequest, cancellationToken).ConfigureAwait(false);

            await ApiAssert.ThrowsException <ConflictException>(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoCloning);

            Assert.IsNotNull(clone);
            Assert.AreEqual(cloneRequest.Origin, clone.Origin);
            Assert.AreEqual(workingBranch, clone.Reference);
            Assert.IsNull(clone.RevisionInformation);
            Assert.IsNotNull(clone.ActiveJob);

            await WaitForJobProgressThenCancel(clone.ActiveJob, 20, cancellationToken).ConfigureAwait(false);

            var secondRead = await repositoryClient.Read(cancellationToken).ConfigureAwait(false);

            Assert.IsNotNull(secondRead);
            Assert.IsNull(secondRead.ActiveJob);

            clone = await repositoryClient.Clone(cloneRequest, cancellationToken).ConfigureAwait(false);

            await WaitForJob(clone.ActiveJob, 9000, false, null, cancellationToken).ConfigureAwait(false);

            var readAfterClone = await repositoryClient.Read(cancellationToken);

            Assert.AreEqual(cloneRequest.Origin, readAfterClone.Origin);
            Assert.AreEqual(workingBranch, readAfterClone.Reference);
            Assert.IsNotNull(readAfterClone.RevisionInformation);
            Assert.IsNotNull(readAfterClone.RevisionInformation.ActiveTestMerges);
            Assert.AreEqual(0, readAfterClone.RevisionInformation.ActiveTestMerges.Count);
            Assert.IsNotNull(readAfterClone.RevisionInformation.CommitSha);
            Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha);
            Assert.IsNotNull(readAfterClone.RevisionInformation.CompileJobs);
            Assert.AreEqual(0, readAfterClone.RevisionInformation.CompileJobs.Count);
            Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha);
            Assert.IsNull(readAfterClone.RevisionInformation.PrimaryTestMerge);
            Assert.AreEqual(readAfterClone.RevisionInformation.CommitSha, readAfterClone.RevisionInformation.OriginCommitSha);
            Assert.AreNotEqual(default, readAfterClone.RevisionInformation.Timestamp);
Exemplo n.º 2
0
        public async Task RunPreWatchdog(CancellationToken cancellationToken)
        {
            const string TestRefEnvVar = "TGS4_GITHUB_REF";
            var          envVar        = Environment.GetEnvironmentVariable(TestRefEnvVar);
            string       workingBranch = null;

            if (!String.IsNullOrWhiteSpace(envVar))
            {
                workingBranch = envVar;
                Console.WriteLine($"TEST: Set working branch to '{workingBranch}' from env var '{TestRefEnvVar}'");
            }

            if (workingBranch == null)
            {
                workingBranch = "master";
                Console.WriteLine($"TEST: Set working branch to default '{workingBranch}'");
            }

            var initalRepo = await repositoryClient.Read(cancellationToken);

            Assert.IsNotNull(initalRepo);
            Assert.IsNull(initalRepo.Origin);
            Assert.IsNull(initalRepo.Reference);
            Assert.IsNull(initalRepo.RevisionInformation);
            Assert.IsNull(initalRepo.ActiveJob);

            const string Origin = "https://github.com/tgstation/tgstation-server";

            initalRepo.Origin    = new Uri(Origin);
            initalRepo.Reference = workingBranch;

            var clone = await repositoryClient.Clone(initalRepo, cancellationToken).ConfigureAwait(false);

            await ApiAssert.ThrowsException <ConflictException>(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoCloning);

            Assert.IsNotNull(clone);
            Assert.AreEqual(initalRepo.Origin, clone.Origin);
            Assert.AreEqual(workingBranch, clone.Reference);
            Assert.IsNull(clone.RevisionInformation);
            Assert.IsNotNull(clone.ActiveJob);

            await WaitForJobProgressThenCancel(clone.ActiveJob, 20, cancellationToken).ConfigureAwait(false);

            var secondRead = await repositoryClient.Read(cancellationToken).ConfigureAwait(false);

            Assert.IsNotNull(secondRead);
            Assert.IsNull(secondRead.ActiveJob);

            clone = await repositoryClient.Clone(initalRepo, cancellationToken).ConfigureAwait(false);

            await WaitForJob(clone.ActiveJob, 900, false, null, cancellationToken).ConfigureAwait(false);

            var readAfterClone = await repositoryClient.Read(cancellationToken);

            Assert.AreEqual(initalRepo.Origin, readAfterClone.Origin);
            Assert.AreEqual(workingBranch, readAfterClone.Reference);
            Assert.IsNotNull(readAfterClone.RevisionInformation);
            Assert.IsNotNull(readAfterClone.RevisionInformation.ActiveTestMerges);
            Assert.AreEqual(0, readAfterClone.RevisionInformation.ActiveTestMerges.Count);
            Assert.IsNotNull(readAfterClone.RevisionInformation.CommitSha);
            Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha);
            Assert.IsNotNull(readAfterClone.RevisionInformation.CompileJobs);
            Assert.AreEqual(0, readAfterClone.RevisionInformation.CompileJobs.Count);
            Assert.IsNotNull(readAfterClone.RevisionInformation.OriginCommitSha);
            Assert.IsNull(readAfterClone.RevisionInformation.PrimaryTestMerge);
            Assert.AreEqual(readAfterClone.RevisionInformation.CommitSha, readAfterClone.RevisionInformation.OriginCommitSha);

            readAfterClone.Origin = new Uri("https://github.com/tgstation/tgstation");
            await ApiAssert.ThrowsException <ApiConflictException>(() => repositoryClient.Update(readAfterClone, cancellationToken), ErrorCode.RepoCantChangeOrigin);

            readAfterClone.Origin = new Uri(Origin);

            // checkout V3 and back
            readAfterClone.Reference = "V3";
            var updated = await Checkout(readAfterClone, false, true, cancellationToken);

            // Specific SHA
            updated.CheckoutSha = "f43f5bd";
            await ApiAssert.ThrowsException <ApiConflictException>(() => Checkout(updated, false, false, cancellationToken), ErrorCode.RepoMismatchShaAndReference);

            updated.Reference = null;
            updated           = await Checkout(updated, false, false, cancellationToken);

            // Fake SHA
            updated.Reference   = null;
            updated.CheckoutSha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            updated             = await Checkout(updated, true, false, cancellationToken);

            // Fake ref
            updated.Reference = "Tgs4IntegrationTestFakeBranchNeverNameABranchThis";
            updated           = await Checkout(updated, true, true, cancellationToken);

            // Back
            updated.Reference = workingBranch;
            updated           = await Checkout(updated, false, true, cancellationToken);

            var testPRString = Environment.GetEnvironmentVariable("TGS4_TEST_PULL_REQUEST_NUMBER");

            if (String.IsNullOrWhiteSpace(testPRString))
            {
                testPRString = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER");
            }
            if (String.IsNullOrWhiteSpace(testPRString))
            {
                testPRString = Environment.GetEnvironmentVariable("TRAVIS_PULL_REQUEST");
            }

            if (String.IsNullOrWhiteSpace(testPRString))
            {
                if (workingBranch == "dev")
                {
                    testPRString = "957";
                }
                else
                {
                    testPRString = "958";
                }
            }

            if (!int.TryParse(testPRString, out var prNumber))
            {
                Assert.Inconclusive($"Invalid PR #: {testPRString}");
            }
            await TestMergeTests(updated, prNumber, cancellationToken);
        }