From e1ca0af5185be891f34a2e15ca7f4ccf1cc87091 Mon Sep 17 00:00:00 2001 From: Jay Wen Date: Mon, 6 Jun 2022 11:57:41 -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 | 4 +-- .../DownloadGitHubNpmPackageV1/task.loc.json | 4 +-- Tasks/DownloadGitHubNugetPackageV1/task.json | 4 +-- .../task.loc.json | 4 +-- 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 | 2 +- 26 files changed, 63 insertions(+), 29 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 2441d70b2038..dfc03a010c14 100644 --- a/Tasks/DownloadGitHubNpmPackageV1/task.json +++ b/Tasks/DownloadGitHubNpmPackageV1/task.json @@ -9,8 +9,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 198, - "Patch": 1 + "Minor": 204, + "Patch": 0 }, "runsOn": [ "Agent", diff --git a/Tasks/DownloadGitHubNpmPackageV1/task.loc.json b/Tasks/DownloadGitHubNpmPackageV1/task.loc.json index 4cb3249186f8..e04684e256cf 100644 --- a/Tasks/DownloadGitHubNpmPackageV1/task.loc.json +++ b/Tasks/DownloadGitHubNpmPackageV1/task.loc.json @@ -9,8 +9,8 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 198, - "Patch": 1 + "Minor": 204, + "Patch": 0 }, "runsOn": [ "Agent", diff --git a/Tasks/DownloadGitHubNugetPackageV1/task.json b/Tasks/DownloadGitHubNugetPackageV1/task.json index bf3df5fc783b..3e18a8635647 100644 --- a/Tasks/DownloadGitHubNugetPackageV1/task.json +++ b/Tasks/DownloadGitHubNugetPackageV1/task.json @@ -17,8 +17,8 @@ "demands": [], "version": { "Major": 1, - "Minor": 200, - "Patch": 1 + "Minor": 204, + "Patch": 0 }, "minimumAgentVersion": "2.115.0", "instanceNameFormat": "dotnet restore", diff --git a/Tasks/DownloadGitHubNugetPackageV1/task.loc.json b/Tasks/DownloadGitHubNugetPackageV1/task.loc.json index 8e86fc0ebe1b..4b8ac7e12290 100644 --- a/Tasks/DownloadGitHubNugetPackageV1/task.loc.json +++ b/Tasks/DownloadGitHubNugetPackageV1/task.loc.json @@ -17,8 +17,8 @@ "demands": [], "version": { "Major": 1, - "Minor": 200, - "Patch": 1 + "Minor": 204, + "Patch": 0 }, "minimumAgentVersion": "2.115.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", diff --git a/Tasks/NpmAuthenticateV0/task.json b/Tasks/NpmAuthenticateV0/task.json index 583d7a72a336..ebb623efade8 100644 --- a/Tasks/NpmAuthenticateV0/task.json +++ b/Tasks/NpmAuthenticateV0/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NpmAuthenticateV0/task.loc.json b/Tasks/NpmAuthenticateV0/task.loc.json index 8b40d75ef6fc..858cc1878ed6 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": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetCommandV2/task.json b/Tasks/NuGetCommandV2/task.json index baf796412688..fb1f48c82d95 100644 --- a/Tasks/NuGetCommandV2/task.json +++ b/Tasks/NuGetCommandV2/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetCommandV2/task.loc.json b/Tasks/NuGetCommandV2/task.loc.json index 553da249aac4..571b06661881 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": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetInstallerV0/task.json b/Tasks/NuGetInstallerV0/task.json index bcfbd3ec91da..a25c421a7d90 100644 --- a/Tasks/NuGetInstallerV0/task.json +++ b/Tasks/NuGetInstallerV0/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetInstallerV0/task.loc.json b/Tasks/NuGetInstallerV0/task.loc.json index 7cfe85650221..6188e6713878 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": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetPublisherV0/task.json b/Tasks/NuGetPublisherV0/task.json index 1dde7c8d960d..24d0963d5522 100644 --- a/Tasks/NuGetPublisherV0/task.json +++ b/Tasks/NuGetPublisherV0/task.json @@ -9,7 +9,7 @@ "author": "Lawrence Gripper", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetPublisherV0/task.loc.json b/Tasks/NuGetPublisherV0/task.loc.json index 509001f5e9f0..388e4418d5dd 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": 204, "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..cd9d66c6394d 100644 --- a/Tasks/NuGetRestoreV1/task.json +++ b/Tasks/NuGetRestoreV1/task.json @@ -9,7 +9,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 198, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetRestoreV1/task.loc.json b/Tasks/NuGetRestoreV1/task.loc.json index 612ec3749e43..5ee09ea059c5 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": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetToolInstallerV0/task.json b/Tasks/NuGetToolInstallerV0/task.json index 5968fb591edf..1ba107848fe0 100644 --- a/Tasks/NuGetToolInstallerV0/task.json +++ b/Tasks/NuGetToolInstallerV0/task.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetToolInstallerV0/task.loc.json b/Tasks/NuGetToolInstallerV0/task.loc.json index 89b8c5b77a43..8537e13a9ab9 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": 204, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetToolInstallerV1/task.json b/Tasks/NuGetToolInstallerV1/task.json index 2970b88d1f51..871c15863188 100644 --- a/Tasks/NuGetToolInstallerV1/task.json +++ b/Tasks/NuGetToolInstallerV1/task.json @@ -14,7 +14,7 @@ "author": "Microsoft Corporation", "version": { "Major": 1, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetToolInstallerV1/task.loc.json b/Tasks/NuGetToolInstallerV1/task.loc.json index c21ce13e1302..869cf3db96ed 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": 204, "Patch": 0 }, "preview": false, diff --git a/Tasks/NuGetV0/task.json b/Tasks/NuGetV0/task.json index 8b9e995d96bd..ad6a46e4af26 100644 --- a/Tasks/NuGetV0/task.json +++ b/Tasks/NuGetV0/task.json @@ -10,7 +10,7 @@ "helpMarkDown": "", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/NuGetV0/task.loc.json b/Tasks/NuGetV0/task.loc.json index 5ef51f8636c8..1edb647622a5 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": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/PipAuthenticateV0/task.json b/Tasks/PipAuthenticateV0/task.json index cafc57ae4c8f..238dbd4753ef 100644 --- a/Tasks/PipAuthenticateV0/task.json +++ b/Tasks/PipAuthenticateV0/task.json @@ -9,7 +9,7 @@ "category": "Package", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/PipAuthenticateV0/task.loc.json b/Tasks/PipAuthenticateV0/task.loc.json index b7f14f2fcaed..e23ae6e94858 100644 --- a/Tasks/PipAuthenticateV0/task.loc.json +++ b/Tasks/PipAuthenticateV0/task.loc.json @@ -9,7 +9,7 @@ "category": "Package", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/TwineAuthenticateV0/task.json b/Tasks/TwineAuthenticateV0/task.json index 92535691d20c..1ae6db3051e2 100644 --- a/Tasks/TwineAuthenticateV0/task.json +++ b/Tasks/TwineAuthenticateV0/task.json @@ -9,7 +9,7 @@ "category": "Package", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [ diff --git a/Tasks/TwineAuthenticateV0/task.loc.json b/Tasks/TwineAuthenticateV0/task.loc.json index 98bb5425bc9e..50f38a6342f6 100644 --- a/Tasks/TwineAuthenticateV0/task.loc.json +++ b/Tasks/TwineAuthenticateV0/task.loc.json @@ -9,7 +9,7 @@ "category": "Package", "version": { "Major": 0, - "Minor": 202, + "Minor": 204, "Patch": 0 }, "runsOn": [