Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequential version install fix #16

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dd32dd7
Update installers
nikolai-laevskii May 12, 2023
6d92b9b
Refactor install dir computation
nikolai-laevskii May 12, 2023
aa85432
Refactor installer
nikolai-laevskii May 12, 2023
3dfe267
Format: Refactor installer
nikolai-laevskii May 24, 2023
7e164d3
Fix DOTNET_INSTALL_DIR enviornment variable
nikolai-laevskii May 12, 2023
abf9166
build: Fix DOTNET_INSTALL_DIR enviornment variable
nikolai-laevskii May 12, 2023
df506c2
Refactor convertInstallPathToAbsolute
nikolai-laevskii May 12, 2023
cce8e1b
Merge branch 'main' into refactor-installer
nikolai-laevskii May 24, 2023
b7461a1
Remove excessive whitespace
nikolai-laevskii May 24, 2023
5c7ae4f
Apply consistent naming
nikolai-laevskii May 24, 2023
eb0b7f8
Update build
nikolai-laevskii May 24, 2023
80a318b
Change PLATFORM to constant instead of function
nikolai-laevskii May 25, 2023
2785e21
Update build
nikolai-laevskii May 25, 2023
916aec4
Rename DotnetInstallDir.path to DotnetInstallDir.dirPath
nikolai-laevskii May 30, 2023
defac24
Rename initialize to setEnvironmentVariable
nikolai-laevskii May 30, 2023
89b480a
Call addToPath method on DotnetInstallDir directly
nikolai-laevskii May 30, 2023
427804d
Update tests
nikolai-laevskii May 30, 2023
820f30d
Make assigning of the script path intuitive
nikolai-laevskii May 30, 2023
addb470
Make setup script functions synchronous
nikolai-laevskii May 30, 2023
6019612
Merge remote-tracking branch 'github/main' into refactor-installer
nikolai-laevskii May 31, 2023
3cdb094
Build
nikolai-laevskii May 31, 2023
8f71719
Add dotnet runtime installation before main script run
nikolai-laevskii May 12, 2023
6eb2af6
Update tests to accomodate for changes
nikolai-laevskii May 24, 2023
9471c5d
Update e2e tests
nikolai-laevskii May 24, 2023
ea6d1c2
Add more comprehensive testing
nikolai-laevskii May 12, 2023
faa708d
Fix e2e tests
nikolai-laevskii May 12, 2023
4827734
Reduce number of e2e tests
nikolai-laevskii Jun 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,33 @@ jobs:
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.201$" -CheckNugetConfig

test-sequential-version-installation:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
lower-version: ['2.2.402', '3.0.103', '3.1.426', '6.0.408', '7.0.100']
higher-version: ['6.0.408', '7.0.203']
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
# Install one version, use it for something, then switch to next version
- name: Setup dotnet (lower version)
uses: ./
with:
dotnet-version: ${{ matrix.lower-version }}
- name: Verify dotnet (lower version)
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$"
- name: Setup dotnet (higher version)
uses: ./
with:
dotnet-version: ${{ matrix.higher-version }}
- name: Verify dotnet (higher version)
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$", "^${{ matrix.higher-version }}$"
65 changes: 50 additions & 15 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ describe('installer tests', () => {

await dotnetInstaller.installDotnet();

/**
* First time script would be called to
* install runtime, here we checking only the
* second one that installs actual SDK. i.e. 1
*/
const callIndex = 1;

const scriptArguments = (
getExecOutputSpy.mock.calls[0][1] as string[]
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');
const expectedArgument = IS_WINDOWS
? `-Version ${inputVersion}`
Expand Down Expand Up @@ -185,8 +192,15 @@ describe('installer tests', () => {

await dotnetInstaller.installDotnet();

/**
* First time script would be called to
* install runtime, here we checking only the
* second one that installs actual SDK. i.e. 1
*/
const callIndex = 1;

const scriptArguments = (
getExecOutputSpy.mock.calls[0][1] as string[]
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');
const expectedArgument = IS_WINDOWS
? `-Quality ${inputQuality}`
Expand Down Expand Up @@ -218,8 +232,15 @@ describe('installer tests', () => {

await dotnetInstaller.installDotnet();

/**
* First time script would be called to
* install runtime, here we checking only the
* second one that installs actual SDK. i.e. 1
*/
const callIndex = 1;

const scriptArguments = (
getExecOutputSpy.mock.calls[0][1] as string[]
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');
const expectedArgument = IS_WINDOWS
? `-Channel 6.0`
Expand Down Expand Up @@ -252,8 +273,15 @@ describe('installer tests', () => {

await dotnetInstaller.installDotnet();

/**
* First time script would be called to
* install runtime, here we checking only the
* second one that installs actual SDK. i.e. 1
*/
const callIndex = 1;

const scriptArguments = (
getExecOutputSpy.mock.calls[0][1] as string[]
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');

expect(scriptArguments).toContain(
Expand Down Expand Up @@ -283,8 +311,15 @@ describe('installer tests', () => {

await dotnetInstaller.installDotnet();

/**
* First time script would be called to
* install runtime, here we checking only the
* second one that installs actual SDK. i.e. 1
*/
const callIndex = 1;

const scriptArguments = (
getExecOutputSpy.mock.calls[0][1] as string[]
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');

expect(scriptArguments).toContain(
Expand All @@ -297,22 +332,22 @@ describe('installer tests', () => {
describe('addToPath() tests', () => {
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
installer.DotnetCoreInstaller.addToPath();
installer.DotnetInstallDir.addToPath();
const dotnet_root = process.env['DOTNET_ROOT'];
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
});

it(`should export value from DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
installer.DotnetCoreInstaller.addToPath();
installer.DotnetInstallDir.addToPath();
const path = process.env['PATH'];
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
});
});
});

describe('DotnetVersionResolver tests', () => {
describe('createDotNetVersion() tests', () => {
describe('createDotnetVersion() tests', () => {
each([
'3.1',
'3.x',
Expand All @@ -329,7 +364,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(!!versionObject.value).toBe(true);
}
Expand Down Expand Up @@ -368,7 +403,7 @@ describe('installer tests', () => {
);

await expect(
async () => await dotnetVersionResolver.createDotNetVersion()
async () => await dotnetVersionResolver.createDotnetVersion()
).rejects.toThrow();
}
);
Expand All @@ -380,7 +415,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(versionObject.type.toLowerCase().includes('channel')).toBe(
true
Expand All @@ -395,7 +430,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(versionObject.type.toLowerCase().includes('channel')).toBe(
true
Expand All @@ -411,7 +446,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();

expect(versionObject.type.toLowerCase().includes('version')).toBe(
true
Expand All @@ -427,7 +462,7 @@ describe('installer tests', () => {
version
);
const versionObject =
await dotnetVersionResolver.createDotNetVersion();
await dotnetVersionResolver.createDotnetVersion();
const windowsRegEx = new RegExp(/^-(Version|Channel)/);
const nonWindowsRegEx = new RegExp(/^--(version|channel)/);

Expand All @@ -447,7 +482,7 @@ describe('installer tests', () => {
version
);
await expect(
async () => await dotnetVersionResolver.createDotNetVersion()
async () => await dotnetVersionResolver.createDotnetVersion()
).rejects.toThrow(
`'dotnet-version' was supplied in invalid format: ${version}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
);
Expand Down
19 changes: 7 additions & 12 deletions __tests__/setup-dotnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import semver from 'semver';
import * as auth from '../src/authutil';

import * as setup from '../src/setup-dotnet';
import {DotnetCoreInstaller} from '../src/installer';
import {DotnetCoreInstaller, DotnetInstallDir} from '../src/installer';
import * as cacheUtils from '../src/cache-utils';
import * as cacheRestore from '../src/cache-restore';

Expand All @@ -28,22 +28,25 @@ describe('setup-dotnet tests', () => {
DotnetCoreInstaller.prototype,
'installDotnet'
);
const addToPathSpy = jest.spyOn(DotnetCoreInstaller, 'addToPath');

const isCacheFeatureAvailableSpy = jest.spyOn(
cacheUtils,
'isCacheFeatureAvailable'
);
const restoreCacheSpy = jest.spyOn(cacheRestore, 'restoreCache');
const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
const addToPathOriginal = DotnetInstallDir.addToPath;

describe('run() tests', () => {
beforeEach(() => {
DotnetInstallDir.addToPath = jest.fn();
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
getInputSpy.mockImplementation(input => inputs[input as string]);
getBooleanInputSpy.mockImplementation(input => inputs[input as string]);
});

afterEach(() => {
DotnetInstallDir.addToPath = addToPathOriginal;
jest.clearAllMocks();
jest.resetAllMocks();
});
Expand Down Expand Up @@ -104,10 +107,9 @@ describe('setup-dotnet tests', () => {
inputs['dotnet-quality'] = '';

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(addToPathSpy).toHaveBeenCalledTimes(1);
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
});

it('should call auth.configAuthentication() if source-url input is provided', async () => {
Expand Down Expand Up @@ -148,18 +150,16 @@ describe('setup-dotnet tests', () => {
installDotnetSpy.mockImplementation(() =>
Promise.resolve(`${inputs['dotnet-version']}`)
);
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(setOutputSpy).toHaveBeenCalledTimes(1);
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
});

it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
inputs['dotnet-version'] = ['6.0.300'];
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;

installDotnetSpy.mockImplementation(() => Promise.resolve(null));
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
Expand All @@ -170,8 +170,6 @@ describe('setup-dotnet tests', () => {
inputs['dotnet-version'] = [];
const warningMessage = `The 'dotnet-version' output will not be set.`;

addToPathSpy.mockImplementation(() => {});

await setup.run();

expect(infoSpy).toHaveBeenCalledWith(warningMessage);
Expand All @@ -185,7 +183,6 @@ describe('setup-dotnet tests', () => {
inputs['cache-dependency-path'] = 'fictitious.package.lock.json';

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

isCacheFeatureAvailableSpy.mockImplementation(() => true);
restoreCacheSpy.mockImplementation(() => Promise.resolve());
Expand All @@ -203,7 +200,6 @@ describe('setup-dotnet tests', () => {
inputs['cache'] = false;

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

isCacheFeatureAvailableSpy.mockImplementation(() => true);
restoreCacheSpy.mockImplementation(() => Promise.resolve());
Expand All @@ -218,7 +214,6 @@ describe('setup-dotnet tests', () => {
inputs['cache'] = true;

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

isCacheFeatureAvailableSpy.mockImplementation(() => false);
restoreCacheSpy.mockImplementation(() => Promise.resolve());
Expand Down
Loading