mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-22 03:21:08 +07:00
Accept absolute paths for 'global-json-file' input (#396)
This commit is contained in:
parent
2699274f6e
commit
1d9f0dad5b
@ -18,6 +18,15 @@ if (IS_WINDOWS) {
|
|||||||
toolDir = path.join(process.env['HOME'] + '', '.dotnet');
|
toolDir = path.join(process.env['HOME'] + '', '.dotnet');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createGlobalJsonPath(dotnetVersion: string) {
|
||||||
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
|
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "${dotnetVersion}"${os.EOL}}${os.EOL}}`;
|
||||||
|
if (!fs.existsSync(globalJsonPath)) {
|
||||||
|
fs.writeFileSync(globalJsonPath, jsonContents);
|
||||||
|
}
|
||||||
|
return globalJsonPath;
|
||||||
|
}
|
||||||
|
|
||||||
const tempDir = path.join(__dirname, 'runner', 'temp2');
|
const tempDir = path.join(__dirname, 'runner', 'temp2');
|
||||||
|
|
||||||
describe('setup-dotnet tests', () => {
|
describe('setup-dotnet tests', () => {
|
||||||
@ -52,11 +61,7 @@ describe('setup-dotnet tests', () => {
|
|||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
|
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
|
||||||
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
createGlobalJsonPath('3.1.201');
|
||||||
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
|
|
||||||
if (!fs.existsSync(globalJsonPath)) {
|
|
||||||
fs.writeFileSync(globalJsonPath, jsonContents);
|
|
||||||
}
|
|
||||||
await setup.run();
|
await setup.run();
|
||||||
|
|
||||||
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
|
||||||
@ -78,11 +83,7 @@ describe('setup-dotnet tests', () => {
|
|||||||
}, 400000);
|
}, 400000);
|
||||||
|
|
||||||
it("Sets output with the version specified in global.json, if it's present", async () => {
|
it("Sets output with the version specified in global.json, if it's present", async () => {
|
||||||
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
createGlobalJsonPath('3.0.103');
|
||||||
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.0.103"${os.EOL}}${os.EOL}}`;
|
|
||||||
if (!fs.existsSync(globalJsonPath)) {
|
|
||||||
fs.writeFileSync(globalJsonPath, jsonContents);
|
|
||||||
}
|
|
||||||
|
|
||||||
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
|
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
|
||||||
inputs['global-json-file'] = './global.json';
|
inputs['global-json-file'] = './global.json';
|
||||||
@ -95,4 +96,19 @@ describe('setup-dotnet tests', () => {
|
|||||||
|
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('dotnet-version', '3.0.103');
|
expect(setOutputSpy).toHaveBeenCalledWith('dotnet-version', '3.0.103');
|
||||||
}, 400000);
|
}, 400000);
|
||||||
|
|
||||||
|
it('Sets output with the version specified in global.json with absolute path', async () => {
|
||||||
|
const globalJsonPath = createGlobalJsonPath('3.0.103');
|
||||||
|
|
||||||
|
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
|
||||||
|
inputs['global-json-file'] = globalJsonPath;
|
||||||
|
|
||||||
|
getMultilineInputSpy.mockImplementation(input => inputs[input]);
|
||||||
|
|
||||||
|
getInputSpy.mockImplementation(input => inputs[input]);
|
||||||
|
|
||||||
|
await setup.run();
|
||||||
|
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith('dotnet-version', '3.0.103');
|
||||||
|
}, 400000);
|
||||||
});
|
});
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
@ -513,7 +513,7 @@ function run() {
|
|||||||
const installedDotnetVersions = [];
|
const installedDotnetVersions = [];
|
||||||
const globalJsonFileInput = core.getInput('global-json-file');
|
const globalJsonFileInput = core.getInput('global-json-file');
|
||||||
if (globalJsonFileInput) {
|
if (globalJsonFileInput) {
|
||||||
const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput);
|
const globalJsonPath = path_1.default.resolve(process.cwd(), globalJsonFileInput);
|
||||||
if (!fs.existsSync(globalJsonPath)) {
|
if (!fs.existsSync(globalJsonPath)) {
|
||||||
throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`);
|
throw new Error(`The specified global.json file '${globalJsonFileInput}' does not exist`);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ export async function run() {
|
|||||||
|
|
||||||
const globalJsonFileInput = core.getInput('global-json-file');
|
const globalJsonFileInput = core.getInput('global-json-file');
|
||||||
if (globalJsonFileInput) {
|
if (globalJsonFileInput) {
|
||||||
const globalJsonPath = path.join(process.cwd(), globalJsonFileInput);
|
const globalJsonPath = path.resolve(process.cwd(), globalJsonFileInput);
|
||||||
if (!fs.existsSync(globalJsonPath)) {
|
if (!fs.existsSync(globalJsonPath)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The specified global.json file '${globalJsonFileInput}' does not exist`
|
`The specified global.json file '${globalJsonFileInput}' does not exist`
|
||||||
|
Loading…
Reference in New Issue
Block a user