Skip to content

Commit db362d7

Browse files
author
Danny McCormick
committed
Feedback
1 parent 3280df5 commit db362d7

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ node_modules/.bin
44
node_modules/typescript
55
node_modules/@types
66
node_modules/prettier
7-
__tests__/runner/*
7+
__tests__/runner/*
8+
global.json

__tests__/installer.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const tempDir = path.join(__dirname, 'runner', 'temp');
99

1010
process.env['RUNNER_TOOL_CACHE'] = toolDir;
1111
process.env['RUNNER_TEMP'] = tempDir;
12+
import * as setup from '../src/setup-dotnet';
1213
import * as installer from '../src/installer';
1314

1415
const IS_WINDOWS = process.platform === 'win32';
@@ -40,6 +41,25 @@ describe('installer tests', () => {
4041
}
4142
}, 100000);
4243

44+
it('Acquires version of dotnet if no matching version is installed', async () => {
45+
const dotnetDir = path.join(toolDir, 'dncs', '2.2.105', os.arch());
46+
47+
const globalJsonPath = path.join(process.cwd(), 'global.json');
48+
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "2.2.105"${os.EOL}}${os.EOL}}`
49+
if(!fs.existsSync(globalJsonPath)) {
50+
fs.writeFileSync(globalJsonPath, jsonContents);
51+
}
52+
await setup.run();
53+
54+
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
55+
if (IS_WINDOWS) {
56+
expect(fs.existsSync(path.join(dotnetDir, 'dotnet.exe'))).toBe(true);
57+
} else {
58+
expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true);
59+
}
60+
fs.unlinkSync(globalJsonPath);
61+
}, 100000);
62+
4363
it('Throws if no location contains correct dotnet version', async () => {
4464
let thrown = false;
4565
try {

lib/setup-dotnet.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function run() {
2929
let version = core.getInput('version');
3030
if (!version) {
3131
// Try to fall back to global.json
32+
core.debug('No version found, trying to find version from global.json');
3233
const globalJsonPath = path.join(process.cwd(), 'global.json');
3334
if (fs.existsSync(globalJsonPath)) {
3435
const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' }));
@@ -50,4 +51,5 @@ function run() {
5051
}
5152
});
5253
}
54+
exports.run = run;
5355
run();

src/setup-dotnet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import * as installer from './installer';
33
import * as fs from 'fs';
44
import * as path from 'path';
55

6-
async function run() {
6+
export async function run() {
77
try {
88
//
99
// Version is optional. If supplied, install / use from the tool cache
1010
// If not supplied then task is still used to setup proxy, auth, etc...
1111
//
12-
let version = core.getInput('version');
12+
let version: string = core.getInput('version');
1313
if (!version) {
1414
// Try to fall back to global.json
15+
core.debug('No version found, trying to find version from global.json');
1516
const globalJsonPath = path.join(process.cwd(), 'global.json');
1617
if (fs.existsSync(globalJsonPath)) {
1718
const globalJson = JSON.parse(

0 commit comments

Comments
 (0)