Merge pull request #224 from vsafonkin/v-vlsafo/handle-roll-forward-option

Support `rollForward` option from `global.json` file
This commit is contained in:
Vladimir Safonkin 2021-09-13 10:09:01 +03:00 committed by GitHub
commit f2da928c08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 14 deletions

View File

@ -7,6 +7,7 @@ const toolDir = path.join(__dirname, 'runner', 'tools2');
const tempDir = path.join(__dirname, 'runner', 'temp2'); const tempDir = path.join(__dirname, 'runner', 'temp2');
import * as setup from '../src/setup-dotnet'; import * as setup from '../src/setup-dotnet';
import * as dotnetInstaller from '../src/installer';
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
@ -19,7 +20,7 @@ describe('setup-dotnet tests', () => {
await io.rmRF(tempDir); await io.rmRF(tempDir);
}); });
afterAll(async () => { afterEach(async () => {
try { try {
await io.rmRF(path.join(process.cwd(), 'global.json')); await io.rmRF(path.join(process.cwd(), 'global.json'));
await io.rmRF(toolDir); await io.rmRF(toolDir);
@ -44,4 +45,26 @@ describe('setup-dotnet tests', () => {
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
} }
}, 400000); }, 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);
}); });

22
dist/index.js vendored
View File

@ -7829,12 +7829,7 @@ function run() {
core.debug('No version found, trying to find version from 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( version = getVersionFromGlobalJson(globalJsonPath);
// .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;
}
} }
} }
if (version) { if (version) {
@ -7857,6 +7852,21 @@ function run() {
}); });
} }
exports.run = 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(); run();

View File

@ -19,13 +19,7 @@ export async function run() {
core.debug('No version found, trying to find version from 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( version = getVersionFromGlobalJson(globalJsonPath);
// .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;
}
} }
} }
@ -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(); run();