Skip to content

Commit

Permalink
Install sxs with the install-dotnet scripts (#124)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Zachary Eisinger authored Sep 15, 2020
1 parent 3569a93 commit 3523381
Show file tree
Hide file tree
Showing 16 changed files with 792 additions and 1,833 deletions.
61 changes: 45 additions & 16 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
Expand All @@ -19,7 +20,7 @@ jobs:
- name: Set Node.js 12
uses: actions/setup-node@v1
with:
version: 12.x
node-version: 12.x
- run: npm ci
- run: npm run build
- run: npm run format-check
Expand All @@ -31,27 +32,50 @@ jobs:
test:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Clear tool cache
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
- name: Setup dotnet 3.0.100
- name: Clear tool cache (macOS)
if: runner.os == 'macos'
run: |
echo $PATH
dotnet --info
rm -rf "/Users/runner/.dotnet"
- name: Clear tool cache (Ubuntu)
if: runner.os == 'linux'
run: |
echo $PATH
dotnet --info
rm -rf "/usr/share/dotnet"
- name: Clear tool cache (Windows)
if: runner.os == 'windows'
run: |
echo $env:PATH
dotnet --info
Remove-Item $env:LocalAppData\Microsoft\dotnet/* -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$env:ProgramFiles\dotnet/*" -Recurse -Force -ErrorAction SilentlyContinue
# Side-by-side install of 2.2 and 3.1 used for the test project
- name: Setup dotnet 2.2.402
uses: ./
with:
dotnet-version: 2.2.402
- name: Setup dotnet 3.1.201
uses: ./
with:
dotnet-version: 3.0.100
dotnet-version: 3.1.201
# We are including this veriable to force the generation of the nuget config file to verify that it is created in the correct place
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet
if: runner.os != 'windows'
run: __tests__/verify-dotnet.sh 3.0.100
run: __tests__/verify-dotnet.sh 3.1.201 2.2.402
- name: Verify dotnet (Windows)
if: runner.os == 'windows'
run: __tests__/verify-dotnet.ps1 3.0.100
run: __tests__/verify-dotnet.ps1 3.1.201

test-proxy:
runs-on: ubuntu-latest
Expand All @@ -65,37 +89,42 @@ jobs:
- 3128:3128
env:
https_proxy: http://squid-proxy:3128
http_proxy: http://squid-proxy:3128
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Clear tool cache
run: rm -rf $RUNNER_TOOL_CACHE/*
- name: Setup dotnet 3.0.100
run: rm -rf "/usr/share/dotnet"
- name: Install curl
run: |
apt update
apt -y install curl
- name: Setup dotnet 3.1.201
uses: ./
with:
dotnet-version: 3.0.100
dotnet-version: 3.1.201
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet
run: __tests__/verify-dotnet.sh 3.0.100
run: __tests__/verify-dotnet.sh 3.1.201

test-bypass-proxy:
runs-on: ubuntu-latest
env:
https_proxy: http://no-such-proxy:3128
no_proxy: github.com,dotnetcli.blob.core.windows.net,download.visualstudio.microsoft.com,api.nuget.org
no_proxy: github.com,dotnetcli.blob.core.windows.net,download.visualstudio.microsoft.com,api.nuget.org,dotnetcli.azureedge.net
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Clear tool cache
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
- name: Setup dotnet 3.0.100
run: rm -rf "/usr/share/dotnet"
- name: Setup dotnet 3.1.201
uses: ./
with:
dotnet-version: 3.0.100
dotnet-version: 3.1.201
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: NOTATOKEN
- name: Verify dotnet
run: __tests__/verify-dotnet.sh 3.0.100
run: __tests__/verify-dotnet.sh 3.1.201
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ typings/
# DynamoDB Local files
.dynamodb/

.vscode/*
# Ignore .vscode files
.vscode/
6 changes: 5 additions & 1 deletion __tests__/authutil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
78 changes: 25 additions & 53 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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', [], {
Expand All @@ -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', [], {
Expand All @@ -233,7 +205,7 @@ describe('installer tests', () => {
expect(normalizeFileContents(currentContents)).toBe(
normalizeFileContents(upToDateContents)
);
}, 100000);
}, 30000);
});

function normalizeFileContents(contents: string): string {
Expand Down
13 changes: 7 additions & 6 deletions __tests__/sample-csproj/Program.cs
Original file line number Diff line number Diff line change
@@ -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!");
}
}
}
7 changes: 0 additions & 7 deletions __tests__/sample-csproj/runtimeconfig.template.json

This file was deleted.

11 changes: 8 additions & 3 deletions __tests__/sample-csproj/sample.csproj
Original file line number Diff line number Diff line change
@@ -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>
Loading

0 comments on commit 3523381

Please sign in to comment.