/// <inheritdoc /> public abstract Task StartDeployment( Api.Models.Internal.IGitRemoteInformation remoteInformation, CompileJob compileJob, CancellationToken cancellationToken);
/// <inheritdoc /> public override Task StartDeployment( Api.Models.Internal.IGitRemoteInformation remoteInformation, CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
/// <inheritdoc /> public override async Task StartDeployment( Api.Models.Internal.IGitRemoteInformation remoteInformation, CompileJob compileJob, CancellationToken cancellationToken) { if (remoteInformation == null) { throw new ArgumentNullException(nameof(remoteInformation)); } if (compileJob == null) { throw new ArgumentNullException(nameof(compileJob)); } Logger.LogTrace("Starting deployment..."); RepositorySettings repositorySettings = null; await databaseContextFactory.UseContext( async databaseContext => repositorySettings = await databaseContext .RepositorySettings .AsQueryable() .Where(x => x.InstanceId == Metadata.Id) .FirstAsync(cancellationToken) .ConfigureAwait(false)) .ConfigureAwait(false); var instanceAuthenticated = repositorySettings.AccessToken == null; var gitHubClient = repositorySettings.AccessToken == null ? gitHubClientFactory.CreateClient() : gitHubClientFactory.CreateClient(repositorySettings.AccessToken); var repositoryTask = gitHubClient .Repository .Get( remoteInformation.RemoteRepositoryOwner, remoteInformation.RemoteRepositoryName); if (!repositorySettings.CreateGitHubDeployments.Value) { Logger.LogTrace("Not creating deployment"); } else if (!instanceAuthenticated) { Logger.LogWarning("Can't create GitHub deployment as no access token is set for repository!"); } else { Logger.LogTrace("Creating deployment..."); var deployment = await gitHubClient .Repository .Deployment .Create( remoteInformation.RemoteRepositoryOwner, remoteInformation.RemoteRepositoryName, new NewDeployment(compileJob.RevisionInformation.CommitSha) { AutoMerge = false, Description = "TGS Game Deployment", Environment = $"TGS: {Metadata.Name}", ProductionEnvironment = true, RequiredContexts = new Collection <string>() }) .WithToken(cancellationToken) .ConfigureAwait(false); compileJob.GitHubDeploymentId = deployment.Id; Logger.LogDebug("Created deployment ID {0}", deployment.Id); await gitHubClient .Repository .Deployment .Status .Create( remoteInformation.RemoteRepositoryOwner, remoteInformation.RemoteRepositoryName, deployment.Id, new NewDeploymentStatus(DeploymentState.InProgress) { Description = "The project is being deployed", AutoInactive = false }) .WithToken(cancellationToken) .ConfigureAwait(false); Logger.LogTrace("In-progress deployment status created"); } try { var gitHubRepo = await repositoryTask .WithToken(cancellationToken) .ConfigureAwait(false); compileJob.GitHubRepoId = gitHubRepo.Id; Logger.LogTrace("Set GitHub ID as {0}", compileJob.GitHubRepoId); } catch (RateLimitExceededException ex) when(!repositorySettings.CreateGitHubDeployments.Value) { Logger.LogWarning(ex, "Unable to set compile job repository ID!"); } }