diff --git a/Tasks/PythonScriptV0/Strings/resources.resjson/en-US/resources.resjson b/Tasks/PythonScriptV0/Strings/resources.resjson/en-US/resources.resjson new file mode 100644 index 000000000000..50ccdcc2d6f1 --- /dev/null +++ b/Tasks/PythonScriptV0/Strings/resources.resjson/en-US/resources.resjson @@ -0,0 +1,22 @@ +{ + "loc.friendlyName": "Python Script", + "loc.helpMarkDown": "", + "loc.description": "Run a Python script.", + "loc.instanceNameFormat": "Run Python script", + "loc.group.displayName.advanced": "Advanced", + "loc.input.label.scriptSource": "Script source", + "loc.input.help.scriptSource": "Whether the script is a file in the source tree or is written inline in this task.", + "loc.input.label.scriptPath": "Script path", + "loc.input.help.scriptPath": "Path of the script to execute. Must be a fully qualified path or relative to $(System.DefaultWorkingDirectory).", + "loc.input.label.script": "Script", + "loc.input.help.script": "The Python script to run", + "loc.input.label.arguments": "Arguments", + "loc.input.help.arguments": "Arguments passed to the script execution, available through `sys.argv`.", + "loc.input.label.pythonInterpreter": "Python interpreter", + "loc.input.help.pythonInterpreter": "Absolute path to the Python interpreter to use. If not specified, the task will use the interpreter in PATH.
Run the [Use Python Version](https://go.microsoft.com/fwlink/?linkid=871498) task to add a version of Python to PATH.", + "loc.input.label.workingDirectory": "Working directory", + "loc.input.label.failOnStderr": "Fail on standard error", + "loc.input.help.failOnStderr": "If this is true, this task will fail if any text is written to the stderr stream.", + "loc.messages.NotAFile": "The given path was not to a file: '%s'.", + "loc.messages.ParameterRequired": "The `%s` parameter is required" +} \ No newline at end of file diff --git a/Tasks/PythonScriptV0/ThirdPartyNotice.txt b/Tasks/PythonScriptV0/ThirdPartyNotice.txt new file mode 100644 index 000000000000..6fab32e71821 --- /dev/null +++ b/Tasks/PythonScriptV0/ThirdPartyNotice.txt @@ -0,0 +1,349 @@ + +THIRD-PARTY SOFTWARE NOTICES AND INFORMATION +Do Not Translate or Localize + +This Visual Studio Team Services extension (PythonScriptV0) is based on or incorporates material from the projects listed below (Third Party IP). The original copyright notice and the license under which Microsoft received such Third Party IP, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft licenses the Third Party IP to you under the licensing terms for the Visual Studio Team Services extension. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise. + +1. @types/node (git+https://github.com/DefinitelyTyped/DefinitelyTyped.git.git) +2. @types/q (https://www.github.com/DefinitelyTyped/DefinitelyTyped.git) +3. @types/uuid (https://www.github.com/DefinitelyTyped/DefinitelyTyped.git) +4. balanced-match (git://github.com/juliangruber/balanced-match.git) +5. brace-expansion (git://github.com/juliangruber/brace-expansion.git) +6. concat-map (git://github.com/substack/node-concat-map.git) +7. minimatch (git://github.com/isaacs/minimatch.git) +8. mockery (git://github.com/mfncooper/mockery.git) +9. q (git://github.com/kriskowal/q.git) +10. semver (git+https://github.com/npm/node-semver.git) +11. shelljs (git://github.com/arturadib/shelljs.git) +12. uuid (git+https://github.com/kelektiv/node-uuid.git) +13. vsts-task-lib (git+https://github.com/Microsoft/vsts-task-lib.git) + + +%% @types/node NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +MIT License + + Copyright (c) Microsoft Corporation. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE +========================================= +END OF @types/node NOTICES, INFORMATION, AND LICENSE + +%% @types/q NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +MIT License + + Copyright (c) Microsoft Corporation. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE +========================================= +END OF @types/q NOTICES, INFORMATION, AND LICENSE + +%% @types/uuid NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +MIT License + + Copyright (c) Microsoft Corporation. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE +========================================= +END OF @types/uuid NOTICES, INFORMATION, AND LICENSE + +%% balanced-match NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +(MIT) + +Copyright (c) 2013 Julian Gruber <julian@juliangruber.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +========================================= +END OF balanced-match NOTICES, INFORMATION, AND LICENSE + +%% brace-expansion NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +MIT License + +Copyright (c) 2013 Julian Gruber + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +========================================= +END OF brace-expansion NOTICES, INFORMATION, AND LICENSE + +%% concat-map NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +This software is released under the MIT license: + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +END OF concat-map NOTICES, INFORMATION, AND LICENSE + +%% minimatch NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +The ISC License + +Copyright (c) Isaac Z. Schlueter and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +========================================= +END OF minimatch NOTICES, INFORMATION, AND LICENSE + +%% mockery NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +Copyrights for code authored by Yahoo! Inc. is licensed under the following + terms: + + MIT License + + Copyright (c) 2011 Yahoo! Inc. All Rights Reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +========================================= +END OF mockery NOTICES, INFORMATION, AND LICENSE + +%% q NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +Copyright 2009–2017 Kristopher Michael Kowal. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. +========================================= +END OF q NOTICES, INFORMATION, AND LICENSE + +%% semver NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +The ISC License + +Copyright (c) Isaac Z. Schlueter and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +========================================= +END OF semver NOTICES, INFORMATION, AND LICENSE + +%% shelljs NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +Copyright (c) 2012, Artur Adib +All rights reserved. + +You may use this project under the terms of the New BSD license as follows: + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Artur Adib nor the + names of the contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +========================================= +END OF shelljs NOTICES, INFORMATION, AND LICENSE + +%% uuid NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +The MIT License (MIT) + +Copyright (c) 2010-2016 Robert Kieffer and other contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +========================================= +END OF uuid NOTICES, INFORMATION, AND LICENSE + +%% vsts-task-lib NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +The MIT License (MIT) + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +========================================= +END OF vsts-task-lib NOTICES, INFORMATION, AND LICENSE + diff --git a/Tasks/PythonScriptV0/icon.png b/Tasks/PythonScriptV0/icon.png new file mode 100644 index 000000000000..549bcaa04747 Binary files /dev/null and b/Tasks/PythonScriptV0/icon.png differ diff --git a/Tasks/PythonScriptV0/main.ts b/Tasks/PythonScriptV0/main.ts new file mode 100644 index 000000000000..a89aeb94d02a --- /dev/null +++ b/Tasks/PythonScriptV0/main.ts @@ -0,0 +1,22 @@ +import * as path from 'path'; +import * as task from 'vsts-task-lib/task'; +import { pythonScript } from './pythonscript'; + +(async () => { + try { + task.setResourcePath(path.join(__dirname, 'task.json')); + await pythonScript({ + scriptSource: task.getInput('scriptSource'), + scriptPath: task.getPathInput('scriptPath'), + script: task.getInput('script'), + arguments: task.getInput('arguments'), + pythonInterpreter: task.getInput('pythonInterpreter'), // string instead of path: a path will default to the agent's sources directory + workingDirectory: task.getPathInput('workingDirectory'), + failOnStderr: task.getBoolInput('failOnStderr') + }); + task.setResult(task.TaskResult.Succeeded, ""); + } catch (error) { + task.error(error.message); + task.setResult(task.TaskResult.Failed, error.message); + } +})(); diff --git a/Tasks/PythonScriptV0/package-lock.json b/Tasks/PythonScriptV0/package-lock.json new file mode 100644 index 000000000000..7c4eec086240 --- /dev/null +++ b/Tasks/PythonScriptV0/package-lock.json @@ -0,0 +1,91 @@ +{ + "name": "python-script", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/node": { + "version": "6.0.110", + "resolved": "https://registry.npmjs.org/@types/node/-/node-6.0.110.tgz", + "integrity": "sha512-LiaH3mF+OAqR+9Wo1OTJDbZDtCewAVjTbMhF1ZgUJ3fc8xqOJq6VqbpBh9dJVCVzByGmYIg2fREbuXNX0TKiJA==" + }, + "@types/q": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.0.tgz", + "integrity": "sha512-sWj7AMiG0fYmta6ug1ublLjtj/tqn+CnCZeo7yswR1ykxel0FOWFGdWviTcGSNAMmtLbycDqbg6w98VPFKJmbw==" + }, + "@types/uuid": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.3.tgz", + "integrity": "sha512-5fRLCYhLtDb3hMWqQyH10qtF+Ud2JnNCXTCZ+9ktNdCcgslcuXkDTkFcJNk++MT29yDntDnlF1+jD+uVGumsbw==", + "requires": { + "@types/node": "*" + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "mockery": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/mockery/-/mockery-1.7.0.tgz", + "integrity": "sha1-9O3g2HUMHJcnwnLqLGBiniyaHE8=" + }, + "q": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz", + "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=" + }, + "semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=" + }, + "uuid": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", + "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" + }, + "vsts-task-lib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/vsts-task-lib/-/vsts-task-lib-2.4.0.tgz", + "integrity": "sha512-AqKNrYw6ebzlaV6o09TTWE9LxcywQPanPeocss8BUJXJFEMLRYr3ZyzzjM+lvvsgcYth74VXoHtkBonBpx//Tg==", + "requires": { + "minimatch": "3.0.4", + "mockery": "^1.7.0", + "q": "^1.1.2", + "semver": "^5.1.0", + "shelljs": "^0.3.0", + "uuid": "^3.0.1" + } + } + } +} diff --git a/Tasks/PythonScriptV0/package.json b/Tasks/PythonScriptV0/package.json new file mode 100644 index 000000000000..d46f6e45ab98 --- /dev/null +++ b/Tasks/PythonScriptV0/package.json @@ -0,0 +1,25 @@ +{ + "name": "python-script", + "version": "1.0.0", + "description": "Create and activate a Conda environment.", + "main": "pythonscript.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/microsoft/vsts-tasks.git" + }, + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/microsoft/vsts-tasks/issues" + }, + "homepage": "https://github.com/microsoft/vsts-tasks#readme", + "dependencies": { + "@types/node": "^6.0.101", + "@types/q": "^1.5.0", + "@types/uuid": "^3.4.3", + "vsts-task-lib": "^2.4.0" + } +} diff --git a/Tasks/PythonScriptV0/pythonscript.ts b/Tasks/PythonScriptV0/pythonscript.ts new file mode 100644 index 000000000000..439be202c41c --- /dev/null +++ b/Tasks/PythonScriptV0/pythonscript.ts @@ -0,0 +1,89 @@ +import * as fs from 'fs'; +import * as path from 'path'; + +import * as task from 'vsts-task-lib/task'; +import * as toolRunner from 'vsts-task-lib/toolrunner'; + +import * as uuidV4 from 'uuid/v4'; + +interface TaskParameters { + scriptSource: string, + scriptPath?: string, + script?: string, + arguments?: string, + pythonInterpreter?: string, + workingDirectory?: string, + failOnStderr?: boolean +} + +/** + * Check for a parameter at runtime. + * Useful for conditionally-visible, required parameters. + */ +function assertParameter(value: T | undefined, propertyName: string): T { + if (!value) { + throw new Error(task.loc('ParameterRequired', propertyName)); + } + + return value!; +} + +// TODO Enable with TypeScript 2.8 (ensures correct property name in the error message) +// function assertParameter(parameters: TaskParameters, propertyName: T): NonNullable { +// const param = parameters[propertyName]; +// if (!param) { +// throw new Error(task.loc('ParameterRequired', propertyName)); +// } + +// return param!; +// } + +export async function pythonScript(parameters: Readonly): Promise { + // Get the script to run + const scriptPath = await (async () => { + if (parameters.scriptSource.toLowerCase() === 'filepath') { // Run script file + const scriptPath = assertParameter(parameters.scriptPath, 'scriptPath'); + + if (!fs.statSync(scriptPath).isFile()) { + throw new Error(task.loc('NotAFile', scriptPath)); + } + return scriptPath; + } else { // Run inline script + const script = assertParameter(parameters.script, 'script'); + + // Write the script to disk + task.assertAgent('2.115.0'); + const tempDirectory = task.getVariable('agent.tempDirectory'); + task.checkPath(tempDirectory, `${tempDirectory} (agent.tempDirectory)`); + const scriptPath = path.join(tempDirectory, `${uuidV4()}.py`); + await fs.writeFileSync( + scriptPath, + script, + { encoding: 'utf8' }); + + return scriptPath; + } + })(); + + // Create the tool runner + const pythonPath = parameters.pythonInterpreter || task.which('python'); + const python = task.tool(pythonPath).arg(scriptPath); + + // Calling `line` with a falsy argument returns `undefined`, so can't chain this call + if (parameters.arguments) { + python.line(parameters.arguments); + } + + // Run the script + // Use `any` to work around what I suspect are bugs with `IExecOptions`'s type annotations: + // - optional fields need to be typed as optional + // - `errStream` and `outStream` should be `NodeJs.WritableStream`, not `NodeJS.Writable` + await python.exec({ + cwd: parameters.workingDirectory, + failOnStdErr: parameters.failOnStderr, + // Direct all output to stdout, otherwise the output may appear out-of-order since Node buffers its own stdout but not stderr + errStream: process.stdout, + outStream: process.stdout, + ignoreReturnCode: false + }); +} \ No newline at end of file diff --git a/Tasks/PythonScriptV0/task.json b/Tasks/PythonScriptV0/task.json new file mode 100644 index 000000000000..586707b9deb6 --- /dev/null +++ b/Tasks/PythonScriptV0/task.json @@ -0,0 +1,113 @@ +{ + "id": "6392F95F-7E76-4A18-B3C7-7F078D2F7700", + "name": "PythonScript", + "friendlyName": "Python Script", + "description": "Run a Python script.", + "helpMarkDown": "", + "category": "Utility", + "visibility": [ + "Build", + "Release" + ], + "runsOn": [ + "Agent", + "DeploymentGroup" + ], + "author": "Microsoft Corporation", + "version": { + "Major": 0, + "Minor": 135, + "Patch": 0 + }, + "preview": true, + "demands": [], + "instanceNameFormat": "Run Python script", + "groups": [ + { + "name": "advanced", + "displayName": "Advanced", + "isExpanded": false + } + ], + "inputs": [ + { + "name": "scriptSource", + "type": "radio", + "label": "Script source", + "required": true, + "defaultValue": "filePath", + "helpMarkDown": "Whether the script is a file in the source tree or is written inline in this task.", + "options": { + "filePath": "File path", + "inline": "Inline" + } + }, + { + "name": "scriptPath", + "type": "filePath", + "label": "Script path", + "visibleRule": "scriptSource = filePath", + "required": true, + "defaultValue": "", + "helpMarkDown": "Path of the script to execute. Must be a fully qualified path or relative to $(System.DefaultWorkingDirectory)." + }, + { + "name": "script", + "type": "multiLine", + "label": "Script", + "visibleRule": "scriptSource = inline", + "required": true, + "defaultValue": "", + "properties": { + "resizable": "true", + "rows": "10", + "maxLength": "5000" + }, + "helpMarkDown": "The Python script to run" + }, + { + "name": "arguments", + "type": "string", + "label": "Arguments", + "required": false, + "defaultValue": "", + "helpMarkDown": "Arguments passed to the script execution, available through `sys.argv`." + }, + { + "name": "pythonInterpreter", + "type": "string", + "label": "Python interpreter", + "defaultValue": "", + "required": false, + "helpMarkDown": "Absolute path to the Python interpreter to use. If not specified, the task will use the interpreter in PATH.
Run the [Use Python Version](https://go.microsoft.com/fwlink/?linkid=871498) task to add a version of Python to PATH.", + "groupName": "advanced" + }, + { + "name": "workingDirectory", + "type": "filePath", + "label": "Working directory", + "defaultValue": "", + "required": false, + "groupName": "advanced" + }, + { + "name": "failOnStderr", + "type": "boolean", + "label": "Fail on standard error", + "defaultValue": "false", + "required": false, + "helpMarkDown": "If this is true, this task will fail if any text is written to the stderr stream.", + "groupName": "advanced" + } + ], + "execution": { + "Node": { + "target": "main.js", + "argumentFormat": "" + } + }, + "messages": { + "NotAFile": "The given path was not to a file: '%s'.", + "ParameterRequired": "The `%s` parameter is required" + } +} \ No newline at end of file diff --git a/Tasks/PythonScriptV0/task.loc.json b/Tasks/PythonScriptV0/task.loc.json new file mode 100644 index 000000000000..08ed252167c3 --- /dev/null +++ b/Tasks/PythonScriptV0/task.loc.json @@ -0,0 +1,113 @@ +{ + "id": "6392F95F-7E76-4A18-B3C7-7F078D2F7700", + "name": "PythonScript", + "friendlyName": "ms-resource:loc.friendlyName", + "description": "ms-resource:loc.description", + "helpMarkDown": "ms-resource:loc.helpMarkDown", + "category": "Utility", + "visibility": [ + "Build", + "Release" + ], + "runsOn": [ + "Agent", + "DeploymentGroup" + ], + "author": "Microsoft Corporation", + "version": { + "Major": 0, + "Minor": 135, + "Patch": 0 + }, + "preview": true, + "demands": [], + "instanceNameFormat": "ms-resource:loc.instanceNameFormat", + "groups": [ + { + "name": "advanced", + "displayName": "ms-resource:loc.group.displayName.advanced", + "isExpanded": false + } + ], + "inputs": [ + { + "name": "scriptSource", + "type": "radio", + "label": "ms-resource:loc.input.label.scriptSource", + "required": true, + "defaultValue": "filePath", + "helpMarkDown": "ms-resource:loc.input.help.scriptSource", + "options": { + "filePath": "File path", + "inline": "Inline" + } + }, + { + "name": "scriptPath", + "type": "filePath", + "label": "ms-resource:loc.input.label.scriptPath", + "visibleRule": "scriptSource = filePath", + "required": true, + "defaultValue": "", + "helpMarkDown": "ms-resource:loc.input.help.scriptPath" + }, + { + "name": "script", + "type": "multiLine", + "label": "ms-resource:loc.input.label.script", + "visibleRule": "scriptSource = inline", + "required": true, + "defaultValue": "", + "properties": { + "resizable": "true", + "rows": "10", + "maxLength": "5000" + }, + "helpMarkDown": "ms-resource:loc.input.help.script" + }, + { + "name": "arguments", + "type": "string", + "label": "ms-resource:loc.input.label.arguments", + "required": false, + "defaultValue": "", + "helpMarkDown": "ms-resource:loc.input.help.arguments" + }, + { + "name": "pythonInterpreter", + "type": "string", + "label": "ms-resource:loc.input.label.pythonInterpreter", + "defaultValue": "", + "required": false, + "helpMarkDown": "ms-resource:loc.input.help.pythonInterpreter", + "groupName": "advanced" + }, + { + "name": "workingDirectory", + "type": "filePath", + "label": "ms-resource:loc.input.label.workingDirectory", + "defaultValue": "", + "required": false, + "groupName": "advanced" + }, + { + "name": "failOnStderr", + "type": "boolean", + "label": "ms-resource:loc.input.label.failOnStderr", + "defaultValue": "false", + "required": false, + "helpMarkDown": "ms-resource:loc.input.help.failOnStderr", + "groupName": "advanced" + } + ], + "execution": { + "Node": { + "target": "main.js", + "argumentFormat": "" + } + }, + "messages": { + "NotAFile": "ms-resource:loc.messages.NotAFile", + "ParameterRequired": "ms-resource:loc.messages.ParameterRequired" + } +} \ No newline at end of file diff --git a/Tasks/PythonScriptV0/tsconfig.json b/Tasks/PythonScriptV0/tsconfig.json new file mode 100644 index 000000000000..e2d9151cbddc --- /dev/null +++ b/Tasks/PythonScriptV0/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "commonjs", + "strict": true + } +} \ No newline at end of file diff --git a/make-options.json b/make-options.json index fb08cf760788..e56dd190f76e 100644 --- a/make-options.json +++ b/make-options.json @@ -82,6 +82,7 @@ "PublishTestResults", "PublishToAzureServiceBusV1", "PyPIPublisherV0", + "PythonScriptV0", "QueryWorkItemsV0", "QuickPerfTestV1", "RunDistributedTestsV1", diff --git a/templates/ci/python-django.yml b/templates/ci/python-django.yml index 02563ae458eb..490698a20280 100644 --- a/templates/ci/python-django.yml +++ b/templates/ci/python-django.yml @@ -22,22 +22,20 @@ phases: versionSpec: '$(PYTHON_VERSION)' architecture: 'x64' - - script: | - python - << 'END_DETECT' - from glob import iglob - from os import path - - # Python >= 3.5 - manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None) - - if not manage_py: - raise SystemExit('Could not find a Django project') - - project_location = path.dirname(path.abspath(manage_py)) - - print('Found Django project in', project_location) - print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location)) - END_DETECT + - task: PythonScript@0 + inputs: + targetType: 'inline' + script: | + """Search all subdirectories for `manage.py`.""" + from glob import iglob + from os import path + # Python >= 3.5 + manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None) + if not manage_py: + raise SystemExit('Could not find a Django project') + project_location = path.dirname(path.abspath(manage_py)) + print('Found Django project in', project_location) + print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location)) name: setvar displayName: 'Export project folder name' @@ -67,4 +65,4 @@ phases: # inputs: # sourceFolder: '$(build.sourcesDirectory)' # targetFolder: '$(build.artifactStagingDirectory)' -# - task: PublishBuildArtifacts@1 \ No newline at end of file +# - task: PublishBuildArtifacts@1