mirror of
				https://github.com/actions/setup-java.git
				synced 2025-10-31 14:30:53 +00:00 
			
		
		
		
	Implement getAvailableVersions
This commit is contained in:
		
					parent
					
						
							
								dd80852400
							
						
					
				
			
			
				commit
				
					
						852fac3790
					
				
			
		
					 3 changed files with 129 additions and 0 deletions
				
			
		
							
								
								
									
										23
									
								
								__tests__/distributors/coretto-installer.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								__tests__/distributors/coretto-installer.test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| import { HttpClient } from '@actions/http-client'; | ||||
| 
 | ||||
| import { CorettoDistribution } from '../../src/distributions/coretto/installer'; | ||||
| import { JavaInstallerOptions } from '../../src/distributions/base-models'; | ||||
| 
 | ||||
| describe('getAvailableVersions', () => { | ||||
|   beforeEach(() => {}); | ||||
| 
 | ||||
|   afterEach(() => {}); | ||||
| 
 | ||||
|   it('load available versions', async () => { | ||||
|     const distribution = new CorettoDistribution('coretto', { | ||||
|       version: '11', | ||||
|       architecture: 'x64', | ||||
|       packageType: 'jdk', | ||||
|       checkLatest: false | ||||
|     }); | ||||
| 
 | ||||
|     const availableVersions = await distribution['getAvailableVersions'](); | ||||
|     expect(availableVersions).not.toBeNull(); | ||||
|     expect(availableVersions.length).toBe(24); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										82
									
								
								src/distributions/coretto/installer.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								src/distributions/coretto/installer.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,82 @@ | |||
| import * as core from '@actions/core'; | ||||
| import * as tc from '@actions/tool-cache'; | ||||
| import { JavaBase } from '../base-installer'; | ||||
| import { JavaDownloadRelease, JavaInstallerResults } from '../base-models'; | ||||
| import { ICorrettoAllAvailableVersions, ICorettoAvailableVersions } from './models'; | ||||
| 
 | ||||
| export class CorettoDistribution extends JavaBase { | ||||
|   protected downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> { | ||||
|     throw new Error('Method not implemented.'); | ||||
|   } | ||||
|   protected findPackageForDownload(range: string): Promise<JavaDownloadRelease> { | ||||
|     throw new Error('Method not implemented.'); | ||||
|   } | ||||
| 
 | ||||
|   private async getAvailableVersions(): Promise<ICorettoAvailableVersions[]> { | ||||
|     const platform = this.getPlatformOption(); | ||||
|     const arch = this.architecture; | ||||
|     const imageType = this.packageType; | ||||
| 
 | ||||
|     console.time('coretto-retrieve-available-versions'); | ||||
| 
 | ||||
|     const availableVersionsUrl = | ||||
|       'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'; | ||||
|     const fetchResult = await this.http.getJson<ICorrettoAllAvailableVersions>( | ||||
|       availableVersionsUrl | ||||
|     ); | ||||
|     if (!fetchResult.result) { | ||||
|       throw Error(`Could not fetch latest corretto versions from ${availableVersionsUrl}`); | ||||
|     } | ||||
|     const availableVersions: ICorettoAvailableVersions[] = []; | ||||
|     const eligbleVersions = fetchResult.result[platform][arch][imageType]; | ||||
|     for (const version in eligbleVersions) { | ||||
|       const availableVersion = eligbleVersions[version]; | ||||
|       for (const fileType in availableVersion) { | ||||
|         const availableVersionDetails = availableVersion[fileType]; | ||||
|         const correttoVersion = this.getCorettoVersionr(availableVersionDetails.resource); | ||||
| 
 | ||||
|         availableVersions.push({ | ||||
|           checksum: availableVersionDetails.checksum, | ||||
|           checksum_sha256: availableVersionDetails.checksum_sha256, | ||||
|           fileType, | ||||
|           resource: availableVersionDetails.resource, | ||||
|           version: version, | ||||
|           correttoVersion | ||||
|         }); | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     if (core.isDebug()) { | ||||
|       core.startGroup('Print information about available versions'); | ||||
|       console.timeEnd('coretto-retrieve-available-versions'); | ||||
|       console.log(`Available versions: [${availableVersions.length}]`); | ||||
|       console.log( | ||||
|         availableVersions.map(item => `${item.version}: ${item.correttoVersion}`).join(', ') | ||||
|       ); | ||||
|       core.endGroup(); | ||||
|     } | ||||
| 
 | ||||
|     return availableVersions; | ||||
|   } | ||||
| 
 | ||||
|   private getPlatformOption(): string { | ||||
|     // Coretto has its own platform names so we need to map them
 | ||||
|     switch (process.platform) { | ||||
|       case 'darwin': | ||||
|         return 'mac'; | ||||
|       case 'win32': | ||||
|         return 'windows'; | ||||
|       default: | ||||
|         return process.platform; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private getCorettoVersionr(resource: string): string { | ||||
|     const regex = /(\d+.+)\//; | ||||
|     const match = regex.exec(resource); | ||||
|     if (match === null) { | ||||
|       throw Error(`Could not parse corretto version from ${resource}`); | ||||
|     } | ||||
|     return match[1]; | ||||
|   } | ||||
| } | ||||
							
								
								
									
										24
									
								
								src/distributions/coretto/models.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/distributions/coretto/models.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| export interface ICorrettoAllAvailableVersions { | ||||
|   [os: string]: { | ||||
|     [arch: string]: { | ||||
|       [distributionType: string]: { | ||||
|         [version: string]: { | ||||
|           [fileType: string]: { | ||||
|             checksum: string; | ||||
|             checksum_sha256: string; | ||||
|             resource: string; | ||||
|           }; | ||||
|         }; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| export interface ICorettoAvailableVersions { | ||||
|   version: string; | ||||
|   fileType: string; | ||||
|   checksum: string; | ||||
|   checksum_sha256: string; | ||||
|   resource: string; | ||||
|   correttoVersion: string; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue