mirror of
				https://github.com/actions/setup-dotnet.git
				synced 2025-10-31 15:53:45 +00:00 
			
		
		
		
	refactor using of XMLBuilder
This commit is contained in:
		
							parent
							
								
									0ff311b0d0
								
							
						
					
					
						commit
						354d280fa3
					
				
							
								
								
									
										24
									
								
								.licenses/npm/xmlbuilder.dep.yml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										24
									
								
								.licenses/npm/xmlbuilder.dep.yml
									
									
									
										generated
									
									
									
								
							| @ -1,24 +0,0 @@ | ||||
| --- | ||||
| name: xmlbuilder | ||||
| version: 13.0.2 | ||||
| type: npm | ||||
| summary: An XML builder for node.js | ||||
| homepage: http://github.com/oozcitak/xmlbuilder-js | ||||
| license: mit | ||||
| licenses: | ||||
| - sources: LICENSE | ||||
|   text: "The MIT License (MIT)\r\n\r\nCopyright (c) 2013 Ozgur Ozcitak\r\n\r\nPermission | ||||
|     is hereby granted, free of charge, to any person obtaining a copy\r\nof this software | ||||
|     and associated documentation files (the \"Software\"), to deal\r\nin the Software | ||||
|     without restriction, including without limitation the rights\r\nto use, copy, | ||||
|     modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, | ||||
|     and to permit persons to whom the Software is\r\nfurnished to do so, subject to | ||||
|     the following conditions:\r\n\r\nThe above copyright notice and this permission | ||||
|     notice shall be included in\r\nall copies or substantial portions of the Software.\r\n\r\nTHE | ||||
|     SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, | ||||
|     INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR | ||||
|     A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR | ||||
|     COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER | ||||
|     IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION | ||||
|     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\nTHE SOFTWARE.\r\n" | ||||
| notices: [] | ||||
							
								
								
									
										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/io": "^1.0.2", | ||||
|         "fast-xml-parser": "^4.0.10", | ||||
|         "semver": "^6.3.0", | ||||
|         "xmlbuilder": "^13.0.2" | ||||
|         "semver": "^6.3.0" | ||||
|       }, | ||||
|       "devDependencies": { | ||||
|         "@types/jest": "^27.0.2", | ||||
| @ -4673,14 +4672,6 @@ | ||||
|       "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", | ||||
|       "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": { | ||||
|       "version": "2.2.0", | ||||
|       "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", | ||||
| @ -8313,11 +8304,6 @@ | ||||
|       "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "xmlbuilder": { | ||||
|       "version": "13.0.2", | ||||
|       "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-13.0.2.tgz", | ||||
|       "integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==" | ||||
|     }, | ||||
|     "xmlchars": { | ||||
|       "version": "2.2.0", | ||||
|       "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", | ||||
|  | ||||
| @ -30,8 +30,7 @@ | ||||
|     "@actions/http-client": "^2.0.1", | ||||
|     "@actions/io": "^1.0.2", | ||||
|     "fast-xml-parser": "^4.0.10", | ||||
|     "semver": "^6.3.0", | ||||
|     "xmlbuilder": "^13.0.2" | ||||
|     "semver": "^6.3.0" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@types/jest": "^27.0.2", | ||||
|  | ||||
| @ -2,8 +2,7 @@ import * as fs from 'fs'; | ||||
| import * as path from 'path'; | ||||
| import * as core from '@actions/core'; | ||||
| import * as github from '@actions/github'; | ||||
| import * as xmlbuilder from 'xmlbuilder'; | ||||
| import {XMLParser} from 'fast-xml-parser'; | ||||
| import {XMLParser, XMLBuilder} from 'fast-xml-parser'; | ||||
| 
 | ||||
| export function configAuthentication( | ||||
|   feedUrl: string, | ||||
| @ -49,7 +48,6 @@ function writeFeedToFile( | ||||
|   core.info( | ||||
|     `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 owner: string = core.getInput('owner'); | ||||
|   let sourceUrl: string = feedUrl; | ||||
| @ -103,24 +101,50 @@ function writeFeedToFile( | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   xml = xmlbuilder | ||||
|     .create('configuration') | ||||
|     .ele('config') | ||||
|     .ele('add', {key: 'defaultPushSource', value: sourceUrl}) | ||||
|     .up() | ||||
|     .up(); | ||||
|   const xmlSource: any[] = [ | ||||
|     { | ||||
|       '?xml version="1.0"': [ | ||||
|         { | ||||
|           '#text': '' | ||||
|         } | ||||
|       ] | ||||
|     }, | ||||
|     { | ||||
|       configuration: [ | ||||
|         { | ||||
|           config: [ | ||||
|             { | ||||
|               add: [], | ||||
|               ':@': { | ||||
|                 '@_key': 'defaultPushSource', | ||||
|                 '@_value': sourceUrl | ||||
|               } | ||||
|             } | ||||
|           ] | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ]; | ||||
| 
 | ||||
|   if (!sourceKeys.length) { | ||||
|     let keystring = 'Source'; | ||||
|     xml = xml | ||||
|       .ele('packageSources') | ||||
|       .ele('add', {key: keystring, value: sourceUrl}) | ||||
|       .up() | ||||
|       .up(); | ||||
| 
 | ||||
|     xmlSource[1].configuration.push({ | ||||
|       packageSources: [ | ||||
|         { | ||||
|           add: [], | ||||
|           ':@': { | ||||
|             '@_key': keystring, | ||||
|             '@_value': sourceUrl | ||||
|           } | ||||
|         } | ||||
|       ] | ||||
|     }); | ||||
| 
 | ||||
|     sourceKeys.push(keystring); | ||||
|   } | ||||
|   xml = xml.ele('packageSourceCredentials'); | ||||
| 
 | ||||
|   const packageSourceCredentials: any[] = []; | ||||
|   sourceKeys.forEach(key => { | ||||
|     if (!isValidKey(key)) { | ||||
|       throw new Error( | ||||
| @ -128,16 +152,24 @@ function writeFeedToFile( | ||||
|       ); | ||||
|     } | ||||
| 
 | ||||
|     xml = xml | ||||
|       .ele(key) | ||||
|       .ele('add', {key: 'Username', value: owner}) | ||||
|       .up() | ||||
|       .ele('add', { | ||||
|         key: 'ClearTextPassword', | ||||
|         value: process.env.NUGET_AUTH_TOKEN | ||||
|       }) | ||||
|       .up() | ||||
|       .up(); | ||||
|     packageSourceCredentials.push({ | ||||
|       [key]: [ | ||||
|         { | ||||
|           add: [], | ||||
|           ':@': { | ||||
|             '@_key': 'Username', | ||||
|             '@_value': owner | ||||
|           } | ||||
|         }, | ||||
|         { | ||||
|           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),
 | ||||
| @ -146,6 +178,18 @@ function writeFeedToFile( | ||||
|   //             ? '%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); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user