Skip to content

Commit 1d9f0da

Browse files
Accept absolute paths for 'global-json-file' input (actions#396)
1 parent 2699274 commit 1d9f0da

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

Diff for: __tests__/setup-dotnet.test.ts

+26-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ if (IS_WINDOWS) {
1818
toolDir = path.join(process.env['HOME'] + '', '.dotnet');
1919
}
2020

21+
function createGlobalJsonPath(dotnetVersion: string) {
22+
const globalJsonPath = path.join(process.cwd(), 'global.json');
23+
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "${dotnetVersion}"${os.EOL}}${os.EOL}}`;
24+
if (!fs.existsSync(globalJsonPath)) {
25+
fs.writeFileSync(globalJsonPath, jsonContents);
26+
}
27+
return globalJsonPath;
28+
}
29+
2130
const tempDir = path.join(__dirname, 'runner', 'temp2');
2231

2332
describe('setup-dotnet tests', () => {
@@ -52,11 +61,7 @@ describe('setup-dotnet tests', () => {
5261
}, 30000);
5362

5463
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
55-
const globalJsonPath = path.join(process.cwd(), 'global.json');
56-
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
57-
if (!fs.existsSync(globalJsonPath)) {
58-
fs.writeFileSync(globalJsonPath, jsonContents);
59-
}
64+
createGlobalJsonPath('3.1.201');
6065
await setup.run();
6166

6267
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
@@ -78,11 +83,7 @@ describe('setup-dotnet tests', () => {
7883
}, 400000);
7984

8085
it("Sets output with the version specified in global.json, if it's present", async () => {
81-
const globalJsonPath = path.join(process.cwd(), 'global.json');
82-
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.0.103"${os.EOL}}${os.EOL}}`;
83-
if (!fs.existsSync(globalJsonPath)) {
84-
fs.writeFileSync(globalJsonPath, jsonContents);
85-
}
86+
createGlobalJsonPath('3.0.103');
8687

8788
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
8889
inputs['global-json-file'] = './global.json';
@@ -95,4 +96,19 @@ describe('setup-dotnet tests', () => {
9596

9697
expect(setOutputSpy).toHaveBeenCalledWith('dotnet-version', '3.0.103');
9798
}, 400000);
99+
100+
it('Sets output with the version specified in global.json with absolute path', async () => {
101+
const globalJsonPath = createGlobalJsonPath('3.0.103');
102+
103+
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
104+
inputs['global-json-file'] = globalJsonPath;
105+
106+
getMultilineInputSpy.mockImplementation(input => inputs[input]);
107+
108+
getInputSpy.mockImplementation(input => inputs[input]);
109+
110+
await setup.run();
111+
112+
expect(setOutputSpy).toHaveBeenCalledWith('dotnet-version', '3.0.103');
113+
}, 400000);
98114
});

Diff for: dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ function run() {
513513
const installedDotnetVersions = [];
514514
const globalJsonFileInput = core.getInput('global-json-file');
515515
if (globalJsonFileInput) {
516-
const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput);
516+
const globalJsonPath = path_1.default.resolve(process.cwd(), globalJsonFileInput);
517517
if (!fs.existsSync(globalJsonPath)) {
518518
throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`);
519519
}

Diff for: src/setup-dotnet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function run() {
3131

3232
const globalJsonFileInput = core.getInput('global-json-file');
3333
if (globalJsonFileInput) {
34-
const globalJsonPath = path.join(process.cwd(), globalJsonFileInput);
34+
const globalJsonPath = path.resolve(process.cwd(), globalJsonFileInput);
3535
if (!fs.existsSync(globalJsonPath)) {
3636
throw new Error(
3737
`The specified global.json file '${globalJsonFileInput}' does not exist`

0 commit comments

Comments
 (0)