Skip to content

Commit

Permalink
Send environment url to Run Service (actions#2650)
Browse files Browse the repository at this point in the history
* add EnvironmentUrl to CompleteJobRequest

* Send environment url to Run Service

* Fix whitespace

* Fix test

* Fix more whitespace

* Apply suggestions from code review

Co-authored-by: Tingluo Huang <tingluohuang@github.com>

* Apply suggestion from code review

Co-authored-by: Tingluo Huang <tingluohuang@github.com>

---------

Co-authored-by: Tingluo Huang <tingluohuang@github.com>
  • Loading branch information
2 people authored and ashb committed Jun 23, 2023
1 parent a17f9af commit 27e6926
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Runner.Common/RunServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Task CompleteJobAsync(
Dictionary<String, VariableValue> outputs,
IList<StepResult> stepResults,
IList<Annotation> jobAnnotations,
string environmentUrl,
CancellationToken token);

Task<RenewJobResponse> RenewJobAsync(Guid planId, Guid jobId, CancellationToken token);
Expand Down Expand Up @@ -70,11 +71,12 @@ public Task CompleteJobAsync(
Dictionary<String, VariableValue> outputs,
IList<StepResult> stepResults,
IList<Annotation> jobAnnotations,
string environmentUrl,
CancellationToken cancellationToken)
{
CheckConnection();
return RetryRequest(
async () => await _runServiceHttpClient.CompleteJobAsync(requestUri, planId, jobId, result, outputs, stepResults, jobAnnotations, cancellationToken), cancellationToken);
async () => await _runServiceHttpClient.CompleteJobAsync(requestUri, planId, jobId, result, outputs, stepResults, jobAnnotations, environmentUrl, cancellationToken), cancellationToken);
}

public Task<RenewJobResponse> RenewJobAsync(Guid planId, Guid jobId, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Listener/JobDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ private async Task ForceFailJob(IRunnerService server, Pipelines.AgentJobRequest
jobAnnotations.Add(unhandledAnnotation.Value);
}

await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, TaskResult.Failed, outputs: null, stepResults: null, jobAnnotations: jobAnnotations, CancellationToken.None);
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, TaskResult.Failed, outputs: null, stepResults: null, jobAnnotations: jobAnnotations, environmentUrl: null, CancellationToken.None);
}
catch (Exception ex)
{
Expand Down
10 changes: 9 additions & 1 deletion src/Runner.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GitHub.DistributedTask.ObjectTemplating.Tokens;
using GitHub.DistributedTask.Pipelines;
using GitHub.DistributedTask.WebApi;
using GitHub.Runner.Common;
Expand Down Expand Up @@ -283,14 +284,21 @@ private async Task<TaskResult> CompleteJobAsync(IRunServer runServer, IExecution
// Make sure we don't submit secrets as telemetry
MaskTelemetrySecrets(jobContext.Global.JobTelemetry);

// Get environment url
string environmentUrl = null;
if (jobContext.ActionsEnvironment?.Url is StringToken urlStringToken)
{
environmentUrl = urlStringToken.Value;
}

Trace.Info($"Raising job completed against run service");
var completeJobRetryLimit = 5;
var exceptions = new List<Exception>();
while (completeJobRetryLimit-- > 0)
{
try
{
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, default);
await runServer.CompleteJobAsync(message.Plan.PlanId, message.JobId, result, jobContext.JobOutputs, jobContext.Global.StepsResult, jobContext.Global.JobAnnotations, environmentUrl, default);
return result;
}
catch (Exception ex)
Expand Down
3 changes: 3 additions & 0 deletions src/Sdk/RSWebApi/Contracts/CompleteJobRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public class CompleteJobRequest

[DataMember(Name = "annotations", EmitDefaultValue = false)]
public IList<Annotation> Annotations { get; set; }

[DataMember(Name = "environmentUrl", EmitDefaultValue = false)]
public string EnvironmentUrl { get; set; }
}
}
4 changes: 3 additions & 1 deletion src/Sdk/RSWebApi/RunServiceHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public async Task CompleteJobAsync(
Dictionary<String, VariableValue> outputs,
IList<StepResult> stepResults,
IList<Annotation> jobAnnotations,
string environmentUrl,
CancellationToken cancellationToken = default)
{
HttpMethod httpMethod = new HttpMethod("POST");
Expand All @@ -110,7 +111,8 @@ public async Task CompleteJobAsync(
Conclusion = result,
Outputs = outputs,
StepResults = stepResults,
Annotations = jobAnnotations
Annotations = jobAnnotations,
EnvironmentUrl = environmentUrl,
};

requestUri = new Uri(requestUri, "completejob");
Expand Down
3 changes: 2 additions & 1 deletion src/Test/L0/Worker/JobRunnerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private Pipelines.AgentJobRequestMessage GetMessage(String messageType = JobRequ
timeline,
jobId,
testName,
testName, null, null, null, new Dictionary<string, VariableValue>(), new List<MaskHint>(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List<Pipelines.ActionStep>(), null, null, null, null,
testName, null, null, null, new Dictionary<string, VariableValue>(), new List<MaskHint>(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List<Pipelines.ActionStep>(), null, null, null,
new ActionsEnvironmentReference("staging"),
messageType: messageType);
message.Variables[Constants.Variables.System.Culture] = "en-US";
message.Resources.Endpoints.Add(new ServiceEndpoint()
Expand Down

0 comments on commit 27e6926

Please sign in to comment.