Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check task deprecation #4458

Merged
merged 9 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 7 additions & 1 deletion src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,17 @@ public class AgentKnobs
new EnvironmentKnobSource("AGENT_DISABLE_CLEAN_REPO_DEFAULT_VALUE"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob IgnoreVSTSTaskLib = new Knob(
public static readonly Knob IgnoreVSTSTaskLib = new Knob(
nameof(IgnoreVSTSTaskLib),
"Ignores the VSTSTaskLib folder when copying tasks.",
new RuntimeKnobSource("AZP_AGENT_IGNORE_VSTSTASKLIB"),
new EnvironmentKnobSource("AZP_AGENT_IGNORE_VSTSTASKLIB"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob DisableTaskDeprecationCheck = new Knob(
nameof(DisableTaskDeprecationCheck),
"Disables the task deprecation check.",
new EnvironmentKnobSource("AZP_AGENT_DISABLE_TASK_DEPRECATION_CHECK"),
new BuiltInDefaultKnobSource("false"));
DenisRumyantsev marked this conversation as resolved.
Show resolved Hide resolved
}
DenisRumyantsev marked this conversation as resolved.
Show resolved Hide resolved
}
45 changes: 45 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 @@ -73,7 +74,13 @@ into taskGrouping
Trace.Info("Skip download checkout task.");
continue;
}

await DownloadAsync(executionContext, task);

if (!AgentKnobs.DisableTaskDeprecationCheck.GetValue(UtilKnobValueContext.Instance()).AsBoolean())
{
CheckTaskDeprecation(executionContext, task);
}
}
}

Expand Down Expand Up @@ -308,6 +315,44 @@ 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>())
{
string friendlyName = taskJson["friendlyName"].Value<string>();
int majorVersion = new Version(task.Version).Major;
string deprecationMessage = $"Task '{friendlyName}' version {majorVersion} ({task.Name}@{majorVersion}) is deprecated";
var removalDate = taskJson["removalDate"];

if (removalDate != null)
{
string removalDateString = removalDate.Value<DateTime>().ToString("MMMM d, yyyy");
deprecationMessage += $" and will be removed. From {removalDateString} onwards it may no longer be available";
DenisRumyantsev marked this conversation as resolved.
Show resolved Hide resolved
var helpUrl = taskJson["helpUrl"];

if (helpUrl != null)
{
string helpUrlString = helpUrl.Value<string>();
string category = taskJson["category"].Value<string>().ToLower();
string urlPrefix = $"https://docs.microsoft.com/azure/devops/pipelines/tasks/{category}/";

if (helpUrlString.StartsWith(urlPrefix))
{
string versionHelpUrl = $"{helpUrlString}-v{majorVersion}".Replace(urlPrefix, $"https://learn.microsoft.com/azure/devops/pipelines/tasks/reference/");
deprecationMessage += $". Please see {versionHelpUrl} for more information about this task";
}
}
}

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

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