From 1bbe18ccd019437bc8c20320a03e52cb28ab2a79 Mon Sep 17 00:00:00 2001 From: Ajinkya Date: Tue, 22 Oct 2019 12:37:47 +0530 Subject: [PATCH] Added Azure Func Tools Installer task. (#11348) * Added Azure Func Tools Installer task. * Use toolLib cache to cache the installation. * remove unnecessary dependencies * Addressing PR review comments * PR review changes --- .../func-tools-common/functoolsutility.ts | 78 ++++++++++ .../func-tools-common/package-lock.json | 129 +++++++++++++++++ Tasks/Common/func-tools-common/package.json | 19 +++ Tasks/Common/func-tools-common/tsconfig.json | 9 ++ Tasks/Common/func-tools-common/typings.json | 5 + .../resources.resjson/en-US/resources.resjson | 16 +++ Tasks/FuncToolsInstallerV0/icon.png | Bin 0 -> 1373 bytes Tasks/FuncToolsInstallerV0/icon.svg | 12 ++ Tasks/FuncToolsInstallerV0/make.json | 16 +++ Tasks/FuncToolsInstallerV0/package-lock.json | 134 ++++++++++++++++++ Tasks/FuncToolsInstallerV0/package.json | 7 + .../src/functoolsinstaller.ts | 34 +++++ Tasks/FuncToolsInstallerV0/src/utils.ts | 31 ++++ Tasks/FuncToolsInstallerV0/task.json | 50 +++++++ Tasks/FuncToolsInstallerV0/task.loc.json | 50 +++++++ Tasks/FuncToolsInstallerV0/tsconfig.json | 10 ++ make-options.json | 1 + 17 files changed, 601 insertions(+) create mode 100644 Tasks/Common/func-tools-common/functoolsutility.ts create mode 100644 Tasks/Common/func-tools-common/package-lock.json create mode 100644 Tasks/Common/func-tools-common/package.json create mode 100644 Tasks/Common/func-tools-common/tsconfig.json create mode 100644 Tasks/Common/func-tools-common/typings.json create mode 100644 Tasks/FuncToolsInstallerV0/Strings/resources.resjson/en-US/resources.resjson create mode 100644 Tasks/FuncToolsInstallerV0/icon.png create mode 100644 Tasks/FuncToolsInstallerV0/icon.svg create mode 100644 Tasks/FuncToolsInstallerV0/make.json create mode 100644 Tasks/FuncToolsInstallerV0/package-lock.json create mode 100644 Tasks/FuncToolsInstallerV0/package.json create mode 100644 Tasks/FuncToolsInstallerV0/src/functoolsinstaller.ts create mode 100644 Tasks/FuncToolsInstallerV0/src/utils.ts create mode 100644 Tasks/FuncToolsInstallerV0/task.json create mode 100644 Tasks/FuncToolsInstallerV0/task.loc.json create mode 100644 Tasks/FuncToolsInstallerV0/tsconfig.json diff --git a/Tasks/Common/func-tools-common/functoolsutility.ts b/Tasks/Common/func-tools-common/functoolsutility.ts new file mode 100644 index 000000000000..f36c7caddfce --- /dev/null +++ b/Tasks/Common/func-tools-common/functoolsutility.ts @@ -0,0 +1,78 @@ +"use strict"; + +import * as fs from 'fs'; +import * as os from 'os'; +import * as util from 'util'; +import * as tl from "azure-pipelines-task-lib/task"; +import * as toolLib from 'azure-pipelines-tool-lib/tool'; +import * as path from "path"; + +const funcToolName = 'func'; +const stableFuncToolsVersion = '2.7.1585'; + +function getExecutableExtension(): string { + if (os.type().match(/^Win/)) { + return '.exe'; + } + + return ''; +} + +function getDownloadUrl(version: string) { + let downloadUrlFormat = 'https://github.com/Azure/azure-functions-core-tools/releases/download/%s/Azure.Functions.Cli.%s.%s.zip'; + switch (os.type()) { + case 'Linux': + return util.format(downloadUrlFormat, version, 'linux-x64', version); + + case 'Darwin': + return util.format(downloadUrlFormat, version, 'osx-x64', version); + + case 'Windows_NT': + default: + return util.format(downloadUrlFormat, version, 'win-x86', version); + + } +} + +export async function getLatestFuncToolsVersion(): Promise { + const funcToolsLatestReleaseUrl = 'https://api.github.com/repos/Azure/azure-functions-core-tools/releases/latest'; + let latestVersion = stableFuncToolsVersion; + + try { + const downloadPath = await toolLib.downloadTool(funcToolsLatestReleaseUrl); + const response = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim()); + if (response.tag_name) { + latestVersion = response.tag_name; + } + } catch (error) { + tl.warning(tl.loc('ErrorFetchingLatestVersion', funcToolsLatestReleaseUrl, error, stableFuncToolsVersion)); + } + + return latestVersion; +} + +export async function downloadFuncTools(version: string): Promise { + let cachedToolpath = toolLib.findLocalTool(funcToolName, version); + + if (!cachedToolpath) { + const downloadUrl = getDownloadUrl(version); + let downloadPath; + try { + downloadPath = await toolLib.downloadTool(downloadUrl); + } + catch (ex) { + throw new Error(tl.loc('FuncDownloadFailed', downloadUrl, ex)); + } + + tl.debug('Extracting the downloaded func tool zip..'); + const unzippedFuncPath = await toolLib.extractZip(downloadPath); + cachedToolpath = await toolLib.cacheDir(unzippedFuncPath, funcToolName, version); + console.log(tl.loc("SuccessfullyDownloaded", version, cachedToolpath)); + } else { + console.log(tl.loc("VersionAlreadyInstalled", version, cachedToolpath)); + } + + const funcPath = path.join(cachedToolpath, funcToolName + getExecutableExtension()); + fs.chmodSync(funcPath, '777'); + return funcPath; +} \ No newline at end of file diff --git a/Tasks/Common/func-tools-common/package-lock.json b/Tasks/Common/func-tools-common/package-lock.json new file mode 100644 index 000000000000..64ca00b7b5f5 --- /dev/null +++ b/Tasks/Common/func-tools-common/package-lock.json @@ -0,0 +1,129 @@ +{ + "name": "func-tools-common", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/node": { + "version": "12.7.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.5.tgz", + "integrity": "sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w==" + }, + "@types/semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==" + }, + "@types/uuid": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.5.tgz", + "integrity": "sha512-MNL15wC3EKyw1VLF+RoVO4hJJdk9t/Hlv3rt1OL65Qvuadm4BYo6g9ZJQqoq7X8NBFSsQXgAujWciovh2lpVjA==", + "requires": { + "@types/node": "*" + } + }, + "azure-pipelines-task-lib": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/azure-pipelines-task-lib/-/azure-pipelines-task-lib-2.8.0.tgz", + "integrity": "sha512-PR8oap9z2j+o455W3PwAfB4SX1p4GdJc9OHQaQV0V+iQS1IBY6dVgcNSQMkHAXb0V1bbuLOFBLanXPe5eSgGTQ==", + "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" + } + }, + "azure-pipelines-tool-lib": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/azure-pipelines-tool-lib/-/azure-pipelines-tool-lib-0.12.0.tgz", + "integrity": "sha512-JAlFvMTtEXISrnJY/kgq0LecLi089RqXRf/gMsXYbflmzszklkc+LUJpR0A7NDmJ+9/MWpKY/ZX+Q/zirYa7gw==", + "requires": { + "@types/semver": "^5.3.0", + "@types/uuid": "^3.0.1", + "azure-pipelines-task-lib": "^2.8.0", + "semver": "^5.3.0", + "semver-compare": "^1.0.0", + "typed-rest-client": "1.0.9", + "uuid": "^3.0.1" + } + }, + "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.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "semver-compare": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", + "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=" + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=" + }, + "tunnel": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.4.tgz", + "integrity": "sha1-LTeFoVjBdMmhbcLARuxfxfF0IhM=" + }, + "typed-rest-client": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.0.9.tgz", + "integrity": "sha512-iOdwgmnP/tF6Qs+oY4iEtCf/3fnCDl7Gy9LGPJ4E3M4Wj3uaSko15FVwbsaBmnBqTJORnXBWVY5306D4HH8oiA==", + "requires": { + "tunnel": "0.0.4", + "underscore": "1.8.3" + } + }, + "underscore": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", + "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" + }, + "uuid": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", + "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" + } + } +} diff --git a/Tasks/Common/func-tools-common/package.json b/Tasks/Common/func-tools-common/package.json new file mode 100644 index 000000000000..d2011f4900ec --- /dev/null +++ b/Tasks/Common/func-tools-common/package.json @@ -0,0 +1,19 @@ +{ + "name": "func-tools-common", + "version": "1.0.0", + "description": "Common Library for Azure func tools", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/Microsoft/azure-pipelines-tasks.git" + }, + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Microsoft/azure-pipelines-tasks/issues" + }, + "homepage": "https://github.com/Microsoft/azure-pipelines-tasks#readme", + "dependencies": { + "azure-pipelines-task-lib": "2.8.0", + "azure-pipelines-tool-lib": "0.12.0" + } +} diff --git a/Tasks/Common/func-tools-common/tsconfig.json b/Tasks/Common/func-tools-common/tsconfig.json new file mode 100644 index 000000000000..bf3139d06f75 --- /dev/null +++ b/Tasks/Common/func-tools-common/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "declaration": true, + "noImplicitAny": false, + "sourceMap": false + } +} \ No newline at end of file diff --git a/Tasks/Common/func-tools-common/typings.json b/Tasks/Common/func-tools-common/typings.json new file mode 100644 index 000000000000..f47f6e298d90 --- /dev/null +++ b/Tasks/Common/func-tools-common/typings.json @@ -0,0 +1,5 @@ +{ + "globalDependencies": { + "node": "registry:dt/node#6.0.0+20160920093002" + } +} \ No newline at end of file diff --git a/Tasks/FuncToolsInstallerV0/Strings/resources.resjson/en-US/resources.resjson b/Tasks/FuncToolsInstallerV0/Strings/resources.resjson/en-US/resources.resjson new file mode 100644 index 000000000000..e5b886999c68 --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/Strings/resources.resjson/en-US/resources.resjson @@ -0,0 +1,16 @@ +{ + "loc.friendlyName": "Install Azure Func Core Tools", + "loc.helpMarkDown": "[Learn more about this task](https://aka.ms/func-tools-installer)", + "loc.description": "Install Azure Func Core Tools", + "loc.instanceNameFormat": "Install func tools - $(version)", + "loc.input.label.version": "Version", + "loc.input.help.version": "Specify the version of Azure func tools to install. Ex:

2.7.1575
v2.7.1575
latest", + "loc.messages.ErrorFetchingLatestVersion": "An error occured while fetching the latest version info from %s. Error: %s. Downloading default stable version: %s.", + "loc.messages.FindingLatestFuncToolsVersion": "Finding latest func tools version...", + "loc.messages.FuncDownloadFailed": "Failed to download func tools from location %s. Error %s.", + "loc.messages.LatestFuncToolsVersion": "Latest version is %s", + "loc.messages.NotAValidSemverVersion": "Version not specified in correct format. Ex: 2.7.1575, v2.7.1575, latest", + "loc.messages.SuccessfullyDownloaded": "Successfully downloaded func tools %s. Download path: %s.", + "loc.messages.VerifyingFuncToolsInstallation": "Verifying func tools installation...", + "loc.messages.VersionAlreadyInstalled": "Func tool version %s is already installed. Installation path: %s." +} \ No newline at end of file diff --git a/Tasks/FuncToolsInstallerV0/icon.png b/Tasks/FuncToolsInstallerV0/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..76a581b1090d318bb7481195ae1e7b301664cdcf GIT binary patch literal 1373 zcmV-j1)}Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf1oBBlK~z{r#g<)6 zn`IQo|Fn!j!EG?emTYF(U>I2>lrbtWHpR`2883FBPA`mZQDf8_HF}{&FZ@XKO2?cq zolb8IFytloj&4guB;{3prygKrL)_Va%c$ebJ4SPg7@-jtVNbq-8k1g_r)B->2cLZeO( zjRs5y6rZ!ySFe1uML*-iSwrLL+)W2$&8`Iksiw{q{|E5&)8HCY_AniiW94JT?*+D;F!e!f&$OZa zsdBhHeiZOb?<}JfM#vzV_Rqo2uurn88-tAtgRcU^?=c1IOt(k8=HO9`LdGth#MDTQ z%oE^XN-tn!>X`~JN^4uO)@nibGZn~4;k%jz2gFM$nkhQb_;_ikaiM2^>~gahmdPg* zP*M<(TF}NtmLp{}S4)SO#w4O8r(0mX7 z41O9&=K*PyQ@Ly$N;cL;DyLu)ry|e6p05|*CpqaUy!~D&SEIPaA;B`io9|((iPPUl zGA@j8^jh@f6H=|fIyw-%GTE9^XtSJzn~%`q{rcrao%rT4bwY&0+ z@DICvMs8xld1|pPT>SB2+YIbvn?~W#xlVKpOyJ80?KqO3W9UNWz`MUyOvF1y{}?z2Cs zEE;e6eN=0f67_^{uRGO7I&o)hP$X_%R;ruZE^&=76Comwi}B0-%NrL$Y9O40dD%Gs zaIw*|3yjwCTZ_*vj{+OYOkD&fIOQ%pQjE%N99B_?|7UqO=fW6geii#Z0Yr_!65I`p z0H5W3rknuci@>k@_?=J% + + + + + + + + + + + diff --git a/Tasks/FuncToolsInstallerV0/make.json b/Tasks/FuncToolsInstallerV0/make.json new file mode 100644 index 000000000000..ab5cc67fd73a --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/make.json @@ -0,0 +1,16 @@ +{ + "common": [{ + "module": "../Common/func-tools-common", + "type": "node", + "dest" : "./", + "compile" : true + }], + "rm": [ + { + "items": [ + "node_modules/func-tools-common/node_modules/azure-pipelines-task-lib" + ], + "options": "-Rf" + } + ] +} \ No newline at end of file diff --git a/Tasks/FuncToolsInstallerV0/package-lock.json b/Tasks/FuncToolsInstallerV0/package-lock.json new file mode 100644 index 000000000000..6028ff78f0d1 --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/package-lock.json @@ -0,0 +1,134 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "@types/node": { + "version": "6.14.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-6.14.7.tgz", + "integrity": "sha512-YbPXbaynBTe0pVExPhL76TsWnxSPeFAvImIsmylpBWn/yfw+lHy+Q68aawvZHsgskT44ZAoeE67GM5f+Brekew==" + }, + "@types/semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==" + }, + "@types/uuid": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.5.tgz", + "integrity": "sha512-MNL15wC3EKyw1VLF+RoVO4hJJdk9t/Hlv3rt1OL65Qvuadm4BYo6g9ZJQqoq7X8NBFSsQXgAujWciovh2lpVjA==", + "requires": { + "@types/node": "*" + } + }, + "azure-pipelines-task-lib": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/azure-pipelines-task-lib/-/azure-pipelines-task-lib-2.8.0.tgz", + "integrity": "sha512-PR8oap9z2j+o455W3PwAfB4SX1p4GdJc9OHQaQV0V+iQS1IBY6dVgcNSQMkHAXb0V1bbuLOFBLanXPe5eSgGTQ==", + "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" + } + }, + "azure-pipelines-tool-lib": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/azure-pipelines-tool-lib/-/azure-pipelines-tool-lib-0.12.0.tgz", + "integrity": "sha512-JAlFvMTtEXISrnJY/kgq0LecLi089RqXRf/gMsXYbflmzszklkc+LUJpR0A7NDmJ+9/MWpKY/ZX+Q/zirYa7gw==", + "requires": { + "@types/semver": "^5.3.0", + "@types/uuid": "^3.0.1", + "azure-pipelines-task-lib": "^2.8.0", + "semver": "^5.3.0", + "semver-compare": "^1.0.0", + "typed-rest-client": "1.0.9", + "uuid": "^3.0.1" + } + }, + "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=" + }, + "func-tools-common": { + "version": "file:../../_build/Tasks/Common/func-tools-common-1.0.0.tgz", + "requires": { + "azure-pipelines-task-lib": "2.8.0", + "azure-pipelines-tool-lib": "0.12.0" + } + }, + "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.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "semver-compare": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", + "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=" + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=" + }, + "tunnel": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.4.tgz", + "integrity": "sha1-LTeFoVjBdMmhbcLARuxfxfF0IhM=" + }, + "typed-rest-client": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.0.9.tgz", + "integrity": "sha512-iOdwgmnP/tF6Qs+oY4iEtCf/3fnCDl7Gy9LGPJ4E3M4Wj3uaSko15FVwbsaBmnBqTJORnXBWVY5306D4HH8oiA==", + "requires": { + "tunnel": "0.0.4", + "underscore": "1.8.3" + } + }, + "underscore": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", + "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" + }, + "uuid": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", + "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" + } + } +} \ No newline at end of file diff --git a/Tasks/FuncToolsInstallerV0/package.json b/Tasks/FuncToolsInstallerV0/package.json new file mode 100644 index 000000000000..efd7986c9f0d --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "azure-pipelines-task-lib": "2.8.0", + "azure-pipelines-tool-lib": "0.12.0", + "func-tools-common": "file:../../_build/Tasks/Common/func-tools-common-1.0.0.tgz" + } +} diff --git a/Tasks/FuncToolsInstallerV0/src/functoolsinstaller.ts b/Tasks/FuncToolsInstallerV0/src/functoolsinstaller.ts new file mode 100644 index 000000000000..7724456d2c4c --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/src/functoolsinstaller.ts @@ -0,0 +1,34 @@ +"use strict"; + +import * as tl from 'azure-pipelines-task-lib/task'; +import * as path from 'path'; +import * as toolLib from 'azure-pipelines-tool-lib/tool'; +import * as utils from './utils'; + +tl.setResourcePath(path.join(__dirname, '..', 'task.json')); + +async function downloadFuncTools() { + const version = await utils.getFuncToolsVersion(); + const funcToolsPath = await utils.downloadFuncTools(version); + + // prepend the tools path. instructs the agent to prepend for future tasks + if (!process.env['PATH'].startsWith(path.dirname(funcToolsPath))) { + toolLib.prependPath(path.dirname(funcToolsPath)); + } +} + +async function verifyFuncTools() { + console.log(tl.loc("VerifyingFuncToolsInstallation")); + const funcToolsPath = tl.which("func", true); + var func = tl.tool(funcToolsPath); + func.arg("--version"); + return func.exec(); +} + +downloadFuncTools() + .then(() => verifyFuncTools()) + .then(() => { + tl.setResult(tl.TaskResult.Succeeded, ""); + }).catch((error) => { + tl.setResult(tl.TaskResult.Failed, error) + }); \ No newline at end of file diff --git a/Tasks/FuncToolsInstallerV0/src/utils.ts b/Tasks/FuncToolsInstallerV0/src/utils.ts new file mode 100644 index 000000000000..702663923d5e --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/src/utils.ts @@ -0,0 +1,31 @@ +"use strict"; + +import * as tl from 'azure-pipelines-task-lib/task'; +import * as toolLib from 'azure-pipelines-tool-lib/tool'; +import * as functoolsutility from "func-tools-common/functoolsutility"; + +export async function getFuncToolsVersion(): Promise { + const version = tl.getInput("version"); + if (version && version !== "latest") { + return sanitizeVersionString(version); + } + + console.log(tl.loc("FindingLatestFuncToolsVersion")); + const latestVersion = await functoolsutility.getLatestFuncToolsVersion(); + console.log(tl.loc("LatestFuncToolsVersion", latestVersion)); + return latestVersion; +} + +export async function downloadFuncTools(version: string): Promise { + return await functoolsutility.downloadFuncTools(version); +} + +// handle user input scenerios +function sanitizeVersionString(inputVersion: string) : string{ + const version = toolLib.cleanVersion(inputVersion); + if(!version) { + throw new Error(tl.loc("NotAValidSemverVersion")); + } + + return version; +} \ No newline at end of file diff --git a/Tasks/FuncToolsInstallerV0/task.json b/Tasks/FuncToolsInstallerV0/task.json new file mode 100644 index 000000000000..00c6414c3b3c --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/task.json @@ -0,0 +1,50 @@ +{ + "id": "A22A6EB4-FE21-442E-ABCE-5B2B09CFECE3", + "name": "FuncToolsInstaller", + "friendlyName": "Install Azure Func Core Tools", + "description": "Install Azure Func Core Tools", + "helpUrl": "https://aka.ms/func-tools-installer", + "helpMarkDown": "[Learn more about this task](https://aka.ms/func-tools-installer)", + "category": "Tool", + "visibility": [ + "Build", + "Release" + ], + "author": "Microsoft Corporation", + "version": { + "Major": 0, + "Minor": 160, + "Patch": 0 + }, + "preview": true, + "demands": [], + "satisfies": [ + "Func" + ], + "groups": [], + "inputs": [ + { + "name": "version", + "label": "Version", + "type": "string", + "helpMarkDown": "Specify the version of Azure func tools to install. Ex:

2.7.1575
v2.7.1575
latest", + "defaultValue": "latest" + } + ], + "instanceNameFormat": "Install func tools - $(version)", + "execution": { + "Node": { + "target": "src/functoolsinstaller.js" + } + }, + "messages": { + "ErrorFetchingLatestVersion": "An error occured while fetching the latest version info from %s. Error: %s. Downloading default stable version: %s.", + "FindingLatestFuncToolsVersion": "Finding latest func tools version...", + "FuncDownloadFailed": "Failed to download func tools from location %s. Error %s.", + "LatestFuncToolsVersion": "Latest version is %s", + "NotAValidSemverVersion": "Version not specified in correct format. Ex: 2.7.1575, v2.7.1575, latest", + "SuccessfullyDownloaded": "Successfully downloaded func tools %s. Download path: %s.", + "VerifyingFuncToolsInstallation": "Verifying func tools installation...", + "VersionAlreadyInstalled": "Func tool version %s is already installed. Installation path: %s." + } +} diff --git a/Tasks/FuncToolsInstallerV0/task.loc.json b/Tasks/FuncToolsInstallerV0/task.loc.json new file mode 100644 index 000000000000..f911e346f7bb --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/task.loc.json @@ -0,0 +1,50 @@ +{ + "id": "A22A6EB4-FE21-442E-ABCE-5B2B09CFECE3", + "name": "FuncToolsInstaller", + "friendlyName": "ms-resource:loc.friendlyName", + "description": "ms-resource:loc.description", + "helpUrl": "https://aka.ms/func-tools-installer", + "helpMarkDown": "ms-resource:loc.helpMarkDown", + "category": "Tool", + "visibility": [ + "Build", + "Release" + ], + "author": "Microsoft Corporation", + "version": { + "Major": 0, + "Minor": 160, + "Patch": 0 + }, + "preview": true, + "demands": [], + "satisfies": [ + "Func" + ], + "groups": [], + "inputs": [ + { + "name": "version", + "label": "ms-resource:loc.input.label.version", + "type": "string", + "helpMarkDown": "ms-resource:loc.input.help.version", + "defaultValue": "latest" + } + ], + "instanceNameFormat": "ms-resource:loc.instanceNameFormat", + "execution": { + "Node": { + "target": "src/functoolsinstaller.js" + } + }, + "messages": { + "ErrorFetchingLatestVersion": "ms-resource:loc.messages.ErrorFetchingLatestVersion", + "FindingLatestFuncToolsVersion": "ms-resource:loc.messages.FindingLatestFuncToolsVersion", + "FuncDownloadFailed": "ms-resource:loc.messages.FuncDownloadFailed", + "LatestFuncToolsVersion": "ms-resource:loc.messages.LatestFuncToolsVersion", + "NotAValidSemverVersion": "ms-resource:loc.messages.NotAValidSemverVersion", + "SuccessfullyDownloaded": "ms-resource:loc.messages.SuccessfullyDownloaded", + "VerifyingFuncToolsInstallation": "ms-resource:loc.messages.VerifyingFuncToolsInstallation", + "VersionAlreadyInstalled": "ms-resource:loc.messages.VersionAlreadyInstalled" + } +} \ No newline at end of file diff --git a/Tasks/FuncToolsInstallerV0/tsconfig.json b/Tasks/FuncToolsInstallerV0/tsconfig.json new file mode 100644 index 000000000000..75c70c9e1748 --- /dev/null +++ b/Tasks/FuncToolsInstallerV0/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "commonjs", + "typeRoots": [ "node_modules/@types" ] + }, + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/make-options.json b/make-options.json index 27b252d265c8..75b5358c0a4f 100644 --- a/make-options.json +++ b/make-options.json @@ -80,6 +80,7 @@ "FileTransformV2", "FtpUploadV1", "FtpUploadV2", + "FuncToolsInstallerV0", "GitHubCommentV0", "GitHubReleaseV0", "GitHubReleaseV1",