Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to suppress github token warning #20534

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"loc.input.help.addToPath": "Whether to prepend the retrieved Python version to the PATH environment variable to make it available in subsequent tasks or scripts without using the output variable.",
"loc.input.label.architecture": "Architecture",
"loc.input.help.architecture": "The target architecture (x86, x64) of the Python interpreter.",
"loc.input.label.suppressGitHubTokenWarning": "Supress GitHub token warning",
"loc.input.help.suppressGitHubTokenWarning": "Supress GitHub token warning when the token is not provided.",
"loc.messages.ListAvailableVersions": "Versions in %s:",
"loc.messages.PlatformNotRecognized": "Platform not recognized",
"loc.messages.PrependPath": "Prepending PATH environment variable with directory: %s",
Expand Down
1 change: 1 addition & 0 deletions Tasks/UsePythonVersionV0/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('UsePythonVersion L0 Suite', function () {
assert(didPrependPath(testRunner, pythonDir));
assert(didPrependPath(testRunner, pythonBinDir));
assert(didPrependPath(testRunner, pythonAppdataDir));
assert(testRunner.stdout.includes("loc_mock_MissingGithubToken"), 'should log warning when github token is missing');
assert.strictEqual(testRunner.stderr.length, 0, 'should not have written to stderr');
assert(testRunner.succeeded, 'task should have succeeded');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
const taskPath = path.join(__dirname, '..', 'main.js');
const taskRunner = new TaskMockRunner(taskPath);

const TEST_GITHUB_TOKEN = 'testtoken';

taskRunner.setInput('versionSpec', '3.10.x');
taskRunner.setInput('disableDownloadFromRegistry', 'false');
taskRunner.setInput('addToPath', 'true');
taskRunner.setInput('architecture', 'x64');
taskRunner.setInput('githubToken', TEST_GITHUB_TOKEN);


// `getVariable` is not supported by `TaskLibAnswers`
process.env['AGENT_TOOLSDIRECTORY'] = '$(Agent.ToolsDirectory)';
Expand Down
3 changes: 1 addition & 2 deletions Tasks/UsePythonVersionV0/Tests/L0DownloadsUnstable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
const taskPath = path.join(__dirname, '..', 'main.js');
const taskRunner = new TaskMockRunner(taskPath);

const TEST_GITHUB_TOKEN = 'testtoken';

taskRunner.setInput('versionSpec', '3.11.x');
taskRunner.setInput('disableDownloadFromRegistry', 'false');
taskRunner.setInput('allowUnstable', 'true');
taskRunner.setInput('addToPath', 'true');
taskRunner.setInput('architecture', 'x64');
taskRunner.setInput('githubToken', TEST_GITHUB_TOKEN);
taskRunner.setInput('suppressGitHubTokenWarning', 'true');

// `getVariable` is not supported by `TaskLibAnswers`
process.env['AGENT_TOOLSDIRECTORY'] = '$(Agent.ToolsDirectory)';
Expand Down
6 changes: 4 additions & 2 deletions Tasks/UsePythonVersionV0/Tests/L0_usepythonversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ it('sets PATH correctly on Linux', async function () {
allowUnstable: true,
addToPath: true,
architecture: 'x64',
githubToken: 'testgithubtoken'
githubToken: 'testgithubtoken',
suppressGitHubTokenWarning: false
};

await uut.usePythonVersion(parameters, Platform.Linux);
Expand Down Expand Up @@ -84,7 +85,8 @@ it('sets PATH correctly on Windows', async function () {
allowUnstable: true,
addToPath: true,
architecture: 'x64',
githubToken: 'testgithubtoken'
githubToken: 'testgithubtoken',
suppressGitHubTokenWarning: false
};

await uut.usePythonVersion(parameters, Platform.Windows);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/UsePythonVersionV0/installpythonversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function downloadPythonVersion(versionSpec: string, parameters: TaskParame
const additionalHeaders = {};
if (parameters.githubToken) {
additionalHeaders['Authorization'] = auth;
} else {
} else if (!parameters.suppressGitHubTokenWarning){
task.warning(task.loc('MissingGithubToken'));
}

Expand Down
1 change: 1 addition & 0 deletions Tasks/UsePythonVersionV0/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface TaskParameters {
addToPath: boolean,
architecture: string,
githubToken?: string
suppressGitHubTokenWarning: boolean
}

export interface PythonRelease {
Expand Down
5 changes: 4 additions & 1 deletion Tasks/UsePythonVersionV0/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import { usePythonVersion } from './usepythonversion';
const addToPath = task.getBoolInput('addToPath', true);
const architecture = task.getInput('architecture', true);
const githubToken = task.getInput('githubToken', false);
const suppressGitHubTokenWarning = task.getBoolInput('suppressGitHubTokenWarning', false);

await usePythonVersion({
versionSpec,
allowUnstable,
disableDownloadFromRegistry,
addToPath,
architecture,
githubToken
githubToken,
suppressGitHubTokenWarning
},
getPlatform());
task.setResult(task.TaskResult.Succeeded, "");
Expand Down
11 changes: 10 additions & 1 deletion Tasks/UsePythonVersionV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"minimumAgentVersion": "2.182.1",
"version": {
"Major": 0,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -80,6 +80,15 @@
"x86": "x86",
"x64": "x64"
}
},
{
"name": "suppressGitHubTokenWarning",
"type": "boolean",
"label": "Supress GitHub token warning",
"required": false,
"defaultValue": "false",
"helpMarkDown": "Supress GitHub token warning when the token is not provided.",
"groupName": "advanced"
}
],
"outputVariables": [
Expand Down
11 changes: 10 additions & 1 deletion Tasks/UsePythonVersionV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"minimumAgentVersion": "2.182.1",
"version": {
"Major": 0,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -80,6 +80,15 @@
"x86": "x86",
"x64": "x64"
}
},
{
"name": "suppressGitHubTokenWarning",
"type": "boolean",
"label": "ms-resource:loc.input.label.suppressGitHubTokenWarning",
"required": false,
"defaultValue": "false",
"helpMarkDown": "ms-resource:loc.input.help.suppressGitHubTokenWarning",
"groupName": "advanced"
}
],
"outputVariables": [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions _generated/UsePythonVersionV0.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|0.246.0
Node20-225|0.246.1
Default|0.247.0
Node20-225|0.247.1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"loc.input.help.addToPath": "Whether to prepend the retrieved Python version to the PATH environment variable to make it available in subsequent tasks or scripts without using the output variable.",
"loc.input.label.architecture": "Architecture",
"loc.input.help.architecture": "The target architecture (x86, x64) of the Python interpreter.",
"loc.input.label.suppressGitHubTokenWarning": "Supress GitHub token warning",
"loc.input.help.suppressGitHubTokenWarning": "Supress GitHub token warning when the token is not provided.",
"loc.messages.ListAvailableVersions": "Versions in %s:",
"loc.messages.PlatformNotRecognized": "Platform not recognized",
"loc.messages.PrependPath": "Prepending PATH environment variable with directory: %s",
Expand Down
1 change: 1 addition & 0 deletions _generated/UsePythonVersionV0/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('UsePythonVersion L0 Suite', function () {
assert(didPrependPath(testRunner, pythonDir));
assert(didPrependPath(testRunner, pythonBinDir));
assert(didPrependPath(testRunner, pythonAppdataDir));
assert(testRunner.stdout.includes("loc_mock_MissingGithubToken"), 'should log warning when github token is missing');
assert.strictEqual(testRunner.stderr.length, 0, 'should not have written to stderr');
assert(testRunner.succeeded, 'task should have succeeded');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
const taskPath = path.join(__dirname, '..', 'main.js');
const taskRunner = new TaskMockRunner(taskPath);

const TEST_GITHUB_TOKEN = 'testtoken';

taskRunner.setInput('versionSpec', '3.10.x');
taskRunner.setInput('disableDownloadFromRegistry', 'false');
taskRunner.setInput('addToPath', 'true');
taskRunner.setInput('architecture', 'x64');
taskRunner.setInput('githubToken', TEST_GITHUB_TOKEN);


// `getVariable` is not supported by `TaskLibAnswers`
process.env['AGENT_TOOLSDIRECTORY'] = '$(Agent.ToolsDirectory)';
Expand Down
3 changes: 1 addition & 2 deletions _generated/UsePythonVersionV0/Tests/L0DownloadsUnstable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
const taskPath = path.join(__dirname, '..', 'main.js');
const taskRunner = new TaskMockRunner(taskPath);

const TEST_GITHUB_TOKEN = 'testtoken';

taskRunner.setInput('versionSpec', '3.11.x');
taskRunner.setInput('disableDownloadFromRegistry', 'false');
taskRunner.setInput('allowUnstable', 'true');
taskRunner.setInput('addToPath', 'true');
taskRunner.setInput('architecture', 'x64');
taskRunner.setInput('githubToken', TEST_GITHUB_TOKEN);
taskRunner.setInput('suppressGitHubTokenWarning', 'true');

// `getVariable` is not supported by `TaskLibAnswers`
process.env['AGENT_TOOLSDIRECTORY'] = '$(Agent.ToolsDirectory)';
Expand Down
6 changes: 4 additions & 2 deletions _generated/UsePythonVersionV0/Tests/L0_usepythonversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ it('sets PATH correctly on Linux', async function () {
allowUnstable: true,
addToPath: true,
architecture: 'x64',
githubToken: 'testgithubtoken'
githubToken: 'testgithubtoken',
suppressGitHubTokenWarning: false
};

await uut.usePythonVersion(parameters, Platform.Linux);
Expand Down Expand Up @@ -84,7 +85,8 @@ it('sets PATH correctly on Windows', async function () {
allowUnstable: true,
addToPath: true,
architecture: 'x64',
githubToken: 'testgithubtoken'
githubToken: 'testgithubtoken',
suppressGitHubTokenWarning: false
};

await uut.usePythonVersion(parameters, Platform.Windows);
Expand Down
2 changes: 1 addition & 1 deletion _generated/UsePythonVersionV0/installpythonversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function downloadPythonVersion(versionSpec: string, parameters: TaskParame
const additionalHeaders = {};
if (parameters.githubToken) {
additionalHeaders['Authorization'] = auth;
} else {
} else if (!parameters.suppressGitHubTokenWarning){
task.warning(task.loc('MissingGithubToken'));
}

Expand Down
1 change: 1 addition & 0 deletions _generated/UsePythonVersionV0/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface TaskParameters {
addToPath: boolean,
architecture: string,
githubToken?: string
suppressGitHubTokenWarning: boolean
}

export interface PythonRelease {
Expand Down
5 changes: 4 additions & 1 deletion _generated/UsePythonVersionV0/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import { usePythonVersion } from './usepythonversion';
const addToPath = task.getBoolInput('addToPath', true);
const architecture = task.getInput('architecture', true);
const githubToken = task.getInput('githubToken', false);
const suppressGitHubTokenWarning = task.getBoolInput('suppressGitHubTokenWarning', false);

await usePythonVersion({
versionSpec,
allowUnstable,
disableDownloadFromRegistry,
addToPath,
architecture,
githubToken
githubToken,
suppressGitHubTokenWarning
},
getPlatform());
task.setResult(task.TaskResult.Succeeded, "");
Expand Down
15 changes: 12 additions & 3 deletions _generated/UsePythonVersionV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"minimumAgentVersion": "2.182.1",
"version": {
"Major": 0,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -80,6 +80,15 @@
"x86": "x86",
"x64": "x64"
}
},
{
"name": "suppressGitHubTokenWarning",
"type": "boolean",
"label": "Supress GitHub token warning",
"required": false,
"defaultValue": "false",
"helpMarkDown": "Supress GitHub token warning when the token is not provided.",
"groupName": "advanced"
}
],
"outputVariables": [
Expand Down Expand Up @@ -126,7 +135,7 @@
}
},
"_buildConfigMapping": {
"Default": "0.246.0",
"Node20-225": "0.246.1"
"Default": "0.247.0",
"Node20-225": "0.247.1"
}
}
15 changes: 12 additions & 3 deletions _generated/UsePythonVersionV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"minimumAgentVersion": "2.182.1",
"version": {
"Major": 0,
"Minor": 246,
"Minor": 247,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -80,6 +80,15 @@
"x86": "x86",
"x64": "x64"
}
},
{
"name": "suppressGitHubTokenWarning",
"type": "boolean",
"label": "ms-resource:loc.input.label.suppressGitHubTokenWarning",
"required": false,
"defaultValue": "false",
"helpMarkDown": "ms-resource:loc.input.help.suppressGitHubTokenWarning",
"groupName": "advanced"
}
],
"outputVariables": [
Expand Down Expand Up @@ -126,7 +135,7 @@
}
},
"_buildConfigMapping": {
"Default": "0.246.0",
"Node20-225": "0.246.1"
"Default": "0.247.0",
"Node20-225": "0.247.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"loc.input.help.addToPath": "Whether to prepend the retrieved Python version to the PATH environment variable to make it available in subsequent tasks or scripts without using the output variable.",
"loc.input.label.architecture": "Architecture",
"loc.input.help.architecture": "The target architecture (x86, x64) of the Python interpreter.",
"loc.input.label.suppressGitHubTokenWarning": "Supress GitHub token warning",
"loc.input.help.suppressGitHubTokenWarning": "Supress GitHub token warning when the token is not provided.",
"loc.messages.ListAvailableVersions": "Versions in %s:",
"loc.messages.PlatformNotRecognized": "Platform not recognized",
"loc.messages.PrependPath": "Prepending PATH environment variable with directory: %s",
Expand Down
1 change: 1 addition & 0 deletions _generated/UsePythonVersionV0_Node20/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('UsePythonVersion L0 Suite', function () {
assert(didPrependPath(testRunner, pythonDir));
assert(didPrependPath(testRunner, pythonBinDir));
assert(didPrependPath(testRunner, pythonAppdataDir));
assert(testRunner.stdout.includes("loc_mock_MissingGithubToken"), 'should log warning when github token is missing');
assert.strictEqual(testRunner.stderr.length, 0, 'should not have written to stderr');
assert(testRunner.succeeded, 'task should have succeeded');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
const taskPath = path.join(__dirname, '..', 'main.js');
const taskRunner = new TaskMockRunner(taskPath);

const TEST_GITHUB_TOKEN = 'testtoken';

taskRunner.setInput('versionSpec', '3.10.x');
taskRunner.setInput('disableDownloadFromRegistry', 'false');
taskRunner.setInput('addToPath', 'true');
taskRunner.setInput('architecture', 'x64');
taskRunner.setInput('githubToken', TEST_GITHUB_TOKEN);


// `getVariable` is not supported by `TaskLibAnswers`
process.env['AGENT_TOOLSDIRECTORY'] = '$(Agent.ToolsDirectory)';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
const taskPath = path.join(__dirname, '..', 'main.js');
const taskRunner = new TaskMockRunner(taskPath);

const TEST_GITHUB_TOKEN = 'testtoken';

taskRunner.setInput('versionSpec', '3.11.x');
taskRunner.setInput('disableDownloadFromRegistry', 'false');
taskRunner.setInput('allowUnstable', 'true');
taskRunner.setInput('addToPath', 'true');
taskRunner.setInput('architecture', 'x64');
taskRunner.setInput('githubToken', TEST_GITHUB_TOKEN);
taskRunner.setInput('suppressGitHubTokenWarning', 'true');

// `getVariable` is not supported by `TaskLibAnswers`
process.env['AGENT_TOOLSDIRECTORY'] = '$(Agent.ToolsDirectory)';
Expand Down
Loading