Skip to content

Commit

Permalink
Added Azure Func Tools Installer task. (#11348)
Browse files Browse the repository at this point in the history
* 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
ajinkya599 authored and leantk committed Dec 23, 2019
1 parent b45e2f9 commit 1bbe18c
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 0 deletions.
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";

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;
}
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

0 comments on commit 1bbe18c

Please sign in to comment.