From 8f71719d12170727f91d62865978ca1704278f05 Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Fri, 12 May 2023 17:00:39 +0200 Subject: [PATCH 1/6] Add dotnet runtime installation before main script run --- dist/setup/index.js | 37 ++++++++++++++++++++++++++++++------ src/installer.ts | 46 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0fed9c1..8783c48 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -71385,14 +71385,39 @@ class DotnetCoreInstaller { return __awaiter(this, void 0, void 0, function* () { const versionResolver = new DotnetVersionResolver(this.version); const dotnetVersion = yield versionResolver.createDotnetVersion(); - const installScript = new DotnetInstallScript() + /** + * Install dotnet runitme first in order to get + * the latest stable version of dotnet CLI + */ + const runtimeInstallOutput = yield new DotnetInstallScript() + // If dotnet CLI is already installed - avoid overwriting it .useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files') - .useVersion(dotnetVersion, this.quality); - const { exitCode, stderr, stdout } = yield installScript.execute(); - if (exitCode) { - throw new Error(`Failed to install dotnet, exit code: ${exitCode}. ${stderr}`); + // Install only runtime + CLI + .useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet') + // Use latest stable version + .useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS') + .execute(); + if (runtimeInstallOutput.exitCode) { + /** + * dotnetInstallScript will install CLI and runtime even if previous script haven't succeded, + * so at this point it's too early to throw an error + */ + core.warning(`Failed to install dotnet runtime + cli, exit code: ${runtimeInstallOutput.exitCode}. ${runtimeInstallOutput.stderr}`); } - return this.parseInstalledVersion(stdout); + /** + * Install dotnet over the latest version of + * dotnet CLI + */ + const dotnetInstallOutput = yield new DotnetInstallScript() + // Don't overwrite CLI because it should be already installed + .useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files') + // Use version provided by user + .useVersion(dotnetVersion, this.quality) + .execute(); + if (dotnetInstallOutput.exitCode) { + throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`); + } + return this.parseInstalledVersion(dotnetInstallOutput.stdout); }); } parseInstalledVersion(stdout) { diff --git a/src/installer.ts b/src/installer.ts index 4d61e5d..4900afa 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -259,21 +259,51 @@ export class DotnetCoreInstaller { const versionResolver = new DotnetVersionResolver(this.version); const dotnetVersion = await versionResolver.createDotnetVersion(); - const installScript = new DotnetInstallScript() + /** + * Install dotnet runitme first in order to get + * the latest stable version of dotnet CLI + */ + const runtimeInstallOutput = await new DotnetInstallScript() + // If dotnet CLI is already installed - avoid overwriting it .useArguments( IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files' ) - .useVersion(dotnetVersion, this.quality); + // Install only runtime + CLI + .useArguments(IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet') + // Use latest stable version + .useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS') + .execute(); - const {exitCode, stderr, stdout} = await installScript.execute(); - - if (exitCode) { - throw new Error( - `Failed to install dotnet, exit code: ${exitCode}. ${stderr}` + if (runtimeInstallOutput.exitCode) { + /** + * dotnetInstallScript will install CLI and runtime even if previous script haven't succeded, + * so at this point it's too early to throw an error + */ + core.warning( + `Failed to install dotnet runtime + cli, exit code: ${runtimeInstallOutput.exitCode}. ${runtimeInstallOutput.stderr}` ); } - return this.parseInstalledVersion(stdout); + /** + * Install dotnet over the latest version of + * dotnet CLI + */ + const dotnetInstallOutput = await new DotnetInstallScript() + // Don't overwrite CLI because it should be already installed + .useArguments( + IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files' + ) + // Use version provided by user + .useVersion(dotnetVersion, this.quality) + .execute(); + + if (dotnetInstallOutput.exitCode) { + throw new Error( + `Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}` + ); + } + + return this.parseInstalledVersion(dotnetInstallOutput.stdout); } private parseInstalledVersion(stdout: string): string | null { From 6eb2af61b6d36c282791886863f399c7ef1a3aba Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Wed, 24 May 2023 17:57:28 +0200 Subject: [PATCH 2/6] Update tests to accomodate for changes --- __tests__/installer.test.ts | 45 ++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index ceb4b37..84aea32 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -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}` @@ -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}` @@ -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` @@ -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( @@ -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( From 9471c5df0b2fd7cca68d558422e90988538aafc6 Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Wed, 24 May 2023 18:04:43 +0200 Subject: [PATCH 3/6] Update e2e tests --- .github/workflows/e2e-tests.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index d244b1c..1b9295f 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -426,3 +426,31 @@ 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] + 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 2.2.402 + uses: ./ + with: + dotnet-version: 2.2.402 + - name: Verify dotnet 2.2.402 + shell: pwsh + run: __tests__/verify-dotnet.ps1 -Patterns "^2.2.402$" + - name: Setup dotnet 7.0.203 + uses: ./ + with: + dotnet-version: 7.0.203 + - name: Verify dotnet 7.0.203 + shell: pwsh + run: __tests__/verify-dotnet.ps1 -Patterns "^7.0.203$" From ea6d1c26e75f8f9650d3bbc361a442abde69fba5 Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Fri, 12 May 2023 18:22:11 +0200 Subject: [PATCH 4/6] Add more comprehensive testing --- .github/workflows/e2e-tests.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 1b9295f..26ccaaa 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -433,6 +433,8 @@ jobs: 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 @@ -440,17 +442,17 @@ jobs: shell: pwsh run: __tests__/clear-toolcache.ps1 ${{ runner.os }} # Install one version, use it for something, then switch to next version - - name: Setup dotnet 2.2.402 + - name: Setup dotnet (lower version) uses: ./ with: - dotnet-version: 2.2.402 - - name: Verify dotnet 2.2.402 + dotnet-version: ${{ matrix.lower-version }} + - name: Verify dotnet (lower version) shell: pwsh - run: __tests__/verify-dotnet.ps1 -Patterns "^2.2.402$" - - name: Setup dotnet 7.0.203 + run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$" + - name: Setup dotnet (higher version) uses: ./ with: - dotnet-version: 7.0.203 - - name: Verify dotnet 7.0.203 + dotnet-version: ${{ matrix.higher-version }} + - name: Verify dotnet (higher version) shell: pwsh - run: __tests__/verify-dotnet.ps1 -Patterns "^7.0.203$" + run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.higher-version }}$" From faa708d00bb10c8288dbce63f0db73b287e52b33 Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Fri, 12 May 2023 18:38:20 +0200 Subject: [PATCH 5/6] Fix e2e tests --- .github/workflows/e2e-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 26ccaaa..a81a42c 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -455,4 +455,4 @@ jobs: dotnet-version: ${{ matrix.higher-version }} - name: Verify dotnet (higher version) shell: pwsh - run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.higher-version }}$" + run: __tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.lower-version }}$", "^${{ matrix.higher-version }}$" From 48277343a530e8f1def38c41afa05da090100cf8 Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Tue, 6 Jun 2023 13:23:53 +0200 Subject: [PATCH 6/6] Reduce number of e2e tests --- .github/workflows/e2e-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index a81a42c..7733af0 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -433,8 +433,8 @@ jobs: 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'] + lower-version: ['3.1.426'] + higher-version: ['7.0.203'] steps: - name: Checkout uses: actions/checkout@v3