Compare commits

..

15 Commits

Author SHA1 Message Date
80ad5026f3 Update signed version 2024-12-26 13:59:06 -06:00
fe6959d227 Fix proxy test failure 2024-12-26 08:47:38 -06:00
6ef01d5b7e Update installer.ts 2024-12-26 14:01:10 +05:30
01bdbbf7b0 Update installer.ts 2024-12-26 14:00:21 +05:30
ddb9124064 Fix CI failures dist 2024-12-25 22:19:34 -06:00
18e3bffb12 Add fallback logic 2024-12-25 22:04:41 -06:00
ac0b2277f9 Install libssl1.1 to fix CI failures 2024-12-25 20:19:32 -06:00
6c86102234 Fix libssl issue 2024-12-25 20:14:30 -06:00
f5096c4df0 Fix globalization invariant issue 2024-12-25 20:10:18 -06:00
5eb3863f79 Fix Proxy env issue 2024-12-25 20:07:31 -06:00
540f47615b Fix proxy test issue 2024-12-25 19:57:37 -06:00
e78e2b6823 Fix upload-artifact@v4 2024-12-25 19:52:50 -06:00
cd6102d6ea Fix CI failures for ubuntu-latest 2024-12-25 19:52:00 -06:00
7ccaf0b56d Fix Workflow 2024-12-25 19:41:38 -06:00
94bfe42e69 new cdn url changes 2024-12-25 19:37:39 -06:00
5 changed files with 2108 additions and 2095 deletions

View File

@ -1,336 +1,340 @@
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(Math.random().toString(36).substring(7)), path.join(
's' Math.random()
); .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>
</configuration>`; const invalidNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>`;
const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?> const emptyNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<packageSources> </configuration>`;
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources> const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
</configuration>`; <configuration>
<packageSources>
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 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 gprNuGetConfig: 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" />
</packageSources> const gprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
</configuration>`; <configuration>
<packageSources>
const twogprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?> <add key="GPR" value="https://nuget.pkg.github.com/OwnerName/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 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 spaceNuGetConfig: 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" />
</packageSources> const spaceNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
</configuration>`; <configuration>
<packageSources>
const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?> <add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/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" />
</packageSources> const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
</configuration>`; <configuration>
<packageSources>
const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?> <add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/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" /> 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" />
// 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. <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config'); </packageSources>
</configuration>`;
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
import * as auth from '../src/authutil'; // 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');
describe('authutil tests', () => {
beforeEach(async () => { process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
await io.rmRF(fakeSourcesDirForTesting); import * as auth from '../src/authutil';
await io.mkdirP(fakeSourcesDirForTesting);
}, 30000); describe('authutil tests', () => {
beforeEach(async () => {
afterAll(async () => { await io.rmRF(fakeSourcesDirForTesting);
await io.rmRF(fakeSourcesDirForTesting); await io.mkdirP(fakeSourcesDirForTesting);
}, 30000); }, 30000);
beforeEach(() => { afterAll(async () => {
if (fs.existsSync(nugetConfigFile)) { await io.rmRF(fakeSourcesDirForTesting);
fs.unlinkSync(nugetConfigFile); }, 30000);
}
process.env['INPUT_OWNER'] = ''; beforeEach(() => {
process.env['NUGET_AUTH_TOKEN'] = ''; if (fs.existsSync(nugetConfigFile)) {
}); fs.unlinkSync(nugetConfigFile);
}
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { process.env['INPUT_OWNER'] = '';
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; process.env['NUGET_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 () => {
fakeSourcesDirForTesting process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com/OwnerName/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('No existing config, auth token environment variable not provided, throws', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
let thrown = false; ).toMatchSnapshot();
try { });
await auth.configAuthentication(
'https://nuget.pkg.github.com/OwnerName/index.json', it('No existing config, auth token environment variable not provided, throws', async () => {
'', let thrown = false;
fakeSourcesDirForTesting try {
); await auth.configAuthentication(
} catch { 'https://nuget.pkg.github.com/OwnerName/index.json',
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 () => { }
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; expect(thrown).toBe(true);
process.env['INPUT_OWNER'] = 'otherorg'; });
await auth.configAuthentication(
'https://nuget.pkg.github.com/otherorg/index.json', 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';
fakeSourcesDirForTesting process.env['INPUT_OWNER'] = 'otherorg';
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com/otherorg/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
); process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig); const inputNuGetConfigPath: string = path.join(
let thrown = false; fakeSourcesDirForTesting,
try { 'nuget.config'
await auth.configAuthentication( );
'https://nuget.pkg.github.com/OwnerName/index.json', fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
'', let thrown = false;
fakeSourcesDirForTesting try {
); await auth.configAuthentication(
} catch { 'https://nuget.pkg.github.com/OwnerName/index.json',
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 () => { }
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; expect(thrown).toBe(true);
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' 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';
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig); const inputNuGetConfigPath: string = path.join(
await auth.configAuthentication( fakeSourcesDirForTesting,
'https://nuget.pkg.github.com/OwnerName/index.json', 'nuget.config'
'', );
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com/OwnerName/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' 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';
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig); const inputNuGetConfigPath: string = path.join(
await auth.configAuthentication( fakeSourcesDirForTesting,
'https://nuget.pkg.github.com/OwnerName/index.json', 'nuget.config'
'', );
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com/OwnerName/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' 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';
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig); const inputNuGetConfigPath: string = path.join(
await auth.configAuthentication( fakeSourcesDirForTesting,
'https://nuget.pkg.github.com/OwnerName/index.json', 'nuget.config'
'', );
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com/OwnerName/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' 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';
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig); const inputNuGetConfigPath: string = path.join(
await auth.configAuthentication( fakeSourcesDirForTesting,
'https://nuget.pkg.github.com/OwnerName/index.json', 'nuget.config'
'', );
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com/OwnerName/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' 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';
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig); const inputNuGetConfigPath: string = path.join(
await auth.configAuthentication( fakeSourcesDirForTesting,
'https://nuget.pkg.github.com', 'nuget.config'
'', );
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config w/ spaces in key, throws for now', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' it('Existing config w/ spaces in key, throws for now', async () => {
); process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig); const inputNuGetConfigPath: string = path.join(
let thrown = false; fakeSourcesDirForTesting,
try { 'nuget.config'
await auth.configAuthentication( );
'https://nuget.pkg.github.com/OwnerName/index.json', fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
'', let thrown = false;
fakeSourcesDirForTesting try {
); await auth.configAuthentication(
} catch { 'https://nuget.pkg.github.com/OwnerName/index.json',
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 () => { }
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; expect(thrown).toBe(true);
const inputNuGetConfigDirectory: string = path.join( });
fakeSourcesDirForTesting,
'subfolder' 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';
const inputNuGetConfigPath: string = path.join( const inputNuGetConfigDirectory: string = path.join(
inputNuGetConfigDirectory, fakeSourcesDirForTesting,
'nuget.config' 'subfolder'
); );
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true}); const inputNuGetConfigPath: string = path.join(
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig); inputNuGetConfigDirectory,
await auth.configAuthentication( 'nuget.config'
'https://nuget.pkg.github.com/OwnerName/index.json', );
'subfolder/nuget.config', fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://nuget.pkg.github.com/OwnerName/index.json',
expect( 'subfolder/nuget.config',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' 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';
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig); const inputNuGetConfigPath: string = path.join(
await auth.configAuthentication( fakeSourcesDirForTesting,
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', 'nuget.config'
'', );
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
const inputNuGetConfigPath: string = path.join( });
fakeSourcesDirForTesting,
'nuget.config' 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';
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig); const inputNuGetConfigPath: string = path.join(
await auth.configAuthentication( fakeSourcesDirForTesting,
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json', 'nuget.config'
'', );
fakeSourcesDirForTesting fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
expect(
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => { fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN'; ).toMatchSnapshot();
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 () => {
fakeSourcesDirForTesting process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
); await auth.configAuthentication(
expect(fs.existsSync(nugetConfigFile)).toBe(true); 'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
expect( '',
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'}) fakeSourcesDirForTesting
).toMatchSnapshot(); );
}); expect(fs.existsSync(nugetConfigFile)).toBe(true);
}); expect(
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
).toMatchSnapshot();
});
});

2595
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -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);
} }

View File

@ -1,305 +1,312 @@
// 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); let response;
try {
const result = response.result || {}; response = await httpClient.getJson<any>(DotNetCoreIndexUrl);
let releasesInfo: any[] = result['releases-index']; } catch (error) {
response = await httpClient.getJson<any>(DotnetCoreIndexFallbackUrl);
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. const result = response.result || {};
const sdkParts: string[] = info['channel-version'].split('.'); let releasesInfo: any[] = result['releases-index'];
if (
versionParts.length >= 2 && releasesInfo = releasesInfo.filter((info: any) => {
!(versionParts[1] == 'x' || versionParts[1] == '*') // 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('.');
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1]; if (
} versionParts.length >= 2 &&
return versionParts[0] == sdkParts[0]; !(versionParts[1] == 'x' || versionParts[1] == '*')
}); ) {
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
if (releasesInfo.length === 0) { }
throw new Error( return versionParts[0] == sdkParts[0];
`Could not find info for version ${versionParts.join( });
'.'
)} at ${DotNetCoreIndexUrl}` if (releasesInfo.length === 0) {
); throw new Error(
} `Could not find info for version ${versionParts.join(
'.'
const releaseInfo = releasesInfo[0]; )} at ${DotNetCoreIndexUrl}`
if (releaseInfo['support-phase'] === 'eol') { );
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.`
); const releaseInfo = releasesInfo[0];
} if (releaseInfo['support-phase'] === 'eol') {
core.warning(
return releaseInfo['releases.json']; `${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.`
} );
}
private version: string;
private includePrerelease: boolean; return releaseInfo['releases.json'];
} }
const DotNetCoreIndexUrl: string = private version: string;
'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json'; private includePrerelease: boolean;
}
const DotNetCoreIndexUrl: string =
'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json';
const DotnetCoreIndexFallbackUrl: string =
'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';

View File

@ -38,8 +38,9 @@ export async function run() {
} }
if (versions.length) { if (versions.length) {
const includePrerelease: boolean = const includePrerelease: boolean = core.getBooleanInput(
core.getBooleanInput('include-prerelease'); '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(