From db362d751e446086a55d0e3da952eb4c0d748f8c Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Mon, 12 Aug 2019 12:14:43 -0400 Subject: [PATCH] Feedback --- .gitignore | 3 ++- __tests__/installer.test.ts | 20 ++++++++++++++++++++ lib/setup-dotnet.js | 2 ++ src/setup-dotnet.ts | 5 +++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0d8c6d3..8e5fc3e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules/.bin node_modules/typescript node_modules/@types node_modules/prettier -__tests__/runner/* \ No newline at end of file +__tests__/runner/* +global.json \ No newline at end of file diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index e0fb18d..855ef5d 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -9,6 +9,7 @@ const tempDir = path.join(__dirname, 'runner', 'temp'); process.env['RUNNER_TOOL_CACHE'] = toolDir; process.env['RUNNER_TEMP'] = tempDir; +import * as setup from '../src/setup-dotnet'; import * as installer from '../src/installer'; const IS_WINDOWS = process.platform === 'win32'; @@ -40,6 +41,25 @@ describe('installer tests', () => { } }, 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); + it('Throws if no location contains correct dotnet version', async () => { let thrown = false; try { diff --git a/lib/setup-dotnet.js b/lib/setup-dotnet.js index f49fd89..0eda2a6 100644 --- a/lib/setup-dotnet.js +++ b/lib/setup-dotnet.js @@ -29,6 +29,7 @@ function run() { let version = core.getInput('version'); if (!version) { // Try to fall back to global.json + core.debug('No version found, trying to find version from global.json'); const globalJsonPath = path.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' })); @@ -50,4 +51,5 @@ function run() { } }); } +exports.run = run; run(); diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 54da1f6..515dad6 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -3,15 +3,16 @@ 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 // If not supplied then task is still used to setup proxy, auth, etc... // - let version = core.getInput('version'); + let version: string = core.getInput('version'); if (!version) { // Try to fall back to global.json + core.debug('No version found, trying to find version from global.json'); const globalJsonPath = path.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { const globalJson = JSON.parse(