-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
b45e2f9
commit 1bbe18c
Showing
17 changed files
with
601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> { | ||
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<string> { | ||
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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://[email protected]/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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"declaration": true, | ||
"noImplicitAny": false, | ||
"sourceMap": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"globalDependencies": { | ||
"node": "registry:dt/node#6.0.0+20160920093002" | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Tasks/FuncToolsInstallerV0/Strings/resources.resjson/en-US/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:<br><br>2.7.1575<br>v2.7.1575<br>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." | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] | ||
} |
Oops, something went wrong.