Skip to content

Commit 9b40770

Browse files
Merge pull request #433 from akv-platform/sequential-version-install-fix
Sequential version install fix
2 parents 70fa320 + 4827734 commit 9b40770

File tree

4 files changed

+137
-17
lines changed

4 files changed

+137
-17
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,33 @@ jobs:
451451
- name: Verify dotnet
452452
shell: pwsh
453453
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.201$" -CheckNugetConfig
454+
455+
test-sequential-version-installation:
456+
runs-on: ${{ matrix.operating-system }}
457+
strategy:
458+
fail-fast: false
459+
matrix:
460+
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
461+
lower-version: ['3.1.426']
462+
higher-version: ['7.0.203']
463+
steps:
464+
- name: Checkout
465+
uses: actions/checkout@v3
466+
- name: Clear toolcache
467+
shell: pwsh
468+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
469+
# Install one version, use it for something, then switch to next version
470+
- name: Setup dotnet (lower version)
471+
uses: ./
472+
with:
473+
dotnet-version: ${{ matrix.lower-version }}
474+
- name: Verify dotnet (lower version)
475+
shell: pwsh
476+
run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$"
477+
- name: Setup dotnet (higher version)
478+
uses: ./
479+
with:
480+
dotnet-version: ${{ matrix.higher-version }}
481+
- name: Verify dotnet (higher version)
482+
shell: pwsh
483+
run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$", "^${{ matrix.higher-version }}$"

__tests__/installer.test.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,15 @@ describe('installer tests', () => {
102102

103103
await dotnetInstaller.installDotnet();
104104

105+
/**
106+
* First time script would be called to
107+
* install runtime, here we checking only the
108+
* second one that installs actual SDK. i.e. 1
109+
*/
110+
const callIndex = 1;
111+
105112
const scriptArguments = (
106-
getExecOutputSpy.mock.calls[0][1] as string[]
113+
getExecOutputSpy.mock.calls[callIndex][1] as string[]
107114
).join(' ');
108115
const expectedArgument = IS_WINDOWS
109116
? `-Version ${inputVersion}`
@@ -185,8 +192,15 @@ describe('installer tests', () => {
185192

186193
await dotnetInstaller.installDotnet();
187194

195+
/**
196+
* First time script would be called to
197+
* install runtime, here we checking only the
198+
* second one that installs actual SDK. i.e. 1
199+
*/
200+
const callIndex = 1;
201+
188202
const scriptArguments = (
189-
getExecOutputSpy.mock.calls[0][1] as string[]
203+
getExecOutputSpy.mock.calls[callIndex][1] as string[]
190204
).join(' ');
191205
const expectedArgument = IS_WINDOWS
192206
? `-Quality ${inputQuality}`
@@ -218,8 +232,15 @@ describe('installer tests', () => {
218232

219233
await dotnetInstaller.installDotnet();
220234

235+
/**
236+
* First time script would be called to
237+
* install runtime, here we checking only the
238+
* second one that installs actual SDK. i.e. 1
239+
*/
240+
const callIndex = 1;
241+
221242
const scriptArguments = (
222-
getExecOutputSpy.mock.calls[0][1] as string[]
243+
getExecOutputSpy.mock.calls[callIndex][1] as string[]
223244
).join(' ');
224245
const expectedArgument = IS_WINDOWS
225246
? `-Channel 6.0`
@@ -252,8 +273,15 @@ describe('installer tests', () => {
252273

253274
await dotnetInstaller.installDotnet();
254275

276+
/**
277+
* First time script would be called to
278+
* install runtime, here we checking only the
279+
* second one that installs actual SDK. i.e. 1
280+
*/
281+
const callIndex = 1;
282+
255283
const scriptArguments = (
256-
getExecOutputSpy.mock.calls[0][1] as string[]
284+
getExecOutputSpy.mock.calls[callIndex][1] as string[]
257285
).join(' ');
258286

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

284312
await dotnetInstaller.installDotnet();
285313

314+
/**
315+
* First time script would be called to
316+
* install runtime, here we checking only the
317+
* second one that installs actual SDK. i.e. 1
318+
*/
319+
const callIndex = 1;
320+
286321
const scriptArguments = (
287-
getExecOutputSpy.mock.calls[0][1] as string[]
322+
getExecOutputSpy.mock.calls[callIndex][1] as string[]
288323
).join(' ');
289324

290325
expect(scriptArguments).toContain(

dist/setup/index.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72843,14 +72843,39 @@ class DotnetCoreInstaller {
7284372843
return __awaiter(this, void 0, void 0, function* () {
7284472844
const versionResolver = new DotnetVersionResolver(this.version);
7284572845
const dotnetVersion = yield versionResolver.createDotnetVersion();
72846-
const installScript = new DotnetInstallScript()
72846+
/**
72847+
* Install dotnet runitme first in order to get
72848+
* the latest stable version of dotnet CLI
72849+
*/
72850+
const runtimeInstallOutput = yield new DotnetInstallScript()
72851+
// If dotnet CLI is already installed - avoid overwriting it
72852+
.useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
72853+
// Install only runtime + CLI
72854+
.useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
72855+
// Use latest stable version
72856+
.useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
72857+
.execute();
72858+
if (runtimeInstallOutput.exitCode) {
72859+
/**
72860+
* dotnetInstallScript will install CLI and runtime even if previous script haven't succeded,
72861+
* so at this point it's too early to throw an error
72862+
*/
72863+
core.warning(`Failed to install dotnet runtime + cli, exit code: ${runtimeInstallOutput.exitCode}. ${runtimeInstallOutput.stderr}`);
72864+
}
72865+
/**
72866+
* Install dotnet over the latest version of
72867+
* dotnet CLI
72868+
*/
72869+
const dotnetInstallOutput = yield new DotnetInstallScript()
72870+
// Don't overwrite CLI because it should be already installed
7284772871
.useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
72848-
.useVersion(dotnetVersion, this.quality);
72849-
const { exitCode, stderr, stdout } = yield installScript.execute();
72850-
if (exitCode) {
72851-
throw new Error(`Failed to install dotnet, exit code: ${exitCode}. ${stderr}`);
72872+
// Use version provided by user
72873+
.useVersion(dotnetVersion, this.quality)
72874+
.execute();
72875+
if (dotnetInstallOutput.exitCode) {
72876+
throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`);
7285272877
}
72853-
return this.parseInstalledVersion(stdout);
72878+
return this.parseInstalledVersion(dotnetInstallOutput.stdout);
7285472879
});
7285572880
}
7285672881
parseInstalledVersion(stdout) {

src/installer.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,51 @@ export class DotnetCoreInstaller {
259259
const versionResolver = new DotnetVersionResolver(this.version);
260260
const dotnetVersion = await versionResolver.createDotnetVersion();
261261

262-
const installScript = new DotnetInstallScript()
262+
/**
263+
* Install dotnet runitme first in order to get
264+
* the latest stable version of dotnet CLI
265+
*/
266+
const runtimeInstallOutput = await new DotnetInstallScript()
267+
// If dotnet CLI is already installed - avoid overwriting it
263268
.useArguments(
264269
IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files'
265270
)
266-
.useVersion(dotnetVersion, this.quality);
271+
// Install only runtime + CLI
272+
.useArguments(IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
273+
// Use latest stable version
274+
.useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
275+
.execute();
276+
277+
if (runtimeInstallOutput.exitCode) {
278+
/**
279+
* dotnetInstallScript will install CLI and runtime even if previous script haven't succeded,
280+
* so at this point it's too early to throw an error
281+
*/
282+
core.warning(
283+
`Failed to install dotnet runtime + cli, exit code: ${runtimeInstallOutput.exitCode}. ${runtimeInstallOutput.stderr}`
284+
);
285+
}
267286

268-
const {exitCode, stderr, stdout} = await installScript.execute();
287+
/**
288+
* Install dotnet over the latest version of
289+
* dotnet CLI
290+
*/
291+
const dotnetInstallOutput = await new DotnetInstallScript()
292+
// Don't overwrite CLI because it should be already installed
293+
.useArguments(
294+
IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files'
295+
)
296+
// Use version provided by user
297+
.useVersion(dotnetVersion, this.quality)
298+
.execute();
269299

270-
if (exitCode) {
300+
if (dotnetInstallOutput.exitCode) {
271301
throw new Error(
272-
`Failed to install dotnet, exit code: ${exitCode}. ${stderr}`
302+
`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`
273303
);
274304
}
275305

276-
return this.parseInstalledVersion(stdout);
306+
return this.parseInstalledVersion(dotnetInstallOutput.stdout);
277307
}
278308

279309
private parseInstalledVersion(stdout: string): string | null {

0 commit comments

Comments
 (0)