Skip to content

Commit

Permalink
Check task deprecation (#4458)
Browse files Browse the repository at this point in the history
* check task deprecation

* update deprecation message

* add help url

* update warning message

* Add Knob

* Rename Knob

* localization
  • Loading branch information
DenisRumyantsev authored Oct 12, 2023
1 parent 3ad7bb5 commit c313e3e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions .azure-pipelines/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ jobs:
- script: ${{ variables.devCommand }} testl0 Debug ${{ parameters.os }}-${{ parameters.arch }}
workingDirectory: src
displayName: Unit tests
timeoutInMinutes: 5

# Install nuget
- ${{ if eq(parameters.os, 'win') }}:
Expand Down
8 changes: 7 additions & 1 deletion src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,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 CheckForTaskDeprecation = new Knob(
nameof(CheckForTaskDeprecation),
"If true, the agent will check in the 'Initialize job' step each task used in the job for task deprecation.",
new EnvironmentKnobSource("AZP_AGENT_CHECK_FOR_TASK_DEPRECATION"),
new BuiltInDefaultKnobSource("false"));
}
}
46 changes: 46 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.CheckForTaskDeprecation.GetValue(UtilKnobValueContext.Instance()).AsBoolean())
{
CheckForTaskDeprecation(executionContext, task);
}
}
}

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

private void CheckForTaskDeprecation(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 = StringUtil.Loc("DeprecationMessage", friendlyName, majorVersion, task.Name);
var removalDate = taskJson["removalDate"];

if (removalDate != null)
{
string whitespace = " ";
string removalDateString = removalDate.Value<DateTime>().ToString("MMMM d, yyyy");
deprecationMessage += whitespace + StringUtil.Loc("DeprecationMessageRemovalDate", removalDateString);
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 += whitespace + StringUtil.Loc("DeprecationMessageHelpUrl", versionHelpUrl);
}
}
}

executionContext.Warning(deprecationMessage);
}
}

private void ExtractZip(String zipFile, String destinationDirectory)
{
ZipFile.ExtractToDirectory(zipFile, destinationDirectory);
Expand Down
3 changes: 3 additions & 0 deletions src/Misc/layoutbin/en-US/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@
"DeploymentPoolNotFound": "Deployment pool not found: '{0}'",
"DeprecatedNode6": "This task uses Node 6 execution handler, which will be removed March 31st 2022. If you are the developer of the task - please consider the migration guideline to Node 10 handler - https://aka.ms/migrateTaskNode10 (check this page also if you would like to disable Node 6 deprecation warnings). If you are the user - feel free to reach out to the owners of this task to proceed on migration.",
"DeprecatedRunner": "Task '{0}' is dependent on a task runner that is end-of-life and will be removed in the future. Authors should review Node upgrade guidance: https://aka.ms/node-runner-guidance.",
"DeprecationMessage": "Task '{0}' version {1} ({2}@{1}) is deprecated.",
"DeprecationMessageHelpUrl": "Please see {0} for more information about this task.",
"DeprecationMessageRemovalDate": "This task will be removed. From {0}, onwards it may no longer be available.",
"DirectoryHierarchyUnauthorized": "Permission to read the directory contents is required for '{0}' and each directory up the hierarchy. {1}",
"DirectoryIsEmptyForArtifact": "Directory '{0}' is empty. Nothing will be added to build artifact '{1}'.",
"DirectoryNotFound": "Directory not found: '{0}'",
Expand Down

0 comments on commit c313e3e

Please sign in to comment.