diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 3af807c..05bf7d3 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -8,6 +8,7 @@ const toolDir = path.join(__dirname, 'runner', 'tools'); const tempDir = path.join(__dirname, 'runner', 'temp'); process.env['RUNNER_TOOL_CACHE'] = toolDir; +process.env['DOTNET_INSTALL_DIR'] = toolDir; process.env['RUNNER_TEMP'] = tempDir; import * as installer from '../src/installer'; @@ -30,7 +31,7 @@ describe('installer tests', () => { it('Acquires version of dotnet if no matching version is installed', async () => { await getDotnet('2.2.104'); - const dotnetDir = path.join(toolDir, 'dncs', '2.2.104', os.arch()); + const dotnetDir = path.join(toolDir); expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true); if (IS_WINDOWS) { @@ -59,20 +60,6 @@ describe('installer tests', () => { return; }); - it('Doesnt use version of dotnet that was only partially installed in cache', async () => { - const dotnetDir: string = path.join(toolDir, 'dncs', '251.0.0', os.arch()); - await io.mkdirP(dotnetDir); - let thrown = false; - try { - // This will throw if it doesn't find it in the cache (because no such version exists) - await getDotnet('251.0.0'); - } catch { - thrown = true; - } - expect(thrown).toBe(true); - return; - }); - it('Uses an up to date bash download script', async () => { var httpCallbackClient = new httpClient.HttpClient( 'setup-dotnet-test', diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts new file mode 100644 index 0000000..8820523 --- /dev/null +++ b/__tests__/setup-dotnet.test.ts @@ -0,0 +1,51 @@ +import io = require('@actions/io'); +import fs = require('fs'); +import os = require('os'); +import path = require('path'); +import httpClient = require('typed-rest-client/HttpClient'); + +const toolDir = path.join(__dirname, 'runner', 'tools'); +const tempDir = path.join(__dirname, 'runner', 'temp'); + +import * as setup from '../src/setup-dotnet'; + +const IS_WINDOWS = process.platform === 'win32'; + +describe('setup-dotnet tests', () => { + beforeAll(async () => { + process.env['RUNNER_TOOL_CACHE'] = toolDir; + process.env['DOTNET_INSTALL_DIR'] = toolDir; + process.env['RUNNER_TEMP'] = tempDir; + await io.rmRF(toolDir); + await io.rmRF(tempDir); + }); + + afterAll(async () => { + try { + await io.rmRF(path.join(process.cwd(), 'global.json')); + await io.rmRF(toolDir); + await io.rmRF(tempDir); + } catch { + console.log('Failed to remove test directories'); + } + }, 100000); + + it('Acquires version of dotnet if no matching version is installed', async () => { + const dotnetDir = path.join(toolDir, 'dncs', '2.2.105', os.arch()); + + const globalJsonPath = path.join(process.cwd(), 'global.json'); + const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "2.2.105"${os.EOL}}${os.EOL}}`; + if (!fs.existsSync(globalJsonPath)) { + fs.writeFileSync(globalJsonPath, jsonContents); + } + await setup.run(); + + expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true); + if (IS_WINDOWS) { + expect(fs.existsSync(path.join(dotnetDir, 'dotnet.exe'))).toBe(true); + } else { + expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true); + } + fs.unlinkSync(globalJsonPath); + }, 100000); +}); diff --git a/lib/installer.js b/lib/installer.js index 60f960d..87ec16b 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -23,7 +23,7 @@ const path = __importStar(require("path")); const semver = __importStar(require("semver")); const IS_WINDOWS = process.platform === 'win32'; class DotnetCoreInstaller { - constructor(version = "", jsonfile = "") { + constructor(version = '', jsonfile = '') { if (semver.valid(semver.clean(version) || '') == null) { throw 'Implicit version not permitted'; } diff --git a/lib/setup-dotnet.js b/lib/setup-dotnet.js index 477f94a..6ebbc20 100644 --- a/lib/setup-dotnet.js +++ b/lib/setup-dotnet.js @@ -50,4 +50,5 @@ function run() { } }); } +exports.run = run; run(); diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 08ab9c1..080cc48 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -3,7 +3,7 @@ import * as installer from './installer'; import * as fs from 'fs'; import * as path from 'path'; -async function run() { +export async function run() { try { // // Version is optional. If supplied, install / use from the tool cache