From 0f199de1c829868e63bb91ed0f0d58fde6d57f02 Mon Sep 17 00:00:00 2001 From: Jiahong Wen Date: Mon, 6 Jun 2022 11:20:29 -0400 Subject: [PATCH] Update NugetToolInstaller to add nuget script for unix system to get the correct version (#16397) * Add nuget script for non windows systems to pick up the correct version from bash task * update permissions to 500 * update version for common dependent tasks * add fs.exist to not overwrite file * bump pipAuth to patch 1 * move nuget string as const * bumping DownloadGitHubNugetPackageV1 version --- .../packaging-common/nuget/NuGetToolGetter.ts | 33 +++++++++++++++++++ Tasks/DownloadGitHubNpmPackageV1/task.json | 2 +- .../DownloadGitHubNpmPackageV1/task.loc.json | 2 +- Tasks/DownloadGitHubNugetPackageV1/task.json | 2 +- .../task.loc.json | 2 +- Tasks/NpmAuthenticateV0/task.json | 2 +- Tasks/NpmAuthenticateV0/task.loc.json | 2 +- Tasks/NuGetCommandV2/task.json | 2 +- Tasks/NuGetCommandV2/task.loc.json | 2 +- Tasks/NuGetInstallerV0/task.json | 2 +- Tasks/NuGetInstallerV0/task.loc.json | 2 +- Tasks/NuGetPublisherV0/task.json | 2 +- Tasks/NuGetPublisherV0/task.loc.json | 2 +- Tasks/NuGetRestoreV1/nugetinstaller.ts | 3 +- Tasks/NuGetRestoreV1/task.json | 2 +- Tasks/NuGetRestoreV1/task.loc.json | 2 +- Tasks/NuGetToolInstallerV0/task.json | 2 +- Tasks/NuGetToolInstallerV0/task.loc.json | 2 +- Tasks/NuGetToolInstallerV1/task.json | 2 +- Tasks/NuGetToolInstallerV1/task.loc.json | 2 +- Tasks/NuGetV0/task.json | 2 +- Tasks/NuGetV0/task.loc.json | 2 +- Tasks/PipAuthenticateV0/task.json | 2 +- Tasks/PipAuthenticateV0/task.loc.json | 2 +- Tasks/TwineAuthenticateV0/task.json | 2 +- Tasks/TwineAuthenticateV0/task.loc.json | 15 +++------ 26 files changed, 62 insertions(+), 35 deletions(-) diff --git a/Tasks/Common/packaging-common/nuget/NuGetToolGetter.ts b/Tasks/Common/packaging-common/nuget/NuGetToolGetter.ts index 1edca2300ea2..bca721ebc4c2 100644 --- a/Tasks/Common/packaging-common/nuget/NuGetToolGetter.ts +++ b/Tasks/Common/packaging-common/nuget/NuGetToolGetter.ts @@ -4,6 +4,9 @@ import * as restm from 'typed-rest-client/RestClient'; import * as path from 'path'; import * as semver from 'semver'; import * as commandHelper from './CommandHelper'; +import * as fs from "fs"; +import * as os from "os"; + interface INuGetTools { nugetexe: INuGetVersionInfo[] } @@ -23,6 +26,7 @@ enum NuGetReleaseStage const NUGET_TOOL_NAME: string = 'NuGet'; const NUGET_EXE_FILENAME: string = 'nuget.exe'; +const NUGET_SCRIPT_FILENAME: string = 'nuget'; export const FORCE_NUGET_4_0_0: string = 'FORCE_NUGET_4_0_0'; export const NUGET_VERSION_4_0_0: string = '4.0.0'; @@ -96,9 +100,38 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu let fullNuGetPath: string = path.join(toolPath, NUGET_EXE_FILENAME); taskLib.setVariable(NUGET_EXE_TOOL_PATH_ENV_VAR, fullNuGetPath); + // create a nuget posix script for nuget exe in non-windows agents + if (os.platform() !== "win32") { + generateNugetScript(toolPath, fullNuGetPath); + } + return fullNuGetPath; } +function generateNugetScript(nugetToolPath: string, nugetExePath: string) { + var nugetScriptPath = path.join(nugetToolPath, NUGET_SCRIPT_FILENAME); + + if (fs.existsSync(nugetScriptPath)) { + taskLib.debug(`nugetScriptPath already exist at ${nugetScriptPath}, skipped.`) + } else { + taskLib.debug(`create nugetScriptPath ${nugetScriptPath}`); + + fs.writeFile( + nugetScriptPath, + `#!/bin/sh\nmono ${nugetExePath} "$@"\n`, + (err) => { + if (err) { + taskLib.debug("Writing nuget script failed with error: " + err); + } else { + // give read and execute permissions to everyone + fs.chmodSync(nugetScriptPath, "500"); + taskLib.debug("Writing nuget script succeeded"); + } + } + ); + } +} + function pathExistsAsFile(path: string) { try { return taskLib.stats(path).isFile(); diff --git a/Tasks/DownloadGitHubNpmPackageV1/task.json b/Tasks/DownloadGitHubNpmPackageV1/task.json index c408f9e2e4ac..4ca2f3ce4fc2 100644 --- a/Tasks/DownloadGitHubNpmPackageV1/task.json +++ b/Tasks/DownloadGitHubNpmPackageV1/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 205, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/DownloadGitHubNpmPackageV1/task.loc.json b/Tasks/DownloadGitHubNpmPackageV1/task.loc.json index 68f7904b87d8..d0f2422fad7e 100644 --- a/Tasks/DownloadGitHubNpmPackageV1/task.loc.json +++ b/Tasks/DownloadGitHubNpmPackageV1/task.loc.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 205, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/DownloadGitHubNugetPackageV1/task.json b/Tasks/DownloadGitHubNugetPackageV1/task.json index d8c0e68d054a..e1a91f3c6086 100644 --- a/Tasks/DownloadGitHubNugetPackageV1/task.json +++ b/Tasks/DownloadGitHubNugetPackageV1/task.json @@ -18,7 +18,7 @@ "version": { "Major": 1, "Minor": 206, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "2.144.0", "instanceNameFormat": "dotnet restore", diff --git a/Tasks/DownloadGitHubNugetPackageV1/task.loc.json b/Tasks/DownloadGitHubNugetPackageV1/task.loc.json index 6363d7ac2711..d9dfa026fedd 100644 --- a/Tasks/DownloadGitHubNugetPackageV1/task.loc.json +++ b/Tasks/DownloadGitHubNugetPackageV1/task.loc.json @@ -18,7 +18,7 @@ "version": { "Major": 1, "Minor": 206, - "Patch": 0 + "Patch": 1 }, "minimumAgentVersion": "2.144.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", diff --git a/Tasks/NpmAuthenticateV0/task.json b/Tasks/NpmAuthenticateV0/task.json index 583d7a72a336..7805600617f1 100644 --- a/Tasks/NpmAuthenticateV0/task.json +++ b/Tasks/NpmAuthenticateV0/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NpmAuthenticateV0/task.loc.json b/Tasks/NpmAuthenticateV0/task.loc.json index 8b40d75ef6fc..586950e78957 100644 --- a/Tasks/NpmAuthenticateV0/task.loc.json +++ b/Tasks/NpmAuthenticateV0/task.loc.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetCommandV2/task.json b/Tasks/NuGetCommandV2/task.json index baf796412688..fb177169cb3e 100644 --- a/Tasks/NuGetCommandV2/task.json +++ b/Tasks/NuGetCommandV2/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetCommandV2/task.loc.json b/Tasks/NuGetCommandV2/task.loc.json index 553da249aac4..c56ebe473625 100644 --- a/Tasks/NuGetCommandV2/task.loc.json +++ b/Tasks/NuGetCommandV2/task.loc.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetInstallerV0/task.json b/Tasks/NuGetInstallerV0/task.json index bcfbd3ec91da..81ca04829006 100644 --- a/Tasks/NuGetInstallerV0/task.json +++ b/Tasks/NuGetInstallerV0/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetInstallerV0/task.loc.json b/Tasks/NuGetInstallerV0/task.loc.json index 7cfe85650221..537c669f84ef 100644 --- a/Tasks/NuGetInstallerV0/task.loc.json +++ b/Tasks/NuGetInstallerV0/task.loc.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetPublisherV0/task.json b/Tasks/NuGetPublisherV0/task.json index 1dde7c8d960d..7ca69f6156e7 100644 --- a/Tasks/NuGetPublisherV0/task.json +++ b/Tasks/NuGetPublisherV0/task.json @@ -9,7 +9,7 @@ "author": "Lawrence Gripper", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetPublisherV0/task.loc.json b/Tasks/NuGetPublisherV0/task.loc.json index 509001f5e9f0..aadbc3e7ec2a 100644 --- a/Tasks/NuGetPublisherV0/task.loc.json +++ b/Tasks/NuGetPublisherV0/task.loc.json @@ -9,7 +9,7 @@ "author": "Lawrence Gripper", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetRestoreV1/nugetinstaller.ts b/Tasks/NuGetRestoreV1/nugetinstaller.ts index 3c89e6739cbd..b7b61ff0d7be 100644 --- a/Tasks/NuGetRestoreV1/nugetinstaller.ts +++ b/Tasks/NuGetRestoreV1/nugetinstaller.ts @@ -67,10 +67,11 @@ async function main(): Promise { // Getting NuGet tl.debug('Getting NuGet'); try { - nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR]; + nuGetPath = tl.getVariable(nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR); if (!nuGetPath){ nuGetPath = await nuGetGetter.getNuGet("4.0.0"); } + tl.debug(`Using NuGet in path: ${nuGetPath}`); } catch (error) { tl.setResult(tl.TaskResult.Failed, error.message); diff --git a/Tasks/NuGetRestoreV1/task.json b/Tasks/NuGetRestoreV1/task.json index 9bd81b5d0053..f03b9739971e 100644 --- a/Tasks/NuGetRestoreV1/task.json +++ b/Tasks/NuGetRestoreV1/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 198, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetRestoreV1/task.loc.json b/Tasks/NuGetRestoreV1/task.loc.json index 612ec3749e43..b3c03f7000bb 100644 --- a/Tasks/NuGetRestoreV1/task.loc.json +++ b/Tasks/NuGetRestoreV1/task.loc.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 198, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetToolInstallerV0/task.json b/Tasks/NuGetToolInstallerV0/task.json index 5968fb591edf..cc5935546540 100644 --- a/Tasks/NuGetToolInstallerV0/task.json +++ b/Tasks/NuGetToolInstallerV0/task.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetToolInstallerV0/task.loc.json b/Tasks/NuGetToolInstallerV0/task.loc.json index 89b8c5b77a43..a1ca7f21da2c 100644 --- a/Tasks/NuGetToolInstallerV0/task.loc.json +++ b/Tasks/NuGetToolInstallerV0/task.loc.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetToolInstallerV1/task.json b/Tasks/NuGetToolInstallerV1/task.json index 2970b88d1f51..4dd6ad82faa3 100644 --- a/Tasks/NuGetToolInstallerV1/task.json +++ b/Tasks/NuGetToolInstallerV1/task.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetToolInstallerV1/task.loc.json b/Tasks/NuGetToolInstallerV1/task.loc.json index c21ce13e1302..27224761d539 100644 --- a/Tasks/NuGetToolInstallerV1/task.loc.json +++ b/Tasks/NuGetToolInstallerV1/task.loc.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetV0/task.json b/Tasks/NuGetV0/task.json index 8b9e995d96bd..26e0ee76142a 100644 --- a/Tasks/NuGetV0/task.json +++ b/Tasks/NuGetV0/task.json @@ -10,7 +10,7 @@ "helpMarkDown": "", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetV0/task.loc.json b/Tasks/NuGetV0/task.loc.json index 5ef51f8636c8..d32a8d1f87c6 100644 --- a/Tasks/NuGetV0/task.loc.json +++ b/Tasks/NuGetV0/task.loc.json @@ -10,7 +10,7 @@ "helpMarkDown": "ms-resource:loc.helpMarkDown", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/PipAuthenticateV0/task.json b/Tasks/PipAuthenticateV0/task.json index 8783487cd94a..82b2ee197abb 100644 --- a/Tasks/PipAuthenticateV0/task.json +++ b/Tasks/PipAuthenticateV0/task.json @@ -10,7 +10,7 @@ "version": { "Major": 0, "Minor": 206, - "Patch": 0 + "Patch": 1 }, "runsOn": [ "Agent", diff --git a/Tasks/PipAuthenticateV0/task.loc.json b/Tasks/PipAuthenticateV0/task.loc.json index 59fa6d695b5d..2f447da24a08 100644 --- a/Tasks/PipAuthenticateV0/task.loc.json +++ b/Tasks/PipAuthenticateV0/task.loc.json @@ -10,7 +10,7 @@ "version": { "Major": 0, "Minor": 206, - "Patch": 0 + "Patch": 1 }, "runsOn": [ "Agent", diff --git a/Tasks/TwineAuthenticateV0/task.json b/Tasks/TwineAuthenticateV0/task.json index 92535691d20c..051674b73779 100644 --- a/Tasks/TwineAuthenticateV0/task.json +++ b/Tasks/TwineAuthenticateV0/task.json @@ -9,7 +9,7 @@ "category": "Package", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/TwineAuthenticateV0/task.loc.json b/Tasks/TwineAuthenticateV0/task.loc.json index 98bb5425bc9e..54bd6352a443 100644 --- a/Tasks/TwineAuthenticateV0/task.loc.json +++ b/Tasks/TwineAuthenticateV0/task.loc.json @@ -9,13 +9,10 @@ "category": "Package", "version": { "Major": 0, - "Minor": 202, + "Minor": 206, "Patch": 0 }, - "runsOn": [ - "Agent", - "DeploymentGroup" - ], + "runsOn": ["Agent", "DeploymentGroup"], "minimumAgentVersion": "2.115.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", "groups": [ @@ -33,9 +30,7 @@ "inputs": [ { "name": "feedList", - "aliases": [ - "artifactFeeds" - ], + "aliases": ["artifactFeeds"], "type": "pickList", "label": "ms-resource:loc.input.label.feedList", "helpMarkDown": "ms-resource:loc.input.help.feedList", @@ -49,9 +44,7 @@ }, { "name": "externalSources", - "aliases": [ - "externalFeeds" - ], + "aliases": ["externalFeeds"], "type": "connectedService:externalPythonUploadFeed", "label": "ms-resource:loc.input.label.externalSources", "required": false,