Skip to content

Commit

Permalink
check task deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisRumyantsev committed Oct 3, 2023
1 parent 82cf476 commit 85dfb5d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Agent.Worker/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Pipelines = Microsoft.TeamFoundation.DistributedTask.Pipelines;
using Microsoft.VisualStudio.Services.Agent.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -74,6 +75,7 @@ into taskGrouping
continue;
}
await DownloadAsync(executionContext, task);
CheckTaskDeprecation(executionContext, task);
}
}

Expand Down Expand Up @@ -308,6 +310,29 @@ private async Task DownloadAsync(IExecutionContext executionContext, Pipelines.T
}
}

private void CheckTaskDeprecation(IExecutionContext executionContext, Pipelines.TaskStepDefinitionReference task)
{
string taskJsonPath = Path.Combine(GetDirectory(task), "task.json");
string taskJsonText = File.ReadAllText(taskJsonPath);
JObject taskJson = JObject.Parse(taskJsonText);
var deprecated = taskJson["deprecated"];

if (deprecated != null && deprecated.Value<bool>())
{
int majorVersion = new Version(task.Version).Major;
string deprecationMessage = $"Task '{task.Name}' version {majorVersion} is deprecated";
var removalDate = taskJson["removalDate"];

if (removalDate != null)
{
string removalDateString = removalDate.Value<DateTime>().ToString("MMMM d, yyyy");
deprecationMessage += $" and will be removed on {removalDateString}";
}

executionContext.Warning($"{deprecationMessage}.");
}
}

private void ExtractZip(String zipFile, String destinationDirectory)
{
ZipFile.ExtractToDirectory(zipFile, destinationDirectory);
Expand Down

0 comments on commit 85dfb5d

Please sign in to comment.