Support for non-GPR sources

This commit is contained in:
Alex Mullans
2019-10-03 17:29:20 -07:00
parent 6bd4969ec6
commit 70528ac007
6 changed files with 203 additions and 65 deletions

View File

@ -22,12 +22,15 @@ exports.configAuthentication = configAuthentication;
function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
console.log(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`);
let xml;
let gprKeys = [];
let sourceKeys = [];
let owner = core.getInput('owner');
if (!owner && feedUrl.indexOf('nuget.pkg.github.com') > -1) {
let sourceUrl = feedUrl;
if (!owner) {
owner = github.context.repo.owner;
}
let sourceUrl = 'https://nuget.pkg.github.com/' + owner;
if (feedUrl.indexOf('nuget.pkg.github.com') > -1) {
sourceUrl = 'https://nuget.pkg.github.com/' + owner;
}
if (!process.env.NUGET_AUTH_TOKEN || process.env.NUGET_AUTH_TOKEN == '') {
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}}');
}
@ -45,10 +48,10 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
// file has only one <add>
if (json.configuration.packageSources.add['@_value']
.toLowerCase()
.includes('nuget.pkg.github.com')) {
.includes(feedUrl.toLowerCase())) {
let key = json.configuration.packageSources.add['@_key'];
gprKeys.push(key);
core.debug(`Found a GPR URL with key ${key}`);
sourceKeys.push(key);
core.debug(`Found a URL with key ${key}`);
}
}
else {
@ -57,10 +60,10 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
core.debug(json.configuration.packageSources.add[i]);
if (json.configuration.packageSources.add[i]['@_value']
.toLowerCase()
.includes('nuget.pkg.github.com')) {
.includes(feedUrl.toLowerCase())) {
let key = json.configuration.packageSources.add[i]['@_key'];
gprKeys.push(key);
core.debug(`Found a GPR URL with key ${key}`);
sourceKeys.push(key);
core.debug(`Found a URL with key ${key}`);
}
}
}
@ -73,22 +76,22 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
.ele('add', { key: 'defaultPushSource', value: sourceUrl })
.up()
.up();
if (gprKeys.length == 0) {
let keystring = 'GPR';
if (sourceKeys.length == 0) {
let keystring = 'Source';
xml = xml
.ele('packageSources')
.ele('add', { key: keystring, value: sourceUrl })
.up()
.up();
gprKeys.push(keystring);
sourceKeys.push(keystring);
}
gprKeys.forEach(key => {
xml = xml
.ele('packageSourceCredentials');
sourceKeys.forEach(key => {
if (key.indexOf(' ') > -1) {
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.");
}
xml = xml
.ele('packageSourceCredentials')
.ele(key)
xml = xml.ele(key)
.ele('add', { key: 'Username', value: owner })
.up()
.ele('add', {

View File

@ -35,8 +35,9 @@ function run() {
yield dotnetInstaller.installDotnet();
}
const sourceUrl = core.getInput('source-url');
const configFile = core.getInput('config-file');
if (sourceUrl) {
auth.configAuthentication(sourceUrl);
auth.configAuthentication(sourceUrl, configFile);
}
// TODO: setup proxy from runner proxy config
const matchersPath = path.join(__dirname, '..', '.github');