Install sxs with the install-dotnet scripts (#124)

* Use dotnet-install scripts for proper sxs

* Update dotnet version in testing

* Error message cleanup

* SxS testing in the dotnet project

* Update package lock

* Test fixes

* Use proper environment variable

* Set dotnet root for windows
This commit is contained in:
Zachary Eisinger
2020-09-15 09:36:09 -07:00
committed by GitHub
parent 3569a93d9f
commit 352338157c
16 changed files with 775 additions and 1816 deletions

View File

@ -81,7 +81,11 @@ describe('authutil tests', () => {
beforeEach(async () => {
await io.rmRF(fakeSourcesDirForTesting);
await io.mkdirP(fakeSourcesDirForTesting);
}, 100000);
}, 30000);
afterAll(async () => {
await io.rmRF(fakeSourcesDirForTesting);
}, 30000);
beforeEach(() => {
if (fs.existsSync(nugetConfigFile)) {

View File

@ -73,6 +73,9 @@ describe('version tests', () => {
describe('installer tests', () => {
beforeAll(async () => {
process.env.RUNNER_TOOL_CACHE = toolDir;
process.env.DOTNET_INSTALL_DIR = toolDir;
process.env.RUNNER_TEMP = tempDir;
await io.rmRF(toolDir);
await io.rmRF(tempDir);
});
@ -84,23 +87,21 @@ describe('installer tests', () => {
} catch {
console.log('Failed to remove test directories');
}
}, 100000);
}, 30000);
it('Resolving a normal generic version works', async () => {
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.x');
let versInfo = await dotnetInstaller.resolveInfos(
['win-x64'],
let versInfo = await dotnetInstaller.resolveVersion(
new installer.DotNetVersionInfo('3.1.x')
);
expect(versInfo.resolvedVersion.startsWith('3.1.'));
expect(versInfo.startsWith('3.1.'));
}, 100000);
it('Resolving a nonexistent generic version fails', async () => {
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
try {
await dotnetInstaller.resolveInfos(
['win-x64'],
await dotnetInstaller.resolveVersion(
new installer.DotNetVersionInfo('999.1.x')
);
fail();
@ -111,53 +112,47 @@ describe('installer tests', () => {
it('Resolving a exact stable version works', async () => {
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.201');
let versInfo = await dotnetInstaller.resolveInfos(
['win-x64'],
let versInfo = await dotnetInstaller.resolveVersion(
new installer.DotNetVersionInfo('3.1.201')
);
expect(versInfo.resolvedVersion).toBe('3.1.201');
expect(versInfo).toBe('3.1.201');
}, 100000);
it('Resolving a exact preview version works', async () => {
const dotnetInstaller = new installer.DotnetCoreInstaller(
'5.0.0-preview.4'
'5.0.0-preview.6'
);
let versInfo = await dotnetInstaller.resolveInfos(
['win-x64'],
new installer.DotNetVersionInfo('5.0.0-preview.4')
let versInfo = await dotnetInstaller.resolveVersion(
new installer.DotNetVersionInfo('5.0.0-preview.6')
);
expect(versInfo.resolvedVersion).toBe('5.0.0-preview.4');
expect(versInfo).toBe('5.0.0-preview.6');
}, 100000);
it('Acquires version of dotnet if no matching version is installed', async () => {
await getDotnet('2.2.205');
const dotnetDir = path.join(toolDir, 'dncs', '2.2.205', os.arch());
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
await getDotnet('3.1.201');
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(dotnetDir, 'dotnet.exe'))).toBe(true);
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
} else {
expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true);
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
}
}, 400000); //This needs some time to download on "slower" internet connections
it('Acquires version of dotnet if no matching version is installed', async () => {
const dotnetDir = path.join(toolDir, 'dncs', '2.2.105', os.arch());
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
const globalJsonPath = path.join(process.cwd(), 'global.json');
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "2.2.105"${os.EOL}}${os.EOL}}`;
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
if (!fs.existsSync(globalJsonPath)) {
fs.writeFileSync(globalJsonPath, jsonContents);
}
await setup.run();
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(dotnetDir, 'dotnet.exe'))).toBe(true);
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
} else {
expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true);
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
}
fs.unlinkSync(globalJsonPath);
}, 100000);
@ -170,30 +165,7 @@ describe('installer tests', () => {
thrown = true;
}
expect(thrown).toBe(true);
}, 100000);
it('Uses version of dotnet installed in cache', async () => {
const dotnetDir: string = path.join(toolDir, 'dncs', '250.0.0', os.arch());
await io.mkdirP(dotnetDir);
fs.writeFileSync(`${dotnetDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
await getDotnet('250.0.0');
return;
});
it('Doesnt use version of dotnet that was only partially installed in cache', async () => {
const dotnetDir: string = path.join(toolDir, 'dncs', '251.0.0', os.arch());
await io.mkdirP(dotnetDir);
let thrown = false;
try {
// This will throw if it doesn't find it in the cache (because no such version exists)
await getDotnet('251.0.0');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
return;
});
}, 30000);
it('Uses an up to date bash download script', async () => {
const httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
@ -213,7 +185,7 @@ describe('installer tests', () => {
expect(normalizeFileContents(currentContents)).toBe(
normalizeFileContents(upToDateContents)
);
}, 100000);
}, 30000);
it('Uses an up to date powershell download script', async () => {
var httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
@ -233,7 +205,7 @@ describe('installer tests', () => {
expect(normalizeFileContents(currentContents)).toBe(
normalizeFileContents(upToDateContents)
);
}, 100000);
}, 30000);
});
function normalizeFileContents(contents: string): string {

View File

@ -1,14 +1,15 @@
using System;
using Newtonsoft.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace sample_csproj
{
class Program
[TestClass]
public class Program
{
static void Main(string[] args)
[TestMethod]
public void TestMethod1()
{
var json = JsonConvert.SerializeObject(new[] {"Hello", "World!" });
Console.WriteLine(json);
Console.WriteLine("Hello, World!");
}
}
}

View File

@ -1,7 +0,0 @@
{
"runtimeOptions": {
"configProperties": {
"System.Globalization.Invariant": true
}
}
}

View File

@ -1,13 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.2</TargetFrameworks>
<RootNamespace>sample_csproj</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<!-- These packages will be downloaded over the network for testing proxy settings -->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,48 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');
const toolDir = path.join(__dirname, 'runner', 'tools2');
const tempDir = path.join(__dirname, 'runner', 'temp2');
import * as setup from '../src/setup-dotnet';
const IS_WINDOWS = process.platform === 'win32';
describe('setup-dotnet tests', () => {
beforeAll(async () => {
process.env.RUNNER_TOOL_CACHE = toolDir;
process.env.DOTNET_INSTALL_DIR = toolDir;
process.env.RUNNER_TEMP = tempDir;
await io.rmRF(toolDir);
await io.rmRF(tempDir);
});
afterAll(async () => {
try {
await io.rmRF(path.join(process.cwd(), 'global.json'));
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log('Failed to remove test directories');
}
}, 30000);
it('Acquires version of dotnet if no matching version is installed', async () => {
const globalJsonPath = path.join(process.cwd(), 'global.json');
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
if (!fs.existsSync(globalJsonPath)) {
fs.writeFileSync(globalJsonPath, jsonContents);
}
await setup.run();
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).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);
}
fs.unlinkSync(globalJsonPath);
}, 100000);
});

View File

@ -13,13 +13,23 @@ Write-Host "Found '$dotnet'"
$version = & $dotnet --version | Out-String | ForEach-Object { $_.Trim() }
Write-Host "Version $version"
# if ($version -ne $args[0])
# {
# Write-Host "PATH='$env:path'"
# Write-Host "gcm dotnet:"
# gcm dotnet | fl
# throw "Unexpected version"
# }
if ($version -ne $args[0])
{
Write-Host "PATH='$env:path'"
throw "Unexpected version"
}
if ($args[1])
{
# SDKs are listed on multiple lines with the path afterwards in square brackets
$version = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() }
Write-Host "Version $version"
if (-not ($version -contains $args[1]))
{
Write-Host "PATH='$env:path'"
throw "Unexpected version"
}
}
Write-Host "Building sample csproj"
& $dotnet build __tests__/sample-csproj/ --no-cache
@ -29,9 +39,20 @@ if ($LASTEXITCODE -ne 0)
}
Write-Host "Testing compiled app"
$sample_output = "$(__tests__/sample-csproj/bin/Debug/netcoreapp3.0/sample.exe)".Trim()
$sample_output = "$(dotnet test __tests__/sample-csproj/ --no-build)"
Write-Host "Sample output: $sample_output"
if ($sample_output -notlike "*Hello*World*")
# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once
if ($args[1])
{
throw "Unexpected output"
if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*")
{
throw "Unexpected output"
}
}
else
{
if ($sample_output -notlike "*Test Run Successful.*")
{
throw "Unexpected output"
}
}

View File

@ -15,13 +15,30 @@ if [ -z "$(echo $dotnet_version | grep $1)" ]; then
exit 1
fi
if [ -n "$2" ]; then
dotnet_version="$(dotnet --list-sdks)"
echo "Found dotnet version '$dotnet_version'"
if [ -z "$(echo $dotnet_version | grep $2)" ]; then
echo "Unexpected version"
exit 1
fi
fi
echo "Building sample csproj"
dotnet build __tests__/sample-csproj/ --no-cache || exit 1
echo "Testing compiled app"
sample_output="$(__tests__/sample-csproj/bin/Debug/netcoreapp3.0/sample)"
sample_output=$(dotnet test __tests__/sample-csproj/ --no-build)
echo "Sample output: $sample_output"
if [ -z "$(echo $sample_output | grep Hello)" ]; then
echo "Unexpected output"
exit 1
# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once
if [ -n "$2" ]; then
if [ -z "$(echo $sample_output | grep "Test Run Successful.*Test Run Successful.")" ]; then
echo "Unexpected output"
exit 1
fi
else
if [ -z "$(echo $sample_output | grep "Test Run Successful.")" ]; then
echo "Unexpected output"
exit 1
fi
fi