diff --git a/__tests__/setup-dotnet.test.ts b/__tests__/setup-dotnet.test.ts index c492f56..7ad8be8 100644 --- a/__tests__/setup-dotnet.test.ts +++ b/__tests__/setup-dotnet.test.ts @@ -7,6 +7,7 @@ const toolDir = path.join(__dirname, 'runner', 'tools2'); const tempDir = path.join(__dirname, 'runner', 'temp2'); import * as setup from '../src/setup-dotnet'; +import * as dotnetInstaller from '../src/installer'; const IS_WINDOWS = process.platform === 'win32'; @@ -19,7 +20,7 @@ describe('setup-dotnet tests', () => { await io.rmRF(tempDir); }); - afterAll(async () => { + afterEach(async () => { try { await io.rmRF(path.join(process.cwd(), 'global.json')); await io.rmRF(toolDir); @@ -44,4 +45,26 @@ describe('setup-dotnet tests', () => { expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); } }, 400000); + + it('Acquires version of dotnet from global.json with rollForward option, install the latest patch', async () => { + const globalJsonPath = path.join(process.cwd(), 'global.json'); + const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version":"3.1.201",${os.EOL}"rollForward":"latestFeature"${os.EOL}}${os.EOL}}`; + if (!fs.existsSync(globalJsonPath)) { + fs.writeFileSync(globalJsonPath, jsonContents); + } + + const version = '3.1'; + const installer = new dotnetInstaller.DotnetCoreInstaller(version); + const patchVersion = await installer.resolveVersion( + new dotnetInstaller.DotNetVersionInfo(version) + ); + await setup.run(); + + expect(fs.existsSync(path.join(toolDir, 'sdk', patchVersion))).toBe(true); + if (IS_WINDOWS) { + expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); + } else { + expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); + } + }, 400000); }); diff --git a/dist/index.js b/dist/index.js index be845d6..f510d10 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7829,12 +7829,7 @@ function run() { 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( - // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 - fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); - if (globalJson.sdk && globalJson.sdk.version) { - version = globalJson.sdk.version; - } + version = getVersionFromGlobalJson(globalJsonPath); } } if (version) { @@ -7857,6 +7852,21 @@ function run() { }); } exports.run = run; +function getVersionFromGlobalJson(globalJsonPath) { + let version = ''; + const globalJson = JSON.parse( + // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 + fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); + if (globalJson.sdk && globalJson.sdk.version) { + version = globalJson.sdk.version; + const rollForward = globalJson.sdk.rollForward; + if (rollForward && rollForward === 'latestFeature') { + const [major, minor] = version.split('.'); + version = `${major}.${minor}`; + } + } + return version; +} run(); diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2a0914f..0d09998 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -19,13 +19,7 @@ export async function run() { 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( - // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 - fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim() - ); - if (globalJson.sdk && globalJson.sdk.version) { - version = globalJson.sdk.version; - } + version = getVersionFromGlobalJson(globalJsonPath); } } @@ -54,4 +48,21 @@ export async function run() { } } +function getVersionFromGlobalJson(globalJsonPath: string): string { + let version: string = ''; + const globalJson = JSON.parse( + // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 + fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim() + ); + if (globalJson.sdk && globalJson.sdk.version) { + version = globalJson.sdk.version; + const rollForward = globalJson.sdk.rollForward; + if (rollForward && rollForward === 'latestFeature') { + const [major, minor] = version.split('.'); + version = `${major}.${minor}`; + } + } + return version; +} + run();