Skip to content

Commit adb6b7c

Browse files
committed
Octo Installer task
1 parent e0a666b commit adb6b7c

File tree

9 files changed

+438
-0
lines changed

9 files changed

+438
-0
lines changed
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
Object.defineProperty(exports, "__esModule", { value: true });
11+
const tasks = require("vsts-task-lib/task");
12+
const tools = require("vsts-task-tool-lib/tool");
13+
const RestClient_1 = require("typed-rest-client/RestClient");
14+
const os = require("os");
15+
const fs = require("fs");
16+
const path = require("path");
17+
//https://download.octopusdeploy.com/octopus-tools/4.35.0/OctopusTools.4.35.0.portable.zip
18+
//https://download.octopusdeploy.com/octopus-tools/4.35.0/OctopusTools.4.35.0.portable.tar.gz
19+
const toolName = "Octo";
20+
var github = new RestClient_1.RestClient("OctoTFS/OctoInstaller", "https://api.github.com");
21+
const octoLatestReleaseUrl = "https://api.github.com/repos/OctopusDeploy/OctopusClients/releases/latest";
22+
const downloadUrl = (version) => `https://download.octopusdeploy.com/octopus-tools/${version}/OctopusTools.${version}.portable.tar.gz`;
23+
const resolveVersion = (version) => __awaiter(this, void 0, void 0, function* () {
24+
if (!version || version.toLowerCase() === "latest") {
25+
return github.get("repos/OctopusDeploy/OctopusClients/releases/latest").then(x => x.result.tag_name);
26+
}
27+
return Promise.resolve(version);
28+
});
29+
function getLocalTool(version) {
30+
console.log("Checking local tool cache");
31+
return tools.findLocalTool(toolName, version);
32+
}
33+
function run() {
34+
return __awaiter(this, void 0, void 0, function* () {
35+
let version = yield resolveVersion(tasks.getInput("version"));
36+
let toolPath = yield download(version);
37+
if (!process.env['PATH'].startsWith(path.dirname(toolPath))) {
38+
tools.prependPath(path.dirname(toolPath));
39+
}
40+
});
41+
}
42+
function download(version) {
43+
return __awaiter(this, void 0, void 0, function* () {
44+
var cachedToolPath = getLocalTool(version);
45+
if (!cachedToolPath) {
46+
try {
47+
let downloadPath = yield tools.downloadTool(downloadUrl(version));
48+
let unzippedPath = yield tools.extractTar(downloadPath);
49+
cachedToolPath = yield tools.cacheDir(unzippedPath, toolName, version);
50+
}
51+
catch (exception) {
52+
throw new Error(`Failed to download octo tools from ${downloadUrl(version)}`);
53+
}
54+
}
55+
const octoPath = findOcto(cachedToolPath);
56+
if (!octoPath) {
57+
throw new Error("Octo wasn't found in tools directory");
58+
}
59+
fs.chmod(octoPath, "777");
60+
return octoPath;
61+
});
62+
}
63+
function findOcto(rootFolder) {
64+
var octoPath = path.join(rootFolder, "*" + toolName + ".dll");
65+
console.log(`Looking for ${octoPath}`);
66+
var allPaths = tasks.find(rootFolder);
67+
var matches = tasks.match(allPaths, octoPath, rootFolder);
68+
console.log(matches);
69+
return matches[0];
70+
}
71+
function getExecutableExtention() {
72+
return os.type().match(/^Win/) ? ".exe" : "";
73+
}
74+
function getTempDirectory() {
75+
return tasks.getVariable('agent.tempDirectory') || os.tmpdir();
76+
}
77+
run().then(() => {
78+
tasks.setResult(tasks.TaskResult.Succeeded, "");
79+
}, (reason) => {
80+
tasks.setResult(tasks.TaskResult.Failed, reason);
81+
}).catch((error) => {
82+
tasks.setResult(tasks.TaskResult.Failed, error);
83+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import * as tasks from 'vsts-task-lib/task';
2+
import * as tools from 'vsts-task-tool-lib/tool';
3+
import { ToolRunner } from "vsts-task-lib/toolrunner";
4+
import { RestClient } from "typed-rest-client/RestClient";
5+
import * as os from "os";
6+
import * as fs from "fs";
7+
import * as path from "path";
8+
9+
interface LatestResponse{
10+
"tag_name":string;
11+
}
12+
13+
//https://download.octopusdeploy.com/octopus-tools/4.35.0/OctopusTools.4.35.0.portable.zip
14+
//https://download.octopusdeploy.com/octopus-tools/4.35.0/OctopusTools.4.35.0.portable.tar.gz
15+
const toolName = "Octo";
16+
17+
var github = new RestClient("OctoTFS/OctoInstaller", "https://api.github.com");
18+
const octoLatestReleaseUrl = "https://api.github.com/repos/OctopusDeploy/OctopusClients/releases/latest";
19+
20+
const downloadUrl = (version:string) => `https://download.octopusdeploy.com/octopus-tools/${version}/OctopusTools.${version}.portable.tar.gz`;
21+
22+
const resolveVersion = async (version: string) => {
23+
if(!version || version.toLowerCase() === "latest"){
24+
return github.get<LatestResponse>("repos/OctopusDeploy/OctopusClients/releases/latest").then(x => x.result.tag_name);
25+
}
26+
return Promise.resolve(version);
27+
}
28+
29+
function getLocalTool(version:string): string {
30+
console.log("Checking local tool cache");
31+
return tools.findLocalTool(toolName, version);
32+
}
33+
34+
async function run(){
35+
let version = await resolveVersion(tasks.getInput("version"));
36+
let toolPath = await download(version);
37+
38+
if(!process.env['PATH'].startsWith(path.dirname(toolPath))){
39+
tools.prependPath(path.dirname(toolPath));
40+
}
41+
}
42+
43+
async function download(version: string): Promise<string>{
44+
var cachedToolPath = getLocalTool(version);
45+
46+
if(!cachedToolPath){
47+
try{
48+
let downloadPath = await tools.downloadTool(downloadUrl(version));
49+
let unzippedPath = await tools.extractTar(downloadPath);
50+
cachedToolPath = await tools.cacheDir(unzippedPath, toolName, version);
51+
52+
}catch(exception){
53+
throw new Error(`Failed to download octo tools from ${downloadUrl(version)}`)
54+
}
55+
}
56+
57+
const octoPath = findOcto(cachedToolPath);
58+
if(!octoPath){
59+
throw new Error("Octo wasn't found in tools directory")
60+
}
61+
62+
fs.chmod(octoPath, "777");
63+
return octoPath;
64+
}
65+
66+
function findOcto(rootFolder){
67+
var octoPath = path.join(rootFolder, "*" + toolName + ".dll");
68+
console.log(`Looking for ${octoPath}`);
69+
var allPaths = tasks.find(rootFolder);
70+
var matches = tasks.match(allPaths, octoPath, rootFolder);
71+
console.log(matches);
72+
return matches[0];
73+
}
74+
75+
function getExecutableExtention(): string {
76+
return os.type().match(/^Win/) ? ".exe" : "";
77+
}
78+
79+
function getTempDirectory(): string {
80+
return tasks.getVariable('agent.tempDirectory') || os.tmpdir();
81+
}
82+
83+
run().then(() => {
84+
tasks.setResult(tasks.TaskResult.Succeeded, "")
85+
}, (reason) => {
86+
tasks.setResult(tasks.TaskResult.Failed, reason)
87+
}).catch((error) => {
88+
tasks.setResult(tasks.TaskResult.Failed, error)
89+
});

source/VSTSExtensions/OctopusBuildAndReleaseTasks/Tasks/OctoInstaller/package-lock.json

+174
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "octoinstaller",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "octoinstaller.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT",
11+
"dependencies": {
12+
"typed-rest-client": "^1.0.7",
13+
"vso-node-api": "^6.5.0",
14+
"vsts-task-lib": "^2.4.0",
15+
"vsts-task-tool-lib": "^0.8.1"
16+
},
17+
"devDependencies": {
18+
"@types/node": "^6.0.108"
19+
},
20+
"bugs": {
21+
"url": "https://github.com/OctopusDeploy/OctopusClients/issues"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "[email protected]:OctopusDeploy/OctopusClients.git"
26+
}
27+
}

0 commit comments

Comments
 (0)