Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/Runner.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,11 +1330,36 @@ public void WriteWebhookPayload()
{
var workflowFile = Path.Combine(workflowDirectory, "event.json");
Trace.Info($"Write event payload to {workflowFile}");
File.WriteAllText(workflowFile, gitHubEvent, new UTF8Encoding(false));
WriteWebhookPayloadFile(workflowFile, gitHubEvent);
SetGitHubContext("event_path", workflowFile);
}
}

// Every step writes the very same webhook payload to the very same file before it runs, and
// steps can run concurrently (parallel/background steps). This implements an atomic write
// that avoids file corruption.
private static void WriteWebhookPayloadFile(string workflowFile, string gitHubEvent)
{
if (File.Exists(workflowFile))
{
return;
}

var tempFile = $"{workflowFile}.{Guid.NewGuid():N}.tmp";
File.WriteAllText(tempFile, gitHubEvent, new UTF8Encoding(false));
try
{
File.Move(tempFile, workflowFile);
}
catch (IOException) when (File.Exists(workflowFile))
{
}
finally
{
File.Delete(tempFile);
}
}

private void InitializeTimelineRecord(Guid timelineId, Guid timelineRecordId, Guid? parentTimelineRecordId, string recordType, string displayName, string refName, int? order, bool embedded = false)
{
_mainTimelineId = timelineId;
Expand Down