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)

* 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 6, 2022
1 parent a154f2e commit 0f199de
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 35 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
2 changes: 1 addition & 1 deletion Tasks/DownloadGitHubNpmPackageV1/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": 205,
"Minor": 206,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadGitHubNpmPackageV1/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": 205,
"Minor": 206,
"Patch": 0
},
"runsOn": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadGitHubNugetPackageV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 206,
"Patch": 0
"Patch": 1
},
"minimumAgentVersion": "2.144.0",
"instanceNameFormat": "dotnet restore",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadGitHubNugetPackageV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 206,
"Patch": 0
"Patch": 1
},
"minimumAgentVersion": "2.144.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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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": 206,
"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 @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 206,
"Patch": 0
"Patch": 1
},
"runsOn": [
"Agent",
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 @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 206,
"Patch": 0
"Patch": 1
},
"runsOn": [
"Agent",
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": 206,
"Patch": 0
},
"runsOn": [
Expand Down
15 changes: 4 additions & 11 deletions Tasks/TwineAuthenticateV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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",
Expand All @@ -49,9 +44,7 @@
},
{
"name": "externalSources",
"aliases": [
"externalFeeds"
],
"aliases": ["externalFeeds"],
"type": "connectedService:externalPythonUploadFeed",
"label": "ms-resource:loc.input.label.externalSources",
"required": false,
Expand Down

0 comments on commit 0f199de

Please sign in to comment.