Skip to content

Commit

Permalink
feat: Updated CLI installer - v6 (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
slewis74 authored Jan 22, 2023
1 parent 696e175 commit 858c2b2
Show file tree
Hide file tree
Showing 15 changed files with 583 additions and 30 deletions.
33 changes: 14 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ on:
required: true

env:
PACKAGE_VERSION: 5.2.${{ github.run_number }}
OCTOPUS_CLI_SERVER: ${{ secrets.OCTOPUS_URL }}
OCTOPUS_CLI_API_KEY: ${{ secrets.INTEGRATIONS_API_KEY }}
PACKAGE_VERSION: 6.0.${{ github.run_number }}
OCTOPUS_URL: ${{ secrets.OCTOPUS_URL }}
OCTOPUS_API_KEY: ${{ secrets.INTEGRATIONS_API_KEY }}

jobs:
build:
Expand All @@ -32,9 +32,9 @@ jobs:
outputs:
package_version: ${{ steps.build.outputs.package_version }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "16"
cache: "npm"
Expand All @@ -45,7 +45,7 @@ jobs:
npm ci
npm run build -- --extensionVersion $PACKAGE_VERSION
echo "::set-output name=package_version::$PACKAGE_VERSION"
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
Expand All @@ -62,9 +62,9 @@ jobs:
matrix:
os: [windows-2022, ubuntu-20.04, macos-11]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "16"
cache: "npm"
Expand All @@ -88,21 +88,21 @@ jobs:
if: github.event_name == 'release' || (github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]')
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
with:
name: dist
path: dist

- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "16"
cache: "npm"

- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: "^1.17.7"
go-version: "^1.19.5"

- name: Embed octo portable
run: |
Expand All @@ -120,13 +120,8 @@ jobs:
tar -czf OctoTFS.vsix.${{ needs.build.outputs.package_version }}.tar.gz ./Artifacts/**/*.vsix
tar -czf OctoTFS.publish.${{ needs.build.outputs.package_version }}.tar.gz ./publish.ps1 ./dist/extension-manifest*.json
- name: Install Octopus CLI 🐙
uses: OctopusDeploy/[email protected]
with:
version: "*"

- name: Push Package 🐙
uses: OctopusDeploy/push-package-action@v1.1.2
uses: OctopusDeploy/push-package-action@v3
with:
space: "Integrations"
packages: |
Expand All @@ -143,7 +138,7 @@ jobs:
echo "::set-output name=release-note-file::$OUTPUT_FILE"
- name: Create a release in Octopus Deploy 🐙
uses: OctopusDeploy/create-release-action@v1.1.1
uses: OctopusDeploy/create-release-action@v3
with:
space: "Integrations"
project: "Azure DevOps Extension"
Expand Down
Binary file modified source/img/octopus_installer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface Endpoint {
export class DownloadEndpointRetriever {
private osPlat: string = os.platform();

constructor(readonly octopusUrl: string) {}
constructor(readonly octopurlsUrl: string) {}

public async getEndpoint(versionSpec: string): Promise<Endpoint> {
const octopurls = this.restClient();
Expand All @@ -48,7 +48,7 @@ export class DownloadEndpointRetriever {

const version = new OctopusCLIVersionFetcher(versionsResponse.result.versions).getVersion(versionSpec);

tasks.debug(`Attempting to contact ${this.octopusUrl} to find Octopus CLI tool version ${version}`);
tasks.debug(`Attempting to contact ${this.octopurlsUrl} to find Octopus CLI tool version ${version}`);

const response = await octopurls.get<LatestResponse>("LatestTools");

Expand Down Expand Up @@ -79,7 +79,7 @@ export class DownloadEndpointRetriever {
}

private restClient() {
const proxyConfiguration = tasks.getHttpProxyConfiguration(this.octopusUrl);
const proxyConfiguration = tasks.getHttpProxyConfiguration(this.octopurlsUrl);
let proxySettings: IProxyConfiguration | undefined = undefined;

if (proxyConfiguration) {
Expand All @@ -94,7 +94,7 @@ export class DownloadEndpointRetriever {
};
}

return new TypedRestClient.RestClient("OctoTFS/Tasks", this.octopusUrl, undefined, { proxy: proxySettings });
return new TypedRestClient.RestClient("OctoTFS/Tasks", this.octopurlsUrl, undefined, { proxy: proxySettings });
}

private applyTemplate(dictionary: Dictionary, template: string) {
Expand Down
6 changes: 3 additions & 3 deletions source/tasks/OctoInstaller/OctoInstallerV5/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import * as tasks from "azure-pipelines-task-lib";
import os from "os";
import path from "path";
import { executeWithSetResult } from "../../Utils/octopusTasks";
import { DownloadEndpointRetriever, Endpoint } from "./downloadVersion";
import { DownloadEndpointRetriever, Endpoint } from "./downloadEndpointRetriever";

const TOOL_NAME = "octo";

const osPlat: string = os.platform();

export class Installer {
constructor(readonly octopusUrl: string) {}
constructor(readonly octopurlsUrl: string) {}

public async run(versionSpec: string) {
await executeWithSetResult(
async () => {
const endpoint = await new DownloadEndpointRetriever(this.octopusUrl).getEndpoint(versionSpec);
const endpoint = await new DownloadEndpointRetriever(this.octopurlsUrl).getEndpoint(versionSpec);
let toolPath = tools.findLocalTool(TOOL_NAME, endpoint.version);

if (!toolPath) {
Expand Down
4 changes: 2 additions & 2 deletions source/tasks/OctoInstaller/OctoInstallerV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"id": "57342b23-3a76-490a-8e78-25d4ade2f2e3",
"name": "OctoInstaller",
"friendlyName": "Octopus CLI Installer",
"description": "Install a specific version of the Octopus CLI",
"helpMarkDown": "Install a specific version of the Octopus CLI",
"description": "Install a specific version of the Octopus CLI (C#)",
"helpMarkDown": "Install a specific version of the Octopus CLI (C#)",
"category": "Tool",
"runsOn": [
"Agent",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { DownloadEndpointRetriever } from "./downloadEndpointRetriever";
import { mkdtemp, rm } from "fs/promises";
import * as path from "path";
import os from "os";
import express from "express";
import { Server } from "http";
import { AddressInfo } from "net";
import { Logger } from "@octopusdeploy/api-client";

describe("OctopusInstaller", () => {
let tempOutDir: string;
let releasesUrl: string;
let server: Server;

const msgs: string[] = [];
const logger: Logger = {
debug: (message) => {
msgs.push(message);
},
info: (message) => {
msgs.push(message);
},
warn: (message) => {
msgs.push(message);
},
error: (message, err) => {
if (err !== undefined) {
msgs.push(err.message);
} else {
msgs.push(message);
}
},
};

jest.setTimeout(100000);

beforeEach(async () => {
tempOutDir = await mkdtemp(path.join(os.tmpdir(), "octopus_"));
process.env["AGENT_TOOLSDIRECTORY"] = tempOutDir;
process.env["AGENT_TEMPDIRECTORY"] = tempOutDir;

const app = express();

app.get("/repos/OctopusDeploy/cli/releases", (_, res) => {
const latestToolsPayload = `[
{
"tag_name": "v7.4.1",
"assets": [
{
"name": "octopus_7.4.1_windows_amd64.zip",
"browser_download_url": "http://localhost:${address.port}/OctopusDeploy/cli/releases/download/v7.4.1/octopus_7.4.1_windows_amd64.zip"
}
]
},
{
"tag_name": "v8.0.0",
"assets": [
{
"name": "octopus_8.0.0_windows_amd64.zip",
"browser_download_url": "http://localhost:${address.port}/OctopusDeploy/cli/releases/download/v8.0.0/octopus_8.0.0_windows_amd64.zip"
}
]
},
{
"tag_name": "v8.2.0",
"assets": [
{
"name": "octopus_8.2.0_windows_amd64.zip",
"browser_download_url": "http://localhost:${address.port}/OctopusDeploy/cli/releases/download/v8.2.0/octopus_8.2.0_windows_amd64.zip"
}
]
}
]`;

res.send(latestToolsPayload);
});

app.get("/OctopusDeploy/cli/releases/download/v7.4.1/octopus_7.4.1_windows_amd64.zip", (_, res) => {
res.statusCode = 200;
});

app.get("/OctopusDeploy/cli/releases/download/v8.0.0/octopus_8.0.0_windows_amd64.zip", (_, res) => {
res.statusCode = 200;
});

app.get("/OctopusDeploy/cli/releases/download/v8.2.0/octopus_8.2.0_windows_amd64.zip", (_, res) => {
res.statusCode = 200;
});

server = await new Promise<Server>((resolve) => {
const r = app.listen(() => {
resolve(r);
});
});

const address = server.address() as AddressInfo;
releasesUrl = `http://localhost:${address.port}/repos/OctopusDeploy/cli/releases`;
});

afterEach(async () => {
await new Promise<void>((resolve) => {
server.close(() => {
resolve();
});
});

await rm(tempOutDir, { recursive: true });
});

test("Installs specific version", async () => {
const result = await new DownloadEndpointRetriever(releasesUrl, "win32", "amd64", logger).getEndpoint("8.0.0");
expect(result.version).toBe("8.0.0");
});

test("Installs wildcard version", async () => {
const result = await new DownloadEndpointRetriever(releasesUrl, "win32", "amd64", logger).getEndpoint("7.*");
expect(result.version).toBe("7.4.1");
});

test("Installs latest of latest", async () => {
const result = await new DownloadEndpointRetriever(releasesUrl, "win32", "amd64", logger).getEndpoint("*");
expect(result.version).toBe("8.2.0");
});
});
Loading

0 comments on commit 858c2b2

Please sign in to comment.