Skip to content

Commit 3523381

Browse files
author
Zachary Eisinger
authored
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
1 parent 3569a93 commit 3523381

16 files changed

+792
-1833
lines changed

.github/workflows/workflow.yml

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
build:
1212
runs-on: ${{ matrix.operating-system }}
1313
strategy:
14+
fail-fast: false
1415
matrix:
1516
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
1617
steps:
@@ -19,7 +20,7 @@ jobs:
1920
- name: Set Node.js 12
2021
uses: actions/setup-node@v1
2122
with:
22-
version: 12.x
23+
node-version: 12.x
2324
- run: npm ci
2425
- run: npm run build
2526
- run: npm run format-check
@@ -31,27 +32,50 @@ jobs:
3132
test:
3233
runs-on: ${{ matrix.operating-system }}
3334
strategy:
35+
fail-fast: false
3436
matrix:
3537
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
3638
steps:
3739
- name: Checkout
3840
uses: actions/checkout@v2
39-
- name: Clear tool cache
40-
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
41-
- name: Setup dotnet 3.0.100
41+
- name: Clear tool cache (macOS)
42+
if: runner.os == 'macos'
43+
run: |
44+
echo $PATH
45+
dotnet --info
46+
rm -rf "/Users/runner/.dotnet"
47+
- name: Clear tool cache (Ubuntu)
48+
if: runner.os == 'linux'
49+
run: |
50+
echo $PATH
51+
dotnet --info
52+
rm -rf "/usr/share/dotnet"
53+
- name: Clear tool cache (Windows)
54+
if: runner.os == 'windows'
55+
run: |
56+
echo $env:PATH
57+
dotnet --info
58+
Remove-Item $env:LocalAppData\Microsoft\dotnet/* -Recurse -Force -ErrorAction SilentlyContinue
59+
Remove-Item "$env:ProgramFiles\dotnet/*" -Recurse -Force -ErrorAction SilentlyContinue
60+
# Side-by-side install of 2.2 and 3.1 used for the test project
61+
- name: Setup dotnet 2.2.402
62+
uses: ./
63+
with:
64+
dotnet-version: 2.2.402
65+
- name: Setup dotnet 3.1.201
4266
uses: ./
4367
with:
44-
dotnet-version: 3.0.100
68+
dotnet-version: 3.1.201
4569
# We are including this veriable to force the generation of the nuget config file to verify that it is created in the correct place
4670
source-url: https://api.nuget.org/v3/index.json
4771
env:
4872
NUGET_AUTH_TOKEN: NOTATOKEN
4973
- name: Verify dotnet
5074
if: runner.os != 'windows'
51-
run: __tests__/verify-dotnet.sh 3.0.100
75+
run: __tests__/verify-dotnet.sh 3.1.201 2.2.402
5276
- name: Verify dotnet (Windows)
5377
if: runner.os == 'windows'
54-
run: __tests__/verify-dotnet.ps1 3.0.100
78+
run: __tests__/verify-dotnet.ps1 3.1.201
5579

5680
test-proxy:
5781
runs-on: ubuntu-latest
@@ -65,37 +89,42 @@ jobs:
6589
- 3128:3128
6690
env:
6791
https_proxy: http://squid-proxy:3128
92+
http_proxy: http://squid-proxy:3128
6893
steps:
6994
- name: Checkout
7095
uses: actions/checkout@v2
7196
- name: Clear tool cache
72-
run: rm -rf $RUNNER_TOOL_CACHE/*
73-
- name: Setup dotnet 3.0.100
97+
run: rm -rf "/usr/share/dotnet"
98+
- name: Install curl
99+
run: |
100+
apt update
101+
apt -y install curl
102+
- name: Setup dotnet 3.1.201
74103
uses: ./
75104
with:
76-
dotnet-version: 3.0.100
105+
dotnet-version: 3.1.201
77106
source-url: https://api.nuget.org/v3/index.json
78107
env:
79108
NUGET_AUTH_TOKEN: NOTATOKEN
80109
- name: Verify dotnet
81-
run: __tests__/verify-dotnet.sh 3.0.100
110+
run: __tests__/verify-dotnet.sh 3.1.201
82111

83112
test-bypass-proxy:
84113
runs-on: ubuntu-latest
85114
env:
86115
https_proxy: http://no-such-proxy:3128
87-
no_proxy: github.com,dotnetcli.blob.core.windows.net,download.visualstudio.microsoft.com,api.nuget.org
116+
no_proxy: github.com,dotnetcli.blob.core.windows.net,download.visualstudio.microsoft.com,api.nuget.org,dotnetcli.azureedge.net
88117
steps:
89118
- name: Checkout
90119
uses: actions/checkout@v2
91120
- name: Clear tool cache
92-
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
93-
- name: Setup dotnet 3.0.100
121+
run: rm -rf "/usr/share/dotnet"
122+
- name: Setup dotnet 3.1.201
94123
uses: ./
95124
with:
96-
dotnet-version: 3.0.100
125+
dotnet-version: 3.1.201
97126
source-url: https://api.nuget.org/v3/index.json
98127
env:
99128
NUGET_AUTH_TOKEN: NOTATOKEN
100129
- name: Verify dotnet
101-
run: __tests__/verify-dotnet.sh 3.0.100
130+
run: __tests__/verify-dotnet.sh 3.1.201

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,5 @@ typings/
9595
# DynamoDB Local files
9696
.dynamodb/
9797

98-
.vscode/*
98+
# Ignore .vscode files
99+
.vscode/

__tests__/authutil.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ describe('authutil tests', () => {
8181
beforeEach(async () => {
8282
await io.rmRF(fakeSourcesDirForTesting);
8383
await io.mkdirP(fakeSourcesDirForTesting);
84-
}, 100000);
84+
}, 30000);
85+
86+
afterAll(async () => {
87+
await io.rmRF(fakeSourcesDirForTesting);
88+
}, 30000);
8589

8690
beforeEach(() => {
8791
if (fs.existsSync(nugetConfigFile)) {

__tests__/installer.test.ts

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ describe('version tests', () => {
7373

7474
describe('installer tests', () => {
7575
beforeAll(async () => {
76+
process.env.RUNNER_TOOL_CACHE = toolDir;
77+
process.env.DOTNET_INSTALL_DIR = toolDir;
78+
process.env.RUNNER_TEMP = tempDir;
7679
await io.rmRF(toolDir);
7780
await io.rmRF(tempDir);
7881
});
@@ -84,23 +87,21 @@ describe('installer tests', () => {
8487
} catch {
8588
console.log('Failed to remove test directories');
8689
}
87-
}, 100000);
90+
}, 30000);
8891

8992
it('Resolving a normal generic version works', async () => {
9093
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.x');
91-
let versInfo = await dotnetInstaller.resolveInfos(
92-
['win-x64'],
94+
let versInfo = await dotnetInstaller.resolveVersion(
9395
new installer.DotNetVersionInfo('3.1.x')
9496
);
9597

96-
expect(versInfo.resolvedVersion.startsWith('3.1.'));
98+
expect(versInfo.startsWith('3.1.'));
9799
}, 100000);
98100

99101
it('Resolving a nonexistent generic version fails', async () => {
100102
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
101103
try {
102-
await dotnetInstaller.resolveInfos(
103-
['win-x64'],
104+
await dotnetInstaller.resolveVersion(
104105
new installer.DotNetVersionInfo('999.1.x')
105106
);
106107
fail();
@@ -111,53 +112,47 @@ describe('installer tests', () => {
111112

112113
it('Resolving a exact stable version works', async () => {
113114
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.201');
114-
let versInfo = await dotnetInstaller.resolveInfos(
115-
['win-x64'],
115+
let versInfo = await dotnetInstaller.resolveVersion(
116116
new installer.DotNetVersionInfo('3.1.201')
117117
);
118118

119-
expect(versInfo.resolvedVersion).toBe('3.1.201');
119+
expect(versInfo).toBe('3.1.201');
120120
}, 100000);
121121

122122
it('Resolving a exact preview version works', async () => {
123123
const dotnetInstaller = new installer.DotnetCoreInstaller(
124-
'5.0.0-preview.4'
124+
'5.0.0-preview.6'
125125
);
126-
let versInfo = await dotnetInstaller.resolveInfos(
127-
['win-x64'],
128-
new installer.DotNetVersionInfo('5.0.0-preview.4')
126+
let versInfo = await dotnetInstaller.resolveVersion(
127+
new installer.DotNetVersionInfo('5.0.0-preview.6')
129128
);
130129

131-
expect(versInfo.resolvedVersion).toBe('5.0.0-preview.4');
130+
expect(versInfo).toBe('5.0.0-preview.6');
132131
}, 100000);
133132

134133
it('Acquires version of dotnet if no matching version is installed', async () => {
135-
await getDotnet('2.2.205');
136-
const dotnetDir = path.join(toolDir, 'dncs', '2.2.205', os.arch());
137-
138-
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
134+
await getDotnet('3.1.201');
135+
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
139136
if (IS_WINDOWS) {
140-
expect(fs.existsSync(path.join(dotnetDir, 'dotnet.exe'))).toBe(true);
137+
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
141138
} else {
142-
expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true);
139+
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
143140
}
144141
}, 400000); //This needs some time to download on "slower" internet connections
145142

146-
it('Acquires version of dotnet if no matching version is installed', async () => {
147-
const dotnetDir = path.join(toolDir, 'dncs', '2.2.105', os.arch());
148-
143+
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
149144
const globalJsonPath = path.join(process.cwd(), 'global.json');
150-
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "2.2.105"${os.EOL}}${os.EOL}}`;
145+
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
151146
if (!fs.existsSync(globalJsonPath)) {
152147
fs.writeFileSync(globalJsonPath, jsonContents);
153148
}
154149
await setup.run();
155150

156-
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
151+
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
157152
if (IS_WINDOWS) {
158-
expect(fs.existsSync(path.join(dotnetDir, 'dotnet.exe'))).toBe(true);
153+
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
159154
} else {
160-
expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true);
155+
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
161156
}
162157
fs.unlinkSync(globalJsonPath);
163158
}, 100000);
@@ -170,30 +165,7 @@ describe('installer tests', () => {
170165
thrown = true;
171166
}
172167
expect(thrown).toBe(true);
173-
}, 100000);
174-
175-
it('Uses version of dotnet installed in cache', async () => {
176-
const dotnetDir: string = path.join(toolDir, 'dncs', '250.0.0', os.arch());
177-
await io.mkdirP(dotnetDir);
178-
fs.writeFileSync(`${dotnetDir}.complete`, 'hello');
179-
// This will throw if it doesn't find it in the cache (because no such version exists)
180-
await getDotnet('250.0.0');
181-
return;
182-
});
183-
184-
it('Doesnt use version of dotnet that was only partially installed in cache', async () => {
185-
const dotnetDir: string = path.join(toolDir, 'dncs', '251.0.0', os.arch());
186-
await io.mkdirP(dotnetDir);
187-
let thrown = false;
188-
try {
189-
// This will throw if it doesn't find it in the cache (because no such version exists)
190-
await getDotnet('251.0.0');
191-
} catch {
192-
thrown = true;
193-
}
194-
expect(thrown).toBe(true);
195-
return;
196-
});
168+
}, 30000);
197169

198170
it('Uses an up to date bash download script', async () => {
199171
const httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
@@ -213,7 +185,7 @@ describe('installer tests', () => {
213185
expect(normalizeFileContents(currentContents)).toBe(
214186
normalizeFileContents(upToDateContents)
215187
);
216-
}, 100000);
188+
}, 30000);
217189

218190
it('Uses an up to date powershell download script', async () => {
219191
var httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
@@ -233,7 +205,7 @@ describe('installer tests', () => {
233205
expect(normalizeFileContents(currentContents)).toBe(
234206
normalizeFileContents(upToDateContents)
235207
);
236-
}, 100000);
208+
}, 30000);
237209
});
238210

239211
function normalizeFileContents(contents: string): string {

__tests__/sample-csproj/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
using System;
2-
using Newtonsoft.Json;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
33

44
namespace sample_csproj
55
{
6-
class Program
6+
[TestClass]
7+
public class Program
78
{
8-
static void Main(string[] args)
9+
[TestMethod]
10+
public void TestMethod1()
911
{
10-
var json = JsonConvert.SerializeObject(new[] {"Hello", "World!" });
11-
Console.WriteLine(json);
12+
Console.WriteLine("Hello, World!");
1213
}
1314
}
1415
}

__tests__/sample-csproj/runtimeconfig.template.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

__tests__/sample-csproj/sample.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFrameworks>netcoreapp3.1;netcoreapp2.2</TargetFrameworks>
65
<RootNamespace>sample_csproj</RootNamespace>
6+
7+
<IsPackable>false</IsPackable>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
11+
<!-- These packages will be downloaded over the network for testing proxy settings -->
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
13+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
14+
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
15+
<PackageReference Include="coverlet.collector" Version="1.2.0" />
1116
</ItemGroup>
1217

1318
</Project>

0 commit comments

Comments
 (0)