mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-22 19:41:08 +07:00
refactor using of XMLBuilder
This commit is contained in:
parent
0ff311b0d0
commit
354d280fa3
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
Binary file not shown.
5274
dist/index.js
vendored
5274
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
16
package-lock.json
generated
16
package-lock.json
generated
@ -15,8 +15,7 @@
|
|||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"fast-xml-parser": "^4.0.10",
|
"fast-xml-parser": "^4.0.10",
|
||||||
"semver": "^6.3.0",
|
"semver": "^6.3.0"
|
||||||
"xmlbuilder": "^13.0.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
@ -4673,14 +4672,6 @@
|
|||||||
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/xmlbuilder": {
|
|
||||||
"version": "13.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-13.0.2.tgz",
|
|
||||||
"integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/xmlchars": {
|
"node_modules/xmlchars": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
||||||
@ -8313,11 +8304,6 @@
|
|||||||
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"xmlbuilder": {
|
|
||||||
"version": "13.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-13.0.2.tgz",
|
|
||||||
"integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ=="
|
|
||||||
},
|
|
||||||
"xmlchars": {
|
"xmlchars": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"fast-xml-parser": "^4.0.10",
|
"fast-xml-parser": "^4.0.10",
|
||||||
"semver": "^6.3.0",
|
"semver": "^6.3.0"
|
||||||
"xmlbuilder": "^13.0.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
|
@ -2,8 +2,7 @@ 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 {XMLParser, XMLBuilder} from 'fast-xml-parser';
|
||||||
import {XMLParser} from 'fast-xml-parser';
|
|
||||||
|
|
||||||
export function configAuthentication(
|
export function configAuthentication(
|
||||||
feedUrl: string,
|
feedUrl: string,
|
||||||
@ -49,7 +48,6 @@ function writeFeedToFile(
|
|||||||
core.info(
|
core.info(
|
||||||
`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 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;
|
||||||
@ -103,24 +101,50 @@ function writeFeedToFile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xml = xmlbuilder
|
const xmlSource: any[] = [
|
||||||
.create('configuration')
|
{
|
||||||
.ele('config')
|
'?xml version="1.0"': [
|
||||||
.ele('add', {key: 'defaultPushSource', value: sourceUrl})
|
{
|
||||||
.up()
|
'#text': ''
|
||||||
.up();
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
configuration: [
|
||||||
|
{
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
add: [],
|
||||||
|
':@': {
|
||||||
|
'@_key': 'defaultPushSource',
|
||||||
|
'@_value': sourceUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
if (!sourceKeys.length) {
|
if (!sourceKeys.length) {
|
||||||
let keystring = 'Source';
|
let keystring = 'Source';
|
||||||
xml = xml
|
|
||||||
.ele('packageSources')
|
xmlSource[1].configuration.push({
|
||||||
.ele('add', {key: keystring, value: sourceUrl})
|
packageSources: [
|
||||||
.up()
|
{
|
||||||
.up();
|
add: [],
|
||||||
|
':@': {
|
||||||
|
'@_key': keystring,
|
||||||
|
'@_value': sourceUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
sourceKeys.push(keystring);
|
sourceKeys.push(keystring);
|
||||||
}
|
}
|
||||||
xml = xml.ele('packageSourceCredentials');
|
|
||||||
|
|
||||||
|
const packageSourceCredentials: any[] = [];
|
||||||
sourceKeys.forEach(key => {
|
sourceKeys.forEach(key => {
|
||||||
if (!isValidKey(key)) {
|
if (!isValidKey(key)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -128,16 +152,24 @@ function writeFeedToFile(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
xml = xml
|
packageSourceCredentials.push({
|
||||||
.ele(key)
|
[key]: [
|
||||||
.ele('add', {key: 'Username', value: owner})
|
{
|
||||||
.up()
|
add: [],
|
||||||
.ele('add', {
|
':@': {
|
||||||
key: 'ClearTextPassword',
|
'@_key': 'Username',
|
||||||
value: process.env.NUGET_AUTH_TOKEN
|
'@_value': owner
|
||||||
})
|
}
|
||||||
.up()
|
},
|
||||||
.up();
|
{
|
||||||
|
add: [],
|
||||||
|
':@': {
|
||||||
|
'@_key': 'ClearTextPassword',
|
||||||
|
'@_value': process.env.NUGET_AUTH_TOKEN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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),
|
||||||
@ -146,6 +178,18 @@ function writeFeedToFile(
|
|||||||
// ? '%NUGET_AUTH_TOKEN%'
|
// ? '%NUGET_AUTH_TOKEN%'
|
||||||
// : '$NUGET_AUTH_TOKEN'
|
// : '$NUGET_AUTH_TOKEN'
|
||||||
|
|
||||||
const output = xml.end({pretty: true});
|
const xmlBuilderOptions = {
|
||||||
|
format: true,
|
||||||
|
ignoreAttributes: false,
|
||||||
|
preserveOrder: true,
|
||||||
|
allowBooleanAttributes: true,
|
||||||
|
suppressBooleanAttributes: true,
|
||||||
|
suppressEmptyNode: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const builder = new XMLBuilder(xmlBuilderOptions);
|
||||||
|
|
||||||
|
const output = builder.build(xmlSource);
|
||||||
|
|
||||||
fs.writeFileSync(tempFileLocation, output);
|
fs.writeFileSync(tempFileLocation, output);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user