mirror of
				https://github.com/actions/setup-dotnet.git
				synced 2025-10-31 15:53:45 +00:00 
			
		
		
		
	Merge pull request #224 from vsafonkin/v-vlsafo/handle-roll-forward-option
Support `rollForward` option from `global.json` file
This commit is contained in:
		
						commit
						f2da928c08
					
				| @ -7,6 +7,7 @@ const toolDir = path.join(__dirname, 'runner', 'tools2'); | ||||
| const tempDir = path.join(__dirname, 'runner', 'temp2'); | ||||
| 
 | ||||
| import * as setup from '../src/setup-dotnet'; | ||||
| import * as dotnetInstaller from '../src/installer'; | ||||
| 
 | ||||
| const IS_WINDOWS = process.platform === 'win32'; | ||||
| 
 | ||||
| @ -19,7 +20,7 @@ describe('setup-dotnet tests', () => { | ||||
|     await io.rmRF(tempDir); | ||||
|   }); | ||||
| 
 | ||||
|   afterAll(async () => { | ||||
|   afterEach(async () => { | ||||
|     try { | ||||
|       await io.rmRF(path.join(process.cwd(), 'global.json')); | ||||
|       await io.rmRF(toolDir); | ||||
| @ -44,4 +45,26 @@ describe('setup-dotnet tests', () => { | ||||
|       expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); | ||||
|     } | ||||
|   }, 400000); | ||||
| 
 | ||||
|   it('Acquires version of dotnet from global.json with rollForward option, install the latest patch', async () => { | ||||
|     const globalJsonPath = path.join(process.cwd(), 'global.json'); | ||||
|     const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version":"3.1.201",${os.EOL}"rollForward":"latestFeature"${os.EOL}}${os.EOL}}`; | ||||
|     if (!fs.existsSync(globalJsonPath)) { | ||||
|       fs.writeFileSync(globalJsonPath, jsonContents); | ||||
|     } | ||||
| 
 | ||||
|     const version = '3.1'; | ||||
|     const installer = new dotnetInstaller.DotnetCoreInstaller(version); | ||||
|     const patchVersion = await installer.resolveVersion( | ||||
|       new dotnetInstaller.DotNetVersionInfo(version) | ||||
|     ); | ||||
|     await setup.run(); | ||||
| 
 | ||||
|     expect(fs.existsSync(path.join(toolDir, 'sdk', patchVersion))).toBe(true); | ||||
|     if (IS_WINDOWS) { | ||||
|       expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); | ||||
|     } else { | ||||
|       expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); | ||||
|     } | ||||
|   }, 400000); | ||||
| }); | ||||
|  | ||||
							
								
								
									
										22
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										22
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @ -7829,12 +7829,7 @@ function run() { | ||||
|                 core.debug('No version found, trying to find version from global.json'); | ||||
|                 const globalJsonPath = path.join(process.cwd(), 'global.json'); | ||||
|                 if (fs.existsSync(globalJsonPath)) { | ||||
|                     const globalJson = JSON.parse( | ||||
|                     // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
 | ||||
|                     fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); | ||||
|                     if (globalJson.sdk && globalJson.sdk.version) { | ||||
|                         version = globalJson.sdk.version; | ||||
|                     } | ||||
|                     version = getVersionFromGlobalJson(globalJsonPath); | ||||
|                 } | ||||
|             } | ||||
|             if (version) { | ||||
| @ -7857,6 +7852,21 @@ function run() { | ||||
|     }); | ||||
| } | ||||
| exports.run = run; | ||||
| function getVersionFromGlobalJson(globalJsonPath) { | ||||
|     let version = ''; | ||||
|     const globalJson = JSON.parse( | ||||
|     // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
 | ||||
|     fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); | ||||
|     if (globalJson.sdk && globalJson.sdk.version) { | ||||
|         version = globalJson.sdk.version; | ||||
|         const rollForward = globalJson.sdk.rollForward; | ||||
|         if (rollForward && rollForward === 'latestFeature') { | ||||
|             const [major, minor] = version.split('.'); | ||||
|             version = `${major}.${minor}`; | ||||
|         } | ||||
|     } | ||||
|     return version; | ||||
| } | ||||
| run(); | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -19,13 +19,7 @@ export async function run() { | ||||
|       core.debug('No version found, trying to find version from global.json'); | ||||
|       const globalJsonPath = path.join(process.cwd(), 'global.json'); | ||||
|       if (fs.existsSync(globalJsonPath)) { | ||||
|         const globalJson = JSON.parse( | ||||
|           // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
 | ||||
|           fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim() | ||||
|         ); | ||||
|         if (globalJson.sdk && globalJson.sdk.version) { | ||||
|           version = globalJson.sdk.version; | ||||
|         } | ||||
|         version = getVersionFromGlobalJson(globalJsonPath); | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
| @ -54,4 +48,21 @@ export async function run() { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| function getVersionFromGlobalJson(globalJsonPath: string): string { | ||||
|   let version: string = ''; | ||||
|   const globalJson = JSON.parse( | ||||
|     // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
 | ||||
|     fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim() | ||||
|   ); | ||||
|   if (globalJson.sdk && globalJson.sdk.version) { | ||||
|     version = globalJson.sdk.version; | ||||
|     const rollForward = globalJson.sdk.rollForward; | ||||
|     if (rollForward && rollForward === 'latestFeature') { | ||||
|       const [major, minor] = version.split('.'); | ||||
|       version = `${major}.${minor}`; | ||||
|     } | ||||
|   } | ||||
|   return version; | ||||
| } | ||||
| 
 | ||||
| run(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user