This commit is contained in:
Danny McCormick 2019-08-12 12:14:43 -04:00
parent 3280df5864
commit db362d751e
4 changed files with 27 additions and 3 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ node_modules/.bin
node_modules/typescript node_modules/typescript
node_modules/@types node_modules/@types
node_modules/prettier node_modules/prettier
__tests__/runner/* __tests__/runner/*
global.json

View File

@ -9,6 +9,7 @@ const tempDir = path.join(__dirname, 'runner', 'temp');
process.env['RUNNER_TOOL_CACHE'] = toolDir; process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir; process.env['RUNNER_TEMP'] = tempDir;
import * as setup from '../src/setup-dotnet';
import * as installer from '../src/installer'; import * as installer from '../src/installer';
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
@ -40,6 +41,25 @@ describe('installer tests', () => {
} }
}, 100000); }, 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 () => { it('Throws if no location contains correct dotnet version', async () => {
let thrown = false; let thrown = false;
try { try {

View File

@ -29,6 +29,7 @@ function run() {
let version = core.getInput('version'); let version = core.getInput('version');
if (!version) { if (!version) {
// Try to fall back to global.json // 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'); const globalJsonPath = path.join(process.cwd(), 'global.json');
if (fs.existsSync(globalJsonPath)) { if (fs.existsSync(globalJsonPath)) {
const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' })); const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' }));
@ -50,4 +51,5 @@ function run() {
} }
}); });
} }
exports.run = run;
run(); run();

View File

@ -3,15 +3,16 @@ import * as installer from './installer';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
async function run() { export async function run() {
try { try {
// //
// Version is optional. If supplied, install / use from the tool cache // Version is optional. If supplied, install / use from the tool cache
// If not supplied then task is still used to setup proxy, auth, etc... // 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) { if (!version) {
// Try to fall back to global.json // 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'); const globalJsonPath = path.join(process.cwd(), 'global.json');
if (fs.existsSync(globalJsonPath)) { if (fs.existsSync(globalJsonPath)) {
const globalJson = JSON.parse( const globalJson = JSON.parse(