mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-20 07:35:10 +00:00
Run prettier over files
This commit is contained in:
parent
4cc87c6ba3
commit
cf245a75d4
@ -1,308 +1,308 @@
|
|||||||
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()
|
Math.random()
|
||||||
.toString(36)
|
.toString(36)
|
||||||
.substring(7)
|
.substring(7)
|
||||||
),
|
),
|
||||||
's'
|
's'
|
||||||
);
|
);
|
||||||
|
|
||||||
const invalidNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>`;
|
const invalidNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>`;
|
||||||
|
|
||||||
const emptyNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const emptyNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
const gprnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const gprnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
<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" />
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
const gprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const gprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
const twogprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const twogprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="GPR-GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
<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" />
|
<add key="GPR-Actions" value="https://nuget.pkg.github.com/actions/index.json" protocolVersion="3" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
const spaceNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const spaceNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
<add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
<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" />
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>`;
|
</configuration>`;
|
||||||
|
|
||||||
// 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.
|
// 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.
|
||||||
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
||||||
|
|
||||||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||||
process.env['RUNNER_TEMP'] = fakeSourcesDirForTesting;
|
process.env['RUNNER_TEMP'] = fakeSourcesDirForTesting;
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
|
|
||||||
describe('authutil tests', () => {
|
describe('authutil tests', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await io.rmRF(fakeSourcesDirForTesting);
|
await io.rmRF(fakeSourcesDirForTesting);
|
||||||
await io.mkdirP(fakeSourcesDirForTesting);
|
await io.mkdirP(fakeSourcesDirForTesting);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
if (fs.existsSync(nugetConfigFile)) {
|
if (fs.existsSync(nugetConfigFile)) {
|
||||||
fs.unlinkSync(nugetConfigFile);
|
fs.unlinkSync(nugetConfigFile);
|
||||||
}
|
}
|
||||||
process.env['INPUT_OWNER'] = '';
|
process.env['INPUT_OWNER'] = '';
|
||||||
process.env['NUGET_AUTH_TOKEN'] = '';
|
process.env['NUGET_AUTH_TOKEN'] = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
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';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('No existing config, auth token environment variable not provided, throws', async () => {
|
it('No existing config, auth token environment variable not provided, throws', async () => {
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
thrown = true;
|
thrown = true;
|
||||||
}
|
}
|
||||||
expect(thrown).toBe(true);
|
expect(thrown).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
process.env['INPUT_OWNER'] = 'otherorg';
|
process.env['INPUT_OWNER'] = 'otherorg';
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/otherorg/index.json'
|
'https://nuget.pkg.github.com/otherorg/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
|
it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
thrown = true;
|
thrown = true;
|
||||||
}
|
}
|
||||||
expect(thrown).toBe(true);
|
expect(thrown).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
||||||
await auth.configAuthentication('https://nuget.pkg.github.com');
|
await auth.configAuthentication('https://nuget.pkg.github.com');
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ spaces in key, throws for now', async () => {
|
it('Existing config w/ spaces in key, throws for now', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json'
|
'https://nuget.pkg.github.com/OwnerName/index.json'
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
thrown = true;
|
thrown = true;
|
||||||
}
|
}
|
||||||
expect(thrown).toBe(true);
|
expect(thrown).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigDirectory: string = path.join(
|
const inputNuGetConfigDirectory: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'subfolder'
|
'subfolder'
|
||||||
);
|
);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
inputNuGetConfigDirectory,
|
inputNuGetConfigDirectory,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
'subfolder/nuget.config'
|
'subfolder/nuget.config'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fakeSourcesDirForTesting,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
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';
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
await auth.configAuthentication(
|
await auth.configAuthentication(
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json'
|
||||||
);
|
);
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
expect(
|
expect(
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -27,15 +27,16 @@ describe('version tests', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
each([['3.1.x', '3.1'], ['1.1.*', '1.1'], ['2.0', '2.0']]).test(
|
each([
|
||||||
"Generic version '%s' should be '%s'",
|
['3.1.x', '3.1'],
|
||||||
(vers, resVers) => {
|
['1.1.*', '1.1'],
|
||||||
let versInfo = new installer.DotNetVersionInfo(vers);
|
['2.0', '2.0']
|
||||||
|
]).test("Generic version '%s' should be '%s'", (vers, resVers) => {
|
||||||
|
let versInfo = new installer.DotNetVersionInfo(vers);
|
||||||
|
|
||||||
expect(versInfo.isExactVersion()).toBe(false);
|
expect(versInfo.isExactVersion()).toBe(false);
|
||||||
expect(versInfo.version()).toBe(resVers);
|
expect(versInfo.version()).toBe(resVers);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
each([
|
each([
|
||||||
'',
|
'',
|
||||||
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -17816,9 +17816,11 @@ class SxSDotnetCoreInstaller {
|
|||||||
console.log(`Setting up .NET SDK from ${toolPath}...`);
|
console.log(`Setting up .NET SDK from ${toolPath}...`);
|
||||||
let entries = fs_2.readdirSync(toolPath);
|
let entries = fs_2.readdirSync(toolPath);
|
||||||
for (var entry of entries) {
|
for (var entry of entries) {
|
||||||
yield io.cp(path.join(toolPath, entry), dest, { recursive: true, force: true });
|
yield io.cp(path.join(toolPath, entry), dest, {
|
||||||
|
recursive: true,
|
||||||
|
force: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
// cache SxS directory as a tool
|
// cache SxS directory as a tool
|
||||||
let cachedDir = yield tc.cacheDir(dest, this.cachedToolName, 'sxs', this.arch);
|
let cachedDir = yield tc.cacheDir(dest, this.cachedToolName, 'sxs', this.arch);
|
||||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -3688,9 +3688,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"version": "1.18.2",
|
"version": "1.19.1",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
|
||||||
"integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==",
|
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"pretty-format": {
|
"pretty-format": {
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
"@zeit/ncc": "^0.21.0",
|
"@zeit/ncc": "^0.21.0",
|
||||||
"jest": "^26.0.1",
|
"jest": "^26.0.1",
|
||||||
"jest-circus": "^26.0.1",
|
"jest-circus": "^26.0.1",
|
||||||
"prettier": "^1.17.1",
|
"prettier": "^1.19.1",
|
||||||
"ts-jest": "^26.0.0",
|
"ts-jest": "^26.0.0",
|
||||||
"typescript": "^3.9.2",
|
"typescript": "^3.9.2",
|
||||||
"wget-improved": "^3.0.2"
|
"wget-improved": "^3.0.2"
|
||||||
|
272
src/authutil.ts
272
src/authutil.ts
@ -1,136 +1,136 @@
|
|||||||
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';
|
||||||
|
|
||||||
export function configAuthentication(
|
export function configAuthentication(
|
||||||
feedUrl: string,
|
feedUrl: string,
|
||||||
existingFileLocation: string = ''
|
existingFileLocation: string = ''
|
||||||
) {
|
) {
|
||||||
const existingNuGetConfig: string = path.resolve(
|
const existingNuGetConfig: string = path.resolve(
|
||||||
process.env['RUNNER_TEMP'] || process.cwd(),
|
process.env['RUNNER_TEMP'] || process.cwd(),
|
||||||
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
|
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
|
||||||
);
|
);
|
||||||
|
|
||||||
const tempNuGetConfig: string = path.resolve(
|
const tempNuGetConfig: string = path.resolve(
|
||||||
process.env['RUNNER_TEMP'] || process.cwd(),
|
process.env['RUNNER_TEMP'] || process.cwd(),
|
||||||
'../',
|
'../',
|
||||||
'nuget.config'
|
'nuget.config'
|
||||||
);
|
);
|
||||||
|
|
||||||
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (key.indexOf(' ') > -1) {
|
if (key.indexOf(' ') > -1) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"This action currently can't handle source names with spaces. Remove the space from your repo's NuGet.config and try again."
|
"This action currently can't handle source names with spaces. Remove the space from your repo's 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);
|
||||||
}
|
}
|
||||||
|
1101
src/installer.ts
1101
src/installer.ts
File diff suppressed because it is too large
Load Diff
@ -34,12 +34,14 @@ export async function run() {
|
|||||||
let versions = version.split(',');
|
let versions = version.split(',');
|
||||||
console.log(`Specified .NET verions: ${versions}`);
|
console.log(`Specified .NET verions: ${versions}`);
|
||||||
for (var currentVersion of versions) {
|
for (var currentVersion of versions) {
|
||||||
console.log(`Installing .NET SDK ${currentVersion}...`)
|
console.log(`Installing .NET SDK ${currentVersion}...`);
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(currentVersion);
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
currentVersion
|
||||||
|
);
|
||||||
toolPaths.push(await dotnetInstaller.installDotnet());
|
toolPaths.push(await dotnetInstaller.installDotnet());
|
||||||
}
|
}
|
||||||
if (toolPaths.length > 0) {
|
if (toolPaths.length > 0) {
|
||||||
console.log(`Setting up SxS .NET SDK versions...`)
|
console.log(`Setting up SxS .NET SDK versions...`);
|
||||||
const sxsInstall = new installer.SxSDotnetCoreInstaller(toolPaths);
|
const sxsInstall = new installer.SxSDotnetCoreInstaller(toolPaths);
|
||||||
await sxsInstall.setupSxs();
|
await sxsInstall.setupSxs();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user