Skip to content

Commit

Permalink
Implement tool caching (#15)
Browse files Browse the repository at this point in the history
To avoid unnecessarily downloading the Augurk CLI from GitHub each and every time, the Augurk CLI Installer task now caches the tool on the build agent for later re-use. Especially in these trying times this can help with builds breaking due to availability issues of GitHub.

Fixes #6

+semver: minor
  • Loading branch information
Jonathan Mezach committed Apr 1, 2020
1 parent e258331 commit 159bb1a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 71 deletions.
43 changes: 25 additions & 18 deletions src/build-task/AugurkCLIInstaller/cli-installer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import * as taskLib from 'azure-pipelines-task-lib/task';
import * as toolLib from 'vsts-task-tool-lib/tool';
import * as toolLib from 'azure-pipelines-tool-lib/tool';
import * as fs from 'fs';
import * as path from 'path';

async function run() {
try {
// Get task inputs
const version: string = taskLib.getInput('version', true);
const version = taskLib.getInput('version', true);
if (!version) {
throw new Error("Version is required");
}

// Determine the correct path in the tools folder for the current platform
let platform: string;
Expand All @@ -24,27 +27,31 @@ async function run() {
throw new Error(`Unknown platform ${process.platform}`);
}

// Construct the download URL
const url = `https://github.com/Augurk/Augurk.CommandLine/releases/download/${version}/Augurk.CommandLine-${platform}-${version}.${extension}`;
// Check if the tool is already installed
let toolPath: string = toolLib.findLocalTool('augurk-cli', version, platform);
if (!toolPath) {
// Tool is not installed, so construct the download URL
const url = `https://github.com/Augurk/Augurk.CommandLine/releases/download/${version}/Augurk.CommandLine-${platform}-${version}.${extension}`;

// Download the NuGet package and extract it
const temp: string = await toolLib.downloadTool(url);
let extractRoot: string;
if (process.platform === 'win32') {
extractRoot = await toolLib.extractZip(temp);
} else if (process.platform === 'linux' ||
process.platform === 'darwin') {
extractRoot = await toolLib.extractTar(temp);
// Download the NuGet package and extract it
const temp: string = await toolLib.downloadTool(url);
let extractRoot: string;
if (process.platform === 'win32') {
extractRoot = await toolLib.extractZip(temp);
} else if (process.platform === 'linux' ||
process.platform === 'darwin') {
extractRoot = await toolLib.extractTar(temp);
} else {
throw new Error(`Unknown platform ${process.platform}`);
}

// HACK: Set executable permissions for everyone, otherwise we can't find it later
// This is a workaround for this bug: https://github.com/Microsoft/azure-pipelines-task-lib/issues/420
fs.chmodSync(path.join(extractRoot, 'augurk'), '0777');
} else {
throw new Error(`Unknown platform ${process.platform}`);
// Cache the tool
toolPath = extractRoot;
toolLib.cacheDir(toolPath, 'augurk-cli', version, platform);
}

// The Node binary is in the bin folder of the extracted directory
toolLib.prependPath(extractRoot);
toolLib.prependPath(toolPath);
}
catch (err) {
taskLib.setResult(taskLib.TaskResult.Failed, taskLib.loc('AugurkCLIInstallerFailed', err.message));
Expand Down
85 changes: 37 additions & 48 deletions src/build-task/AugurkCLIInstaller/package-lock.json

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

6 changes: 3 additions & 3 deletions src/build-task/AugurkCLIInstaller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
},
"homepage": "https://github.com/augurk/vsts-extension#readme",
"dependencies": {
"azure-pipelines-task-lib": "2.8.0",
"vsts-task-tool-lib": "^0.10.0"
"azure-pipelines-task-lib": "2.9.3",
"azure-pipelines-tool-lib": "^0.12.0"
},
"devDependencies": {
"@types/node": "^13.1.7",
"@types/node": "^13.9.8",
"@types/q": "^1.5.2"
}
}
4 changes: 2 additions & 2 deletions src/build-task/AugurkCLIInstaller/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"author": "Augurk",
"version": {
"Major": 0,
"Minor": 1,
"Patch": 7
"Minor": 2,
"Patch": 0
},
"capabilities": [
"augurk-cli"
Expand Down

0 comments on commit 159bb1a

Please sign in to comment.