mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-01-18 14:21:44 +07:00
linter fixes
This commit is contained in:
parent
0b32034241
commit
8bcd8d8b49
@ -1,340 +1,336 @@
|
|||||||
import io = require('@actions/io');
|
import io = require('@actions/io');
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
import path = require('path');
|
import path = require('path');
|
||||||
|
|
||||||
const fakeSourcesDirForTesting = path.join(
|
const fakeSourcesDirForTesting = path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
'runner',
|
'runner',
|
||||||
path.join(
|
path.join(Math.random().toString(36).substring(7)),
|
||||||
Math.random()
|
's'
|
||||||
.toString(36)
|
);
|
||||||
.substring(7)
|
|
||||||
),
|
const invalidNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>`;
|
||||||
's'
|
|
||||||
);
|
const emptyNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
const invalidNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>`;
|
</configuration>`;
|
||||||
|
|
||||||
const emptyNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
</packageSources>
|
||||||
<configuration>
|
</configuration>`;
|
||||||
<packageSources>
|
|
||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
const gprnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
const gprnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
|
||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
const gprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
const gprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
</packageSources>
|
||||||
<configuration>
|
</configuration>`;
|
||||||
<packageSources>
|
|
||||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
const twogprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="GPR-GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
const twogprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="GPR-Actions" value="https://nuget.pkg.github.com/actions/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="GPR-GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
|
||||||
<add key="GPR-Actions" value="https://nuget.pkg.github.com/actions/index.json" protocolVersion="3" />
|
const spaceNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
const spaceNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
</packageSources>
|
||||||
<configuration>
|
</configuration>`;
|
||||||
<packageSources>
|
|
||||||
<add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
||||||
const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
</packageSources>
|
||||||
<configuration>
|
</configuration>`;
|
||||||
<packageSources>
|
|
||||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
||||||
const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
|
||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
// We want a NuGet.config one level above the sources directory, so it doesn't trample a user's NuGet.config but is still picked up by NuGet/dotnet.
|
||||||
</packageSources>
|
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
||||||
</configuration>`;
|
|
||||||
|
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||||
// We want a NuGet.config one level above the sources directory, so it doesn't trample a user's NuGet.config but is still picked up by NuGet/dotnet.
|
import * as auth from '../src/authutil';
|
||||||
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
|
||||||
|
describe('authutil tests', () => {
|
||||||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
beforeEach(async () => {
|
||||||
import * as auth from '../src/authutil';
|
await io.rmRF(fakeSourcesDirForTesting);
|
||||||
|
await io.mkdirP(fakeSourcesDirForTesting);
|
||||||
describe('authutil tests', () => {
|
}, 30000);
|
||||||
beforeEach(async () => {
|
|
||||||
await io.rmRF(fakeSourcesDirForTesting);
|
afterAll(async () => {
|
||||||
await io.mkdirP(fakeSourcesDirForTesting);
|
await io.rmRF(fakeSourcesDirForTesting);
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
afterAll(async () => {
|
beforeEach(() => {
|
||||||
await io.rmRF(fakeSourcesDirForTesting);
|
if (fs.existsSync(nugetConfigFile)) {
|
||||||
}, 30000);
|
fs.unlinkSync(nugetConfigFile);
|
||||||
|
}
|
||||||
beforeEach(() => {
|
process.env['INPUT_OWNER'] = '';
|
||||||
if (fs.existsSync(nugetConfigFile)) {
|
process.env['NUGET_AUTH_TOKEN'] = '';
|
||||||
fs.unlinkSync(nugetConfigFile);
|
});
|
||||||
}
|
|
||||||
process.env['INPUT_OWNER'] = '';
|
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = '';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
await auth.configAuthentication(
|
||||||
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
'',
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('No existing config, auth token environment variable not provided, throws', async () => {
|
||||||
).toMatchSnapshot();
|
let thrown = false;
|
||||||
});
|
try {
|
||||||
|
await auth.configAuthentication(
|
||||||
it('No existing config, auth token environment variable not provided, throws', async () => {
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
let thrown = false;
|
'',
|
||||||
try {
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
} catch {
|
||||||
'',
|
thrown = true;
|
||||||
fakeSourcesDirForTesting
|
}
|
||||||
);
|
expect(thrown).toBe(true);
|
||||||
} catch {
|
});
|
||||||
thrown = true;
|
|
||||||
}
|
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
||||||
expect(thrown).toBe(true);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
process.env['INPUT_OWNER'] = 'otherorg';
|
||||||
|
await auth.configAuthentication(
|
||||||
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
'https://nuget.pkg.github.com/otherorg/index.json',
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
'',
|
||||||
process.env['INPUT_OWNER'] = 'otherorg';
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/otherorg/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
let thrown = false;
|
||||||
'nuget.config'
|
try {
|
||||||
);
|
await auth.configAuthentication(
|
||||||
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
let thrown = false;
|
'',
|
||||||
try {
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
} catch {
|
||||||
'',
|
thrown = true;
|
||||||
fakeSourcesDirForTesting
|
}
|
||||||
);
|
expect(thrown).toBe(true);
|
||||||
} catch {
|
});
|
||||||
thrown = true;
|
|
||||||
}
|
it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
expect(thrown).toBe(true);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
await auth.configAuthentication(
|
||||||
'nuget.config'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
);
|
'',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
await auth.configAuthentication(
|
||||||
'nuget.config'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
);
|
'',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
await auth.configAuthentication(
|
||||||
'nuget.config'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
);
|
'',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
await auth.configAuthentication(
|
||||||
'nuget.config'
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
);
|
'',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
await auth.configAuthentication(
|
||||||
'nuget.config'
|
'https://nuget.pkg.github.com',
|
||||||
);
|
'',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config w/ spaces in key, throws for now', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ spaces in key, throws for now', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
let thrown = false;
|
||||||
'nuget.config'
|
try {
|
||||||
);
|
await auth.configAuthentication(
|
||||||
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
let thrown = false;
|
'',
|
||||||
try {
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
} catch {
|
||||||
'',
|
thrown = true;
|
||||||
fakeSourcesDirForTesting
|
}
|
||||||
);
|
expect(thrown).toBe(true);
|
||||||
} catch {
|
});
|
||||||
thrown = true;
|
|
||||||
}
|
it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
expect(thrown).toBe(true);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigDirectory: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
'subfolder'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigDirectory: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
inputNuGetConfigDirectory,
|
||||||
'subfolder'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
||||||
inputNuGetConfigDirectory,
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
'nuget.config'
|
await auth.configAuthentication(
|
||||||
);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
'subfolder/nuget.config',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'subfolder/nuget.config',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
await auth.configAuthentication(
|
||||||
'nuget.config'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
);
|
'',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
|
fakeSourcesDirForTesting,
|
||||||
it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
'nuget.config'
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
||||||
fakeSourcesDirForTesting,
|
await auth.configAuthentication(
|
||||||
'nuget.config'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
);
|
'',
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
||||||
).toMatchSnapshot();
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
});
|
await auth.configAuthentication(
|
||||||
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
'',
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
fakeSourcesDirForTesting
|
||||||
await auth.configAuthentication(
|
);
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
'',
|
expect(
|
||||||
fakeSourcesDirForTesting
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
);
|
).toMatchSnapshot();
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
});
|
||||||
expect(
|
});
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
|
||||||
).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
310
src/authutil.ts
310
src/authutil.ts
@ -1,155 +1,155 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
import * as xmlbuilder from 'xmlbuilder';
|
import * as xmlbuilder from 'xmlbuilder';
|
||||||
import * as xmlParser from 'fast-xml-parser';
|
import * as xmlParser from 'fast-xml-parser';
|
||||||
import {ProcessEnvOptions} from 'child_process';
|
import {ProcessEnvOptions} from 'child_process';
|
||||||
|
|
||||||
export function configAuthentication(
|
export function configAuthentication(
|
||||||
feedUrl: string,
|
feedUrl: string,
|
||||||
existingFileLocation: string = '',
|
existingFileLocation: string = '',
|
||||||
processRoot: string = process.cwd()
|
processRoot: string = process.cwd()
|
||||||
) {
|
) {
|
||||||
const existingNuGetConfig: string = path.resolve(
|
const existingNuGetConfig: string = path.resolve(
|
||||||
processRoot,
|
processRoot,
|
||||||
existingFileLocation === ''
|
existingFileLocation === ''
|
||||||
? getExistingNugetConfig(processRoot)
|
? getExistingNugetConfig(processRoot)
|
||||||
: existingFileLocation
|
: existingFileLocation
|
||||||
);
|
);
|
||||||
|
|
||||||
const tempNuGetConfig: string = path.resolve(
|
const tempNuGetConfig: string = path.resolve(
|
||||||
processRoot,
|
processRoot,
|
||||||
'../',
|
'../',
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
|
|
||||||
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidKey(key: string): boolean {
|
function isValidKey(key: string): boolean {
|
||||||
return /^[\w\-\.]+$/i.test(key);
|
return /^[\w\-\.]+$/i.test(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExistingNugetConfig(processRoot: string) {
|
function getExistingNugetConfig(processRoot: string) {
|
||||||
const defaultConfigName = 'nuget.config';
|
const defaultConfigName = 'nuget.config';
|
||||||
const configFileNames = fs
|
const configFileNames = fs
|
||||||
.readdirSync(processRoot)
|
.readdirSync(processRoot)
|
||||||
.filter(filename => filename.toLowerCase() === defaultConfigName);
|
.filter(filename => filename.toLowerCase() === defaultConfigName);
|
||||||
if (configFileNames.length) {
|
if (configFileNames.length) {
|
||||||
return configFileNames[0];
|
return configFileNames[0];
|
||||||
}
|
}
|
||||||
return defaultConfigName;
|
return defaultConfigName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeFeedToFile(
|
function writeFeedToFile(
|
||||||
feedUrl: string,
|
feedUrl: string,
|
||||||
existingFileLocation: string,
|
existingFileLocation: string,
|
||||||
tempFileLocation: string
|
tempFileLocation: string
|
||||||
) {
|
) {
|
||||||
console.log(
|
console.log(
|
||||||
`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`
|
`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`
|
||||||
);
|
);
|
||||||
let xml: xmlbuilder.XMLElement;
|
let xml: xmlbuilder.XMLElement;
|
||||||
let sourceKeys: string[] = [];
|
let sourceKeys: string[] = [];
|
||||||
let owner: string = core.getInput('owner');
|
let owner: string = core.getInput('owner');
|
||||||
let sourceUrl: string = feedUrl;
|
let sourceUrl: string = feedUrl;
|
||||||
if (!owner) {
|
if (!owner) {
|
||||||
owner = github.context.repo.owner;
|
owner = github.context.repo.owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.env.NUGET_AUTH_TOKEN || process.env.NUGET_AUTH_TOKEN == '') {
|
if (!process.env.NUGET_AUTH_TOKEN || process.env.NUGET_AUTH_TOKEN == '') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'
|
'The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.existsSync(existingFileLocation)) {
|
if (fs.existsSync(existingFileLocation)) {
|
||||||
// get key from existing NuGet.config so NuGet/dotnet can match credentials
|
// get key from existing NuGet.config so NuGet/dotnet can match credentials
|
||||||
const curContents: string = fs.readFileSync(existingFileLocation, 'utf8');
|
const curContents: string = fs.readFileSync(existingFileLocation, 'utf8');
|
||||||
var json = xmlParser.parse(curContents, {ignoreAttributes: false});
|
var json = xmlParser.parse(curContents, {ignoreAttributes: false});
|
||||||
|
|
||||||
if (typeof json.configuration == 'undefined') {
|
if (typeof json.configuration == 'undefined') {
|
||||||
throw new Error(`The provided NuGet.config seems invalid.`);
|
throw new Error(`The provided NuGet.config seems invalid.`);
|
||||||
}
|
}
|
||||||
if (typeof json.configuration.packageSources != 'undefined') {
|
if (typeof json.configuration.packageSources != 'undefined') {
|
||||||
if (typeof json.configuration.packageSources.add != 'undefined') {
|
if (typeof json.configuration.packageSources.add != 'undefined') {
|
||||||
// file has at least one <add>
|
// file has at least one <add>
|
||||||
if (typeof json.configuration.packageSources.add[0] == 'undefined') {
|
if (typeof json.configuration.packageSources.add[0] == 'undefined') {
|
||||||
// file has only one <add>
|
// file has only one <add>
|
||||||
if (
|
if (
|
||||||
json.configuration.packageSources.add['@_value']
|
json.configuration.packageSources.add['@_value']
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.includes(feedUrl.toLowerCase())
|
.includes(feedUrl.toLowerCase())
|
||||||
) {
|
) {
|
||||||
let key = json.configuration.packageSources.add['@_key'];
|
let key = json.configuration.packageSources.add['@_key'];
|
||||||
sourceKeys.push(key);
|
sourceKeys.push(key);
|
||||||
core.debug(`Found a URL with key ${key}`);
|
core.debug(`Found a URL with key ${key}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// file has 2+ <add>
|
// file has 2+ <add>
|
||||||
for (
|
for (
|
||||||
let i = 0;
|
let i = 0;
|
||||||
i < json.configuration.packageSources.add.length;
|
i < json.configuration.packageSources.add.length;
|
||||||
i++
|
i++
|
||||||
) {
|
) {
|
||||||
const source = json.configuration.packageSources.add[i];
|
const source = json.configuration.packageSources.add[i];
|
||||||
const value = source['@_value'];
|
const value = source['@_value'];
|
||||||
core.debug(`source '${value}'`);
|
core.debug(`source '${value}'`);
|
||||||
if (value.toLowerCase().includes(feedUrl.toLowerCase())) {
|
if (value.toLowerCase().includes(feedUrl.toLowerCase())) {
|
||||||
let key = source['@_key'];
|
let key = source['@_key'];
|
||||||
sourceKeys.push(key);
|
sourceKeys.push(key);
|
||||||
core.debug(`Found a URL with key ${key}`);
|
core.debug(`Found a URL with key ${key}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xml = xmlbuilder
|
xml = xmlbuilder
|
||||||
.create('configuration')
|
.create('configuration')
|
||||||
.ele('config')
|
.ele('config')
|
||||||
.ele('add', {key: 'defaultPushSource', value: sourceUrl})
|
.ele('add', {key: 'defaultPushSource', value: sourceUrl})
|
||||||
.up()
|
.up()
|
||||||
.up();
|
.up();
|
||||||
|
|
||||||
if (sourceKeys.length == 0) {
|
if (sourceKeys.length == 0) {
|
||||||
let keystring = 'Source';
|
let keystring = 'Source';
|
||||||
xml = xml
|
xml = xml
|
||||||
.ele('packageSources')
|
.ele('packageSources')
|
||||||
.ele('add', {key: keystring, value: sourceUrl})
|
.ele('add', {key: keystring, value: sourceUrl})
|
||||||
.up()
|
.up()
|
||||||
.up();
|
.up();
|
||||||
sourceKeys.push(keystring);
|
sourceKeys.push(keystring);
|
||||||
}
|
}
|
||||||
xml = xml.ele('packageSourceCredentials');
|
xml = xml.ele('packageSourceCredentials');
|
||||||
|
|
||||||
sourceKeys.forEach(key => {
|
sourceKeys.forEach(key => {
|
||||||
if (!isValidKey(key)) {
|
if (!isValidKey(key)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."
|
"Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
xml = xml
|
xml = xml
|
||||||
.ele(key)
|
.ele(key)
|
||||||
.ele('add', {key: 'Username', value: owner})
|
.ele('add', {key: 'Username', value: owner})
|
||||||
.up()
|
.up()
|
||||||
.ele('add', {
|
.ele('add', {
|
||||||
key: 'ClearTextPassword',
|
key: 'ClearTextPassword',
|
||||||
value: process.env.NUGET_AUTH_TOKEN
|
value: process.env.NUGET_AUTH_TOKEN
|
||||||
})
|
})
|
||||||
.up()
|
.up()
|
||||||
.up();
|
.up();
|
||||||
});
|
});
|
||||||
|
|
||||||
// If NuGet fixes itself such that on Linux it can look for environment variables in the config file (it doesn't seem to work today),
|
// If NuGet fixes itself such that on Linux it can look for environment variables in the config file (it doesn't seem to work today),
|
||||||
// use this for the value above
|
// use this for the value above
|
||||||
// process.platform == 'win32'
|
// process.platform == 'win32'
|
||||||
// ? '%NUGET_AUTH_TOKEN%'
|
// ? '%NUGET_AUTH_TOKEN%'
|
||||||
// : '$NUGET_AUTH_TOKEN'
|
// : '$NUGET_AUTH_TOKEN'
|
||||||
|
|
||||||
var output = xml.end({pretty: true});
|
var output = xml.end({pretty: true});
|
||||||
fs.writeFileSync(tempFileLocation, output);
|
fs.writeFileSync(tempFileLocation, output);
|
||||||
}
|
}
|
||||||
|
610
src/installer.ts
610
src/installer.ts
@ -1,305 +1,305 @@
|
|||||||
// Load tempDirectory before it gets wiped by tool-cache
|
// Load tempDirectory before it gets wiped by tool-cache
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import hc = require('@actions/http-client');
|
import hc = require('@actions/http-client');
|
||||||
import {chmodSync} from 'fs';
|
import {chmodSync} from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the inputted version information
|
* Represents the inputted version information
|
||||||
*/
|
*/
|
||||||
export class DotNetVersionInfo {
|
export class DotNetVersionInfo {
|
||||||
public inputVersion: string;
|
public inputVersion: string;
|
||||||
private fullversion: string;
|
private fullversion: string;
|
||||||
private isExactVersionSet: boolean = false;
|
private isExactVersionSet: boolean = false;
|
||||||
|
|
||||||
constructor(version: string) {
|
constructor(version: string) {
|
||||||
this.inputVersion = version;
|
this.inputVersion = version;
|
||||||
|
|
||||||
// Check for exact match
|
// Check for exact match
|
||||||
if (semver.valid(semver.clean(version) || '') != null) {
|
if (semver.valid(semver.clean(version) || '') != null) {
|
||||||
this.fullversion = semver.clean(version) as string;
|
this.fullversion = semver.clean(version) as string;
|
||||||
this.isExactVersionSet = true;
|
this.isExactVersionSet = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parts: string[] = version.split('.');
|
const parts: string[] = version.split('.');
|
||||||
|
|
||||||
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
|
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
|
||||||
|
|
||||||
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
|
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
|
||||||
this.throwInvalidVersionFormat();
|
this.throwInvalidVersionFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
const major = this.getVersionNumberOrThrow(parts[0]);
|
const major = this.getVersionNumberOrThrow(parts[0]);
|
||||||
const minor = ['x', '*'].includes(parts[1])
|
const minor = ['x', '*'].includes(parts[1])
|
||||||
? parts[1]
|
? parts[1]
|
||||||
: this.getVersionNumberOrThrow(parts[1]);
|
: this.getVersionNumberOrThrow(parts[1]);
|
||||||
|
|
||||||
this.fullversion = major + '.' + minor;
|
this.fullversion = major + '.' + minor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getVersionNumberOrThrow(input: string): number {
|
private getVersionNumberOrThrow(input: string): number {
|
||||||
try {
|
try {
|
||||||
if (!input || input.trim() === '') this.throwInvalidVersionFormat();
|
if (!input || input.trim() === '') this.throwInvalidVersionFormat();
|
||||||
|
|
||||||
let number = Number(input);
|
let number = Number(input);
|
||||||
|
|
||||||
if (Number.isNaN(number) || number < 0) this.throwInvalidVersionFormat();
|
if (Number.isNaN(number) || number < 0) this.throwInvalidVersionFormat();
|
||||||
|
|
||||||
return number;
|
return number;
|
||||||
} catch {
|
} catch {
|
||||||
this.throwInvalidVersionFormat();
|
this.throwInvalidVersionFormat();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private throwInvalidVersionFormat() {
|
private throwInvalidVersionFormat() {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'
|
'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true exacatly one version should be resolved
|
* If true exacatly one version should be resolved
|
||||||
*/
|
*/
|
||||||
public isExactVersion(): boolean {
|
public isExactVersion(): boolean {
|
||||||
return this.isExactVersionSet;
|
return this.isExactVersionSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public version(): string {
|
public version(): string {
|
||||||
return this.fullversion;
|
return this.fullversion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DotnetCoreInstaller {
|
export class DotnetCoreInstaller {
|
||||||
constructor(version: string, includePrerelease: boolean = false) {
|
constructor(version: string, includePrerelease: boolean = false) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.includePrerelease = includePrerelease;
|
this.includePrerelease = includePrerelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async installDotnet() {
|
public async installDotnet() {
|
||||||
let output = '';
|
let output = '';
|
||||||
let resultCode = 0;
|
let resultCode = 0;
|
||||||
|
|
||||||
let calculatedVersion = await this.resolveVersion(
|
let calculatedVersion = await this.resolveVersion(
|
||||||
new DotNetVersionInfo(this.version)
|
new DotNetVersionInfo(this.version)
|
||||||
);
|
);
|
||||||
|
|
||||||
var envVariables: {[key: string]: string} = {};
|
var envVariables: {[key: string]: string} = {};
|
||||||
for (let key in process.env) {
|
for (let key in process.env) {
|
||||||
if (process.env[key]) {
|
if (process.env[key]) {
|
||||||
let value: any = process.env[key];
|
let value: any = process.env[key];
|
||||||
envVariables[key] = value;
|
envVariables[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
let escapedScript = path
|
let escapedScript = path
|
||||||
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
||||||
.replace(/'/g, "''");
|
.replace(/'/g, "''");
|
||||||
let command = `& '${escapedScript}'`;
|
let command = `& '${escapedScript}'`;
|
||||||
if (calculatedVersion) {
|
if (calculatedVersion) {
|
||||||
command += ` -Version ${calculatedVersion}`;
|
command += ` -Version ${calculatedVersion}`;
|
||||||
}
|
}
|
||||||
if (process.env['https_proxy'] != null) {
|
if (process.env['https_proxy'] != null) {
|
||||||
command += ` -ProxyAddress ${process.env['https_proxy']}`;
|
command += ` -ProxyAddress ${process.env['https_proxy']}`;
|
||||||
}
|
}
|
||||||
// This is not currently an option
|
// This is not currently an option
|
||||||
if (process.env['no_proxy'] != null) {
|
if (process.env['no_proxy'] != null) {
|
||||||
command += ` -ProxyBypassList ${process.env['no_proxy']}`;
|
command += ` -ProxyBypassList ${process.env['no_proxy']}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
|
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
|
||||||
const powershellPath =
|
const powershellPath =
|
||||||
(await io.which('pwsh', false)) || (await io.which('powershell', true));
|
(await io.which('pwsh', false)) || (await io.which('powershell', true));
|
||||||
|
|
||||||
var options: ExecOptions = {
|
var options: ExecOptions = {
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
output += data.toString();
|
output += data.toString();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
env: envVariables
|
env: envVariables
|
||||||
};
|
};
|
||||||
|
|
||||||
resultCode = await exec.exec(
|
resultCode = await exec.exec(
|
||||||
`"${powershellPath}"`,
|
`"${powershellPath}"`,
|
||||||
[
|
[
|
||||||
'-NoLogo',
|
'-NoLogo',
|
||||||
'-Sta',
|
'-Sta',
|
||||||
'-NoProfile',
|
'-NoProfile',
|
||||||
'-NonInteractive',
|
'-NonInteractive',
|
||||||
'-ExecutionPolicy',
|
'-ExecutionPolicy',
|
||||||
'Unrestricted',
|
'Unrestricted',
|
||||||
'-Command',
|
'-Command',
|
||||||
command
|
command
|
||||||
],
|
],
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let escapedScript = path
|
let escapedScript = path
|
||||||
.join(__dirname, '..', 'externals', 'install-dotnet.sh')
|
.join(__dirname, '..', 'externals', 'install-dotnet.sh')
|
||||||
.replace(/'/g, "''");
|
.replace(/'/g, "''");
|
||||||
chmodSync(escapedScript, '777');
|
chmodSync(escapedScript, '777');
|
||||||
|
|
||||||
const scriptPath = await io.which(escapedScript, true);
|
const scriptPath = await io.which(escapedScript, true);
|
||||||
|
|
||||||
let scriptArguments: string[] = [];
|
let scriptArguments: string[] = [];
|
||||||
if (calculatedVersion) {
|
if (calculatedVersion) {
|
||||||
scriptArguments.push('--version', calculatedVersion);
|
scriptArguments.push('--version', calculatedVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
|
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
|
||||||
resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, {
|
resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, {
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
output += data.toString();
|
output += data.toString();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
env: envVariables
|
env: envVariables
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultCode != 0) {
|
if (resultCode != 0) {
|
||||||
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
|
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static addToPath() {
|
static addToPath() {
|
||||||
if (process.env['DOTNET_INSTALL_DIR']) {
|
if (process.env['DOTNET_INSTALL_DIR']) {
|
||||||
core.addPath(process.env['DOTNET_INSTALL_DIR']);
|
core.addPath(process.env['DOTNET_INSTALL_DIR']);
|
||||||
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
|
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
|
||||||
} else {
|
} else {
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
// This is the default set in install-dotnet.ps1
|
// This is the default set in install-dotnet.ps1
|
||||||
core.addPath(
|
core.addPath(
|
||||||
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
|
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
|
||||||
);
|
);
|
||||||
core.exportVariable(
|
core.exportVariable(
|
||||||
'DOTNET_ROOT',
|
'DOTNET_ROOT',
|
||||||
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
|
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// This is the default set in install-dotnet.sh
|
// This is the default set in install-dotnet.sh
|
||||||
core.addPath(path.join(process.env['HOME'] + '', '.dotnet'));
|
core.addPath(path.join(process.env['HOME'] + '', '.dotnet'));
|
||||||
core.exportVariable(
|
core.exportVariable(
|
||||||
'DOTNET_ROOT',
|
'DOTNET_ROOT',
|
||||||
path.join(process.env['HOME'] + '', '.dotnet')
|
path.join(process.env['HOME'] + '', '.dotnet')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(process.env['PATH']);
|
console.log(process.env['PATH']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// versionInfo - versionInfo of the SDK/Runtime
|
// versionInfo - versionInfo of the SDK/Runtime
|
||||||
async resolveVersion(versionInfo: DotNetVersionInfo): Promise<string> {
|
async resolveVersion(versionInfo: DotNetVersionInfo): Promise<string> {
|
||||||
if (versionInfo.isExactVersion()) {
|
if (versionInfo.isExactVersion()) {
|
||||||
return versionInfo.version();
|
return versionInfo.version();
|
||||||
}
|
}
|
||||||
|
|
||||||
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
|
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
|
||||||
allowRetries: true,
|
allowRetries: true,
|
||||||
maxRetries: 3
|
maxRetries: 3
|
||||||
});
|
});
|
||||||
|
|
||||||
const releasesJsonUrl: string = await this.getReleasesJsonUrl(
|
const releasesJsonUrl: string = await this.getReleasesJsonUrl(
|
||||||
httpClient,
|
httpClient,
|
||||||
versionInfo.version().split('.')
|
versionInfo.version().split('.')
|
||||||
);
|
);
|
||||||
|
|
||||||
const releasesResponse = await httpClient.getJson<any>(releasesJsonUrl);
|
const releasesResponse = await httpClient.getJson<any>(releasesJsonUrl);
|
||||||
const releasesResult = releasesResponse.result || {};
|
const releasesResult = releasesResponse.result || {};
|
||||||
let releasesInfo: any[] = releasesResult['releases'];
|
let releasesInfo: any[] = releasesResult['releases'];
|
||||||
releasesInfo = releasesInfo.filter((releaseInfo: any) => {
|
releasesInfo = releasesInfo.filter((releaseInfo: any) => {
|
||||||
return (
|
return (
|
||||||
semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), {
|
semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), {
|
||||||
includePrerelease: this.includePrerelease
|
includePrerelease: this.includePrerelease
|
||||||
}) ||
|
}) ||
|
||||||
semver.satisfies(
|
semver.satisfies(
|
||||||
releaseInfo['sdk']['version-display'],
|
releaseInfo['sdk']['version-display'],
|
||||||
versionInfo.version(),
|
versionInfo.version(),
|
||||||
{
|
{
|
||||||
includePrerelease: this.includePrerelease
|
includePrerelease: this.includePrerelease
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Exclude versions that are newer than the latest if using not exact
|
// Exclude versions that are newer than the latest if using not exact
|
||||||
let latestSdk: string = releasesResult['latest-sdk'];
|
let latestSdk: string = releasesResult['latest-sdk'];
|
||||||
|
|
||||||
releasesInfo = releasesInfo.filter((releaseInfo: any) =>
|
releasesInfo = releasesInfo.filter((releaseInfo: any) =>
|
||||||
semver.lte(releaseInfo['sdk']['version'], latestSdk, {
|
semver.lte(releaseInfo['sdk']['version'], latestSdk, {
|
||||||
includePrerelease: this.includePrerelease
|
includePrerelease: this.includePrerelease
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sort for latest version
|
// Sort for latest version
|
||||||
releasesInfo = releasesInfo.sort((a, b) =>
|
releasesInfo = releasesInfo.sort((a, b) =>
|
||||||
semver.rcompare(a['sdk']['version'], b['sdk']['version'], {
|
semver.rcompare(a['sdk']['version'], b['sdk']['version'], {
|
||||||
includePrerelease: this.includePrerelease
|
includePrerelease: this.includePrerelease
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (releasesInfo.length == 0) {
|
if (releasesInfo.length == 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`
|
`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let release = releasesInfo[0];
|
let release = releasesInfo[0];
|
||||||
return release['sdk']['version'];
|
return release['sdk']['version'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getReleasesJsonUrl(
|
private async getReleasesJsonUrl(
|
||||||
httpClient: hc.HttpClient,
|
httpClient: hc.HttpClient,
|
||||||
versionParts: string[]
|
versionParts: string[]
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const response = await httpClient.getJson<any>(DotNetCoreIndexUrl);
|
const response = await httpClient.getJson<any>(DotNetCoreIndexUrl);
|
||||||
|
|
||||||
const result = response.result || {};
|
const result = response.result || {};
|
||||||
let releasesInfo: any[] = result['releases-index'];
|
let releasesInfo: any[] = result['releases-index'];
|
||||||
|
|
||||||
releasesInfo = releasesInfo.filter((info: any) => {
|
releasesInfo = releasesInfo.filter((info: any) => {
|
||||||
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
|
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
|
||||||
const sdkParts: string[] = info['channel-version'].split('.');
|
const sdkParts: string[] = info['channel-version'].split('.');
|
||||||
if (
|
if (
|
||||||
versionParts.length >= 2 &&
|
versionParts.length >= 2 &&
|
||||||
!(versionParts[1] == 'x' || versionParts[1] == '*')
|
!(versionParts[1] == 'x' || versionParts[1] == '*')
|
||||||
) {
|
) {
|
||||||
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
|
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
|
||||||
}
|
}
|
||||||
return versionParts[0] == sdkParts[0];
|
return versionParts[0] == sdkParts[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (releasesInfo.length === 0) {
|
if (releasesInfo.length === 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Could not find info for version ${versionParts.join(
|
`Could not find info for version ${versionParts.join(
|
||||||
'.'
|
'.'
|
||||||
)} at ${DotNetCoreIndexUrl}`
|
)} at ${DotNetCoreIndexUrl}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const releaseInfo = releasesInfo[0];
|
const releaseInfo = releasesInfo[0];
|
||||||
if (releaseInfo['support-phase'] === 'eol') {
|
if (releaseInfo['support-phase'] === 'eol') {
|
||||||
core.warning(
|
core.warning(
|
||||||
`${releaseInfo['product']} ${releaseInfo['channel-version']} is no longer supported and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the .NET support policy.`
|
`${releaseInfo['product']} ${releaseInfo['channel-version']} is no longer supported and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the .NET support policy.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return releaseInfo['releases.json'];
|
return releaseInfo['releases.json'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private version: string;
|
private version: string;
|
||||||
private includePrerelease: boolean;
|
private includePrerelease: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DotNetCoreIndexUrl: string =
|
const DotNetCoreIndexUrl: string =
|
||||||
'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json';
|
'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json';
|
||||||
|
@ -38,9 +38,8 @@ export async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (versions.length) {
|
if (versions.length) {
|
||||||
const includePrerelease: boolean = core.getBooleanInput(
|
const includePrerelease: boolean =
|
||||||
'include-prerelease'
|
core.getBooleanInput('include-prerelease');
|
||||||
);
|
|
||||||
let dotnetInstaller!: installer.DotnetCoreInstaller;
|
let dotnetInstaller!: installer.DotnetCoreInstaller;
|
||||||
for (const version of new Set<string>(versions)) {
|
for (const version of new Set<string>(versions)) {
|
||||||
dotnetInstaller = new installer.DotnetCoreInstaller(
|
dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
Loading…
Reference in New Issue
Block a user