Skip to content

Commit

Permalink
Update NugetToolInstaller to add nuget script for unix system to get …
Browse files Browse the repository at this point in the history
…the correct version (#16397) (#16423)

* 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
  • Loading branch information
jiaw37 authored Jun 7, 2022
1 parent 75b8e92 commit 8b8975e
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 29 deletions.
33 changes: 33 additions & 0 deletions Tasks/Common/packaging-common/nuget/NuGetToolGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
Expand All @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Tasks/DownloadGitHubNpmPackageV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 198,
"Patch": 1
"Minor": 204,
"Patch": 0
},
"runsOn": [
"Agent",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/DownloadGitHubNpmPackageV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 198,
"Patch": 1
"Minor": 204,
"Patch": 0
},
"runsOn": [
"Agent",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/DownloadGitHubNugetPackageV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"demands": [],
"version": {
"Major": 1,
"Minor": 200,
"Patch": 1
"Minor": 204,
"Patch": 0
},
"minimumAgentVersion": "2.115.0",
"instanceNameFormat": "dotnet restore",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/DownloadGitHubNugetPackageV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NpmAuthenticateV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NpmAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetCommandV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetCommandV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetPublisherV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Lawrence Gripper",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetPublisherV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Lawrence Gripper",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
3 changes: 2 additions & 1 deletion Tasks/NuGetRestoreV1/nugetinstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ async function main(): Promise<void> {
// 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);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetRestoreV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 198,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetRestoreV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 198,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"preview": false,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"preview": false,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"preview": false,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetToolInstallerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"preview": false,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"helpMarkDown": "",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"helpMarkDown": "ms-resource:loc.helpMarkDown",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PipAuthenticateV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"category": "Package",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PipAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"category": "Package",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/TwineAuthenticateV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"category": "Package",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/TwineAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"category": "Package",
"version": {
"Major": 0,
"Minor": 202,
"Minor": 204,
"Patch": 0
},
"runsOn": [
Expand Down

0 comments on commit 8b8975e

Please sign in to comment.