Skip to content

Commit

Permalink
Disables the .NET Core telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ecampidoglio committed Oct 25, 2019
1 parent 783a6e3 commit b01aabb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __tests__/dotnet.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import * as core from '@actions/core';
import { exec } from "@actions/exec";
import { DotNet } from '../src/dotnet';
import { ToolsDirectory } from "../src/toolsDirectory";

jest.mock('@actions/core');
jest.mock('@actions/exec');

describe('When disabling the .NET Core telemetry', () => {
const fakeExportVariable = core.exportVariable as jest.MockedFunction<typeof core.exportVariable>;

test('it should set the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1', () => {
DotNet.disableTelemetry();
expect(fakeExportVariable).toBeCalledWith('DOTNET_CLI_TELEMETRY_OPTOUT', '1');
});
});

describe('When successfully installing the Cake Tool locally', () => {
const fakeExec = exec as jest.MockedFunction<typeof exec>;

Expand Down
5 changes: 5 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ describe('When running the action without any input arguments', () => {
expect(fakeToolsDirectory.prototype.create).toBeCalled();
});

test('it should disable the .NET Core telemetry', async () => {
await run();
expect(fakeDotNet.disableTelemetry).toBeCalled();
});

test('it should install the Cake tool locally', async () => {
await run();
expect(fakeDotNet.installLocalCakeTool).toBeCalled();
Expand Down
11 changes: 11 additions & 0 deletions lib/dotnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec_1 = require("@actions/exec");
const toolsDirectory_1 = require("./toolsDirectory");
const dotnetToolInstall = 'dotnet tool install';
class DotNet {
static disableTelemetry() {
core.exportVariable('DOTNET_CLI_TELEMETRY_OPTOUT', '1');
}
static installLocalCakeTool(targetDirectory = new toolsDirectory_1.ToolsDirectory()) {
return __awaiter(this, void 0, void 0, function* () {
return DotNet.installLocalTool('Cake.Tool', targetDirectory);
Expand Down
1 change: 1 addition & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function run() {
const target = new cakeParameter_1.CakeArgument('target', core.getInput('target'));
const toolsDir = new toolsDirectory_1.ToolsDirectory();
yield toolsDir.create();
dotnet_1.DotNet.disableTelemetry();
yield dotnet_1.DotNet.installLocalCakeTool(toolsDir);
yield cake_1.CakeTool.runScript(scriptPath, toolsDir, target);
}
Expand Down
5 changes: 5 additions & 0 deletions src/dotnet.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as core from '@actions/core';
import { exec } from "@actions/exec";
import { ToolsDirectory } from "./toolsDirectory";

const dotnetToolInstall = 'dotnet tool install';

export class DotNet {
static disableTelemetry() {
core.exportVariable('DOTNET_CLI_TELEMETRY_OPTOUT', '1');
}

static async installLocalCakeTool(targetDirectory: ToolsDirectory = new ToolsDirectory()) {
return DotNet.installLocalTool('Cake.Tool', targetDirectory);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export async function run() {
const toolsDir = new ToolsDirectory();
await toolsDir.create();

DotNet.disableTelemetry();

await DotNet.installLocalCakeTool(toolsDir);
await CakeTool.runScript(scriptPath, toolsDir, target);
} catch (error) {
Expand Down

0 comments on commit b01aabb

Please sign in to comment.