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

Added Azure Func Tools Installer task. #11348

Merged
merged 6 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
78 changes: 78 additions & 0 deletions Tasks/Common/func-tools-common/functoolsutility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"use strict";
Copy link
Contributor

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

Copy link
Contributor Author

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.


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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: this can be moved outside the func

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
129 changes: 129 additions & 0 deletions Tasks/Common/func-tools-common/package-lock.json

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

19 changes: 19 additions & 0 deletions Tasks/Common/func-tools-common/package.json
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"
}
}
9 changes: 9 additions & 0 deletions Tasks/Common/func-tools-common/tsconfig.json
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
}
}
5 changes: 5 additions & 0 deletions Tasks/Common/func-tools-common/typings.json
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."
}
Binary file added Tasks/FuncToolsInstallerV0/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Tasks/FuncToolsInstallerV0/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions Tasks/FuncToolsInstallerV0/make.json
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"
}
]
}
Loading