mirror of
https://github.com/actions/setup-dotnet.git
synced 2026-12-01 00:43:08 +00:00
Resolve global.json latestMajor to the newest active release instead of LTS (#803)
* Resolve global.json latestMajor to the newest active release, not LTS rollForward: latestMajor cleared the version, which createChannelArgument mapped to the LTS channel. When the declared sdk.version belongs to an STS release, the LTS channel is older than the declared version and the installed SDK does not satisfy global.json. Resolve it from the releases index to the newest active release of either support type, still GA only. * Limit latestMajor resolution to global.json and enforce the minimum version An empty version without rollForward latestMajor (for example a global.json without sdk.version) resolves to the LTS channel again. After an online install, the action fails if the installed SDK is older than the global.json minimum version. The installer tests now mock the releases index instead of calling the live service.
This commit is contained in:
@@ -33,6 +33,35 @@ jest.unstable_mockModule('@actions/core', () => ({
|
||||
jest.unstable_mockModule('@actions/io', () => ({
|
||||
which: jest.fn()
|
||||
}));
|
||||
// Keeps resolution of the releases index deterministic and offline.
|
||||
const releasesIndex = {
|
||||
'releases-index': [
|
||||
{
|
||||
'channel-version': '12.0',
|
||||
'support-phase': 'preview',
|
||||
'release-type': 'lts'
|
||||
},
|
||||
{
|
||||
'channel-version': '11.0',
|
||||
'support-phase': 'active',
|
||||
'release-type': 'sts'
|
||||
},
|
||||
{
|
||||
'channel-version': '10.0',
|
||||
'support-phase': 'active',
|
||||
'release-type': 'lts'
|
||||
},
|
||||
{'channel-version': '9.0', 'support-phase': 'eol', 'release-type': 'sts'}
|
||||
]
|
||||
};
|
||||
jest.unstable_mockModule('@actions/http-client', () => ({
|
||||
// A plain class, so jest.resetAllMocks() does not clear the response.
|
||||
HttpClient: class {
|
||||
async getJson() {
|
||||
return {statusCode: 200, result: releasesIndex, headers: {}};
|
||||
}
|
||||
}
|
||||
}));
|
||||
jest.unstable_mockModule('fs', () => {
|
||||
const actual = jest.requireActual('fs') as typeof import('fs');
|
||||
const chmodSync = jest.fn();
|
||||
@@ -586,7 +615,7 @@ describe('installer tests', () => {
|
||||
getExecOutputSpy.mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
exitCode: 0,
|
||||
stdout: 'Fictitious dotnet version 1.2.3 is installed',
|
||||
stdout: 'Fictitious dotnet version 99.0.100 is installed',
|
||||
stderr: ''
|
||||
})
|
||||
);
|
||||
@@ -1244,6 +1273,90 @@ describe('installer tests', () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe('global.json online resolution tests', () => {
|
||||
const mockInstalledVersion = (version: string) =>
|
||||
getExecOutputSpy.mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
exitCode: 0,
|
||||
stdout: `Fictitious dotnet version ${version} is installed`,
|
||||
stderr: ''
|
||||
})
|
||||
);
|
||||
const installArguments = () =>
|
||||
(getExecOutputSpy.mock.calls.at(-1)![1] as string[]).join(' ');
|
||||
const channelArgument = (channel: string) =>
|
||||
IS_WINDOWS ? `-Channel ${channel}` : `--channel ${channel}`;
|
||||
|
||||
beforeEach(() => {
|
||||
readdirSyncSpy.mockReturnValue(makeDirents([]));
|
||||
});
|
||||
|
||||
it('installs the newest active channel for latestMajor even when it is STS', async () => {
|
||||
mockInstalledVersion('11.0.100');
|
||||
|
||||
const installedVersion = await new installer.DotnetCoreInstaller(
|
||||
'',
|
||||
'',
|
||||
undefined,
|
||||
undefined,
|
||||
true,
|
||||
'10.0.100',
|
||||
'latestMajor'
|
||||
).installDotnet();
|
||||
|
||||
expect(installedVersion).toBe('11.0.100');
|
||||
expect(installArguments()).toContain(channelArgument('11.0'));
|
||||
});
|
||||
|
||||
it('keeps installing from the LTS channel for an empty version without latestMajor', async () => {
|
||||
mockInstalledVersion('10.0.100');
|
||||
|
||||
await new installer.DotnetCoreInstaller(
|
||||
'',
|
||||
'',
|
||||
undefined,
|
||||
undefined,
|
||||
true
|
||||
).installDotnet();
|
||||
|
||||
expect(installArguments()).toContain(channelArgument('LTS'));
|
||||
});
|
||||
|
||||
it('fails when the installed SDK in the newest channel is below the global.json minimum', async () => {
|
||||
mockInstalledVersion('11.0.100');
|
||||
|
||||
await expect(
|
||||
new installer.DotnetCoreInstaller(
|
||||
'',
|
||||
'',
|
||||
undefined,
|
||||
undefined,
|
||||
true,
|
||||
'11.0.200',
|
||||
'latestMajor'
|
||||
).installDotnet()
|
||||
).rejects.toThrow(
|
||||
'The installed .NET SDK 11.0.100 is older than the global.json minimum version 11.0.200.'
|
||||
);
|
||||
});
|
||||
|
||||
it('accepts an installed SDK equal to the global.json minimum', async () => {
|
||||
mockInstalledVersion('11.0.200');
|
||||
|
||||
const installedVersion = await new installer.DotnetCoreInstaller(
|
||||
'',
|
||||
'',
|
||||
undefined,
|
||||
undefined,
|
||||
true,
|
||||
'11.0.200',
|
||||
'latestMajor'
|
||||
).installDotnet();
|
||||
|
||||
expect(installedVersion).toBe('11.0.200');
|
||||
});
|
||||
});
|
||||
|
||||
describe('skip-lts-prepass tests', () => {
|
||||
it('should run the LTS pre-pass by default (skip-lts-prepass not set)', async () => {
|
||||
const inputVersion = '9.0.100';
|
||||
|
||||
@@ -117,6 +117,45 @@ describe('DotnetVersionResolver with latest', () => {
|
||||
expect(version.value).toBe('9.0');
|
||||
});
|
||||
|
||||
it('should resolve an empty version (global.json latestMajor) to the highest stable release of any support type', async () => {
|
||||
getJsonMock.mockResolvedValue({result: mockReleases});
|
||||
|
||||
const resolver = new DotnetVersionResolver(
|
||||
'',
|
||||
'',
|
||||
undefined,
|
||||
'latestMajor'
|
||||
);
|
||||
const version = await resolver.createDotnetVersion();
|
||||
|
||||
expect(version.value).toBe('9.0');
|
||||
expect(version.type.toLowerCase()).toContain('channel');
|
||||
expect(version.qualityFlag).toBe(false);
|
||||
});
|
||||
|
||||
it('should keep resolving an empty version (global.json latestMajor) to a stable release when quality is preview', async () => {
|
||||
getJsonMock.mockResolvedValue({result: mockReleases});
|
||||
|
||||
const resolver = new DotnetVersionResolver(
|
||||
'',
|
||||
'preview',
|
||||
undefined,
|
||||
'latestMajor'
|
||||
);
|
||||
const version = await resolver.createDotnetVersion();
|
||||
|
||||
expect(version.value).toBe('9.0');
|
||||
expect(version.qualityFlag).toBe(false);
|
||||
});
|
||||
|
||||
it('should keep resolving an empty version without latestMajor to the LTS channel', async () => {
|
||||
const resolver = new DotnetVersionResolver('');
|
||||
const version = await resolver.createDotnetVersion();
|
||||
|
||||
expect(version.value).toBe('LTS');
|
||||
expect(getJsonMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should warn if channel is provided but version is not latest', async () => {
|
||||
getJsonMock.mockResolvedValue({result: mockReleases});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user