-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Added Azure Func Tools Installer task. #11348
Changes from 4 commits
198518e
38c5a26
22ebd5e
f60afb5
ad61648
4c8fae5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
||
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()) { | ||
thesattiraju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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'; | ||
const stableFuncToolsVersion = '2.7.1585'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: this can be moved outside the func There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
let latestVersion = stableFuncToolsVersion; | ||
|
||
try { | ||
const downloadPath = await toolLib.downloadTool(funcToolsLatestReleaseUrl); | ||
thesattiraju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); | ||
thesattiraju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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.
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" | ||
} | ||
} |
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"globalDependencies": { | ||
"node": "registry:dt/node#6.0.0+20160920093002" | ||
} | ||
} |
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." | ||
} |
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" | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any other task using this common module? If not you can keep it within the task itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping it in Common, as we support installation as a part of main task itself for other tasks (Kubernetes, Helm etc), and if the customers ask for it we will be doing the same for this as well.