mirror of
				https://github.com/actions/setup-java.git
				synced 2025-10-30 22:10:54 +00:00 
			
		
		
		
	Merge branch 'main' into dragonwell
This commit is contained in:
		
				commit
				
					
						446ddaedf9
					
				
			
		
					 35 changed files with 8762 additions and 11377 deletions
				
			
		|  | @ -102,7 +102,7 @@ describe('dependency cache', () => { | |||
|         await expect(restore('gradle')).rejects.toThrow( | ||||
|           `No file in ${projectRoot( | ||||
|             workspace | ||||
|           )} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml], make sure you have checked out the target repository` | ||||
|           )} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml,**/versions.properties], make sure you have checked out the target repository` | ||||
|         ); | ||||
|       }); | ||||
|       it('downloads cache based on build.gradle', async () => { | ||||
|  | @ -145,7 +145,7 @@ describe('dependency cache', () => { | |||
|         await expect(restore('sbt')).rejects.toThrow( | ||||
|           `No file in ${projectRoot( | ||||
|             workspace | ||||
|           )} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository` | ||||
|           )} matched to [**/*.sbt,**/project/build.properties,**/project/**.scala,**/project/**.sbt], make sure you have checked out the target repository` | ||||
|         ); | ||||
|       }); | ||||
|       it('downloads cache', async () => { | ||||
|  | @ -156,6 +156,36 @@ describe('dependency cache', () => { | |||
|         expect(spyWarning).not.toHaveBeenCalled(); | ||||
|         expect(spyInfo).toHaveBeenCalledWith('sbt cache is not found'); | ||||
|       }); | ||||
|       it('detects scala and sbt changes under **/project/ folder', async () => { | ||||
|         createFile(join(workspace, 'build.sbt')); | ||||
|         createDirectory(join(workspace, 'project')); | ||||
|         createFile(join(workspace, 'project/DependenciesV1.scala')); | ||||
| 
 | ||||
|         await restore('sbt'); | ||||
|         const firstCall = spySaveState.mock.calls.toString(); | ||||
| 
 | ||||
|         spySaveState.mockClear(); | ||||
|         await restore('sbt'); | ||||
|         const secondCall = spySaveState.mock.calls.toString(); | ||||
| 
 | ||||
|         // Make sure multiple restores produce the same cache
 | ||||
|         expect(firstCall).toBe(secondCall); | ||||
| 
 | ||||
|         spySaveState.mockClear(); | ||||
|         createFile(join(workspace, 'project/DependenciesV2.scala')); | ||||
|         await restore('sbt'); | ||||
|         const thirdCall = spySaveState.mock.calls.toString(); | ||||
| 
 | ||||
|         expect(firstCall).not.toBe(thirdCall); | ||||
|       }); | ||||
|     }); | ||||
|     it('downloads cache based on versions.properties', async () => { | ||||
|       createFile(join(workspace, 'versions.properties')); | ||||
| 
 | ||||
|       await restore('gradle'); | ||||
|       expect(spyCacheRestore).toHaveBeenCalled(); | ||||
|       expect(spyWarning).not.toHaveBeenCalled(); | ||||
|       expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found'); | ||||
|     }); | ||||
|   }); | ||||
|   describe('save', () => { | ||||
|  | @ -311,6 +341,17 @@ describe('dependency cache', () => { | |||
|           expect.stringMatching(/^Cache saved with the key:.*/) | ||||
|         ); | ||||
|       }); | ||||
|       it('uploads cache based on versions.properties', async () => { | ||||
|         createFile(join(workspace, 'versions.properties')); | ||||
|         createStateForSuccessfulRestore(); | ||||
| 
 | ||||
|         await save('gradle'); | ||||
|         expect(spyCacheSave).toHaveBeenCalled(); | ||||
|         expect(spyWarning).not.toHaveBeenCalled(); | ||||
|         expect(spyInfo).toHaveBeenCalledWith( | ||||
|           expect.stringMatching(/^Cache saved with the key:.*/) | ||||
|         ); | ||||
|       }); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
							
								
								
									
										218
									
								
								__tests__/data/microsoft.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										218
									
								
								__tests__/data/microsoft.json
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,218 @@ | |||
| [ | ||||
|     { | ||||
|         "version": "17.0.7", | ||||
|         "stable": true, | ||||
|         "release_url": "https://aka.ms/download-jdk", | ||||
|         "files": [ | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.7-macos-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-macos-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.7-linux-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-linux-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.7-windows-x64.zip", | ||||
|             "arch": "x64", | ||||
|             "platform": "win32", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-windows-x64.zip" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.7-macos-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-macos-aarch64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.7-linux-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-linux-aarch64.tar.gz" | ||||
|           } | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "version": "17.0.1+12.1", | ||||
|         "stable": true, | ||||
|         "release_url": "https://aka.ms/download-jdk", | ||||
|         "files": [ | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.1.12.1-windows-x64.zip", | ||||
|             "arch": "x64", | ||||
|             "platform": "win32", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-windows-x64.zip" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz" | ||||
|           } | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "version": "16.0.2+7.1", | ||||
|         "stable": true, | ||||
|         "release_url": "https://aka.ms/download-jdk", | ||||
|         "files": [ | ||||
|           { | ||||
|             "filename": "microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-16.0.2.7.1-windows-x64.zip", | ||||
|             "arch": "x64", | ||||
|             "platform": "win32", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-windows-x64.zip" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz" | ||||
|           } | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "version": "11.0.19", | ||||
|         "stable": true, | ||||
|         "release_url": "https://aka.ms/download-jdk", | ||||
|         "files": [ | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.19-macos-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-macos-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.19-linux-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-linux-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.19-windows-x64.zip", | ||||
|             "arch": "x64", | ||||
|             "platform": "win32", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-windows-x64.zip" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.19-macos-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-macos-aarch64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.19-linux-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-linux-aarch64.tar.gz" | ||||
|           } | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "version": "11.0.15", | ||||
|         "stable": true, | ||||
|         "release_url": "https://aka.ms/download-jdk", | ||||
|         "files": [ | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.15-macos-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.15-linux-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.15-windows-x64.zip", | ||||
|             "arch": "x64", | ||||
|             "platform": "win32", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-windows-x64.zip" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.15-macos-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-aarch64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.15-linux-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-aarch64.tar.gz" | ||||
|           } | ||||
|         ] | ||||
|     }, | ||||
|     { | ||||
|         "version": "11.0.13+8.1", | ||||
|         "stable": true, | ||||
|         "release_url": "https://aka.ms/download-jdk", | ||||
|         "files": [ | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "darwin", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz", | ||||
|             "arch": "x64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.13.8.1-windows-x64.zip", | ||||
|             "arch": "x64", | ||||
|             "platform": "win32", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-x64.zip" | ||||
|           }, | ||||
|           { | ||||
|             "filename": "microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz", | ||||
|             "arch": "aarch64", | ||||
|             "platform": "linux", | ||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz" | ||||
|           } | ||||
|         ] | ||||
|     } | ||||
| ] | ||||
|  | @ -214,6 +214,93 @@ describe('setupJava', () => { | |||
|     ); | ||||
|   }); | ||||
| 
 | ||||
|   it('java is resolved from toolcache including Contents/Home on MacOS', async () => { | ||||
|     const inputs = { | ||||
|       version: actualJavaVersion, | ||||
|       architecture: 'x86', | ||||
|       packageType: 'jdk', | ||||
|       checkLatest: false | ||||
|     }; | ||||
|     const jdkFile = 'not_existing_one'; | ||||
|     const expected = { | ||||
|       version: actualJavaVersion, | ||||
|       path: path.join( | ||||
|         'Java_jdkfile_jdk', | ||||
|         inputs.version, | ||||
|         inputs.architecture, | ||||
|         'Contents', | ||||
|         'Home' | ||||
|       ) | ||||
|     }; | ||||
|     const originalPlatform = process.platform; | ||||
|     Object.defineProperty(process, 'platform', { | ||||
|       value: 'darwin' | ||||
|     }); | ||||
| 
 | ||||
|     spyFsStat = jest.spyOn(fs, 'existsSync'); | ||||
|     spyFsStat.mockImplementation((file: string) => { | ||||
|       return file.endsWith('Home'); | ||||
|     }); | ||||
| 
 | ||||
|     mockJavaBase = new LocalDistribution(inputs, jdkFile); | ||||
|     await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); | ||||
|     expect(spyGetToolcachePath).toHaveBeenCalled(); | ||||
|     expect(spyCoreInfo).toHaveBeenCalledWith( | ||||
|       `Resolved Java ${actualJavaVersion} from tool-cache` | ||||
|     ); | ||||
|     expect(spyCoreInfo).not.toHaveBeenCalledWith( | ||||
|       `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` | ||||
|     ); | ||||
| 
 | ||||
|     Object.defineProperty(process, 'platform', { | ||||
|       value: originalPlatform | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   it('java is unpacked from jdkfile including Contents/Home on MacOS', async () => { | ||||
|     const inputs = { | ||||
|       version: '11.0.289', | ||||
|       architecture: 'x86', | ||||
|       packageType: 'jdk', | ||||
|       checkLatest: false | ||||
|     }; | ||||
|     const jdkFile = expectedJdkFile; | ||||
|     const expected = { | ||||
|       version: '11.0.289', | ||||
|       path: path.join( | ||||
|         'Java_jdkfile_jdk', | ||||
|         inputs.version, | ||||
|         inputs.architecture, | ||||
|         'Contents', | ||||
|         'Home' | ||||
|       ) | ||||
|     }; | ||||
|     const originalPlatform = process.platform; | ||||
|     Object.defineProperty(process, 'platform', { | ||||
|       value: 'darwin' | ||||
|     }); | ||||
|     spyFsStat = jest.spyOn(fs, 'existsSync'); | ||||
|     spyFsStat.mockImplementation((file: string) => { | ||||
|       return file.endsWith('Home'); | ||||
|     }); | ||||
| 
 | ||||
|     mockJavaBase = new LocalDistribution(inputs, jdkFile); | ||||
|     await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); | ||||
|     expect(spyTcFindAllVersions).toHaveBeenCalled(); | ||||
|     expect(spyCoreInfo).not.toHaveBeenCalledWith( | ||||
|       `Resolved Java ${actualJavaVersion} from tool-cache` | ||||
|     ); | ||||
|     expect(spyCoreInfo).toHaveBeenCalledWith( | ||||
|       `Extracting Java from '${jdkFile}'` | ||||
|     ); | ||||
|     expect(spyCoreInfo).toHaveBeenCalledWith( | ||||
|       `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` | ||||
|     ); | ||||
|     Object.defineProperty(process, 'platform', { | ||||
|       value: originalPlatform | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   it.each([ | ||||
|     [ | ||||
|       { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import {MicrosoftDistributions} from '../../src/distributions/microsoft/installer'; | ||||
| import os from 'os'; | ||||
| import data from '../../src/distributions/microsoft/microsoft-openjdk-versions.json'; | ||||
| import data from '../data/microsoft.json'; | ||||
| import * as httpm from '@actions/http-client'; | ||||
| import * as core from '@actions/core'; | ||||
| 
 | ||||
|  | @ -36,8 +36,8 @@ describe('findPackageForDownload', () => { | |||
|     ], | ||||
|     [ | ||||
|       '17.x', | ||||
|       '17.0.3', | ||||
|       'https://aka.ms/download-jdk/microsoft-jdk-17.0.3-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' | ||||
|       '17.0.7', | ||||
|       'https://aka.ms/download-jdk/microsoft-jdk-17.0.7-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' | ||||
|     ], | ||||
|     [ | ||||
|       '16.0.x', | ||||
|  | @ -53,6 +53,11 @@ describe('findPackageForDownload', () => { | |||
|       '11.0.15', | ||||
|       '11.0.15', | ||||
|       'https://aka.ms/download-jdk/microsoft-jdk-11.0.15-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' | ||||
|     ], | ||||
|     [ | ||||
|       '11.x', | ||||
|       '11.0.19', | ||||
|       'https://aka.ms/download-jdk/microsoft-jdk-11.0.19-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' | ||||
|     ] | ||||
|   ])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => { | ||||
|     const result = await distribution['findPackageForDownload'](input); | ||||
|  | @ -97,7 +102,7 @@ describe('findPackageForDownload', () => { | |||
|       }); | ||||
| 
 | ||||
|       const result = await distro['findPackageForDownload'](version); | ||||
|       const expectedUrl = `https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-${distroArch}.tar.gz`; | ||||
|       const expectedUrl = `https://aka.ms/download-jdk/microsoft-jdk-17.0.7-linux-${distroArch}.tar.gz`; | ||||
| 
 | ||||
|       expect(result.url).toBe(expectedUrl); | ||||
|     } | ||||
|  |  | |||
|  | @ -2,10 +2,12 @@ import {OracleDistribution} from '../../src/distributions/oracle/installer'; | |||
| import os from 'os'; | ||||
| import * as core from '@actions/core'; | ||||
| import {getDownloadArchiveExtension} from '../../src/util'; | ||||
| import {HttpClient} from '@actions/http-client'; | ||||
| 
 | ||||
| describe('findPackageForDownload', () => { | ||||
|   let distribution: OracleDistribution; | ||||
|   let spyDebug: jest.SpyInstance; | ||||
|   let spyHttpClient: jest.SpyInstance; | ||||
| 
 | ||||
|   beforeEach(() => { | ||||
|     distribution = new OracleDistribution({ | ||||
|  | @ -21,19 +23,19 @@ describe('findPackageForDownload', () => { | |||
| 
 | ||||
|   it.each([ | ||||
|     [ | ||||
|       '19', | ||||
|       '19', | ||||
|       'https://download.oracle.com/java/19/latest/jdk-19_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||||
|       '20', | ||||
|       '20', | ||||
|       'https://download.oracle.com/java/20/latest/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||||
|     ], | ||||
|     [ | ||||
|       '19.0.1', | ||||
|       '19.0.1', | ||||
|       'https://download.oracle.com/java/19/archive/jdk-19.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||||
|       '18', | ||||
|       '18', | ||||
|       'https://download.oracle.com/java/18/archive/jdk-18_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||||
|     ], | ||||
|     [ | ||||
|       '18.0.2.1', | ||||
|       '18.0.2.1', | ||||
|       'https://download.oracle.com/java/18/archive/jdk-18.0.2.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||||
|       '20.0.1', | ||||
|       '20.0.1', | ||||
|       'https://download.oracle.com/java/20/archive/jdk-20.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||||
|     ], | ||||
|     [ | ||||
|       '17', | ||||
|  | @ -46,7 +48,33 @@ describe('findPackageForDownload', () => { | |||
|       'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||||
|     ] | ||||
|   ])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => { | ||||
|     /* Needed only for this particular test because some urls might change */ | ||||
|     spyHttpClient = jest.spyOn(HttpClient.prototype, 'head'); | ||||
|     spyHttpClient.mockReturnValue( | ||||
|       Promise.resolve({ | ||||
|         message: { | ||||
|           statusCode: 200 | ||||
|         } | ||||
|       }) | ||||
|     ); | ||||
| 
 | ||||
|     /** | ||||
|      * NOTE - Should fail to retrieve 18 from latest and check archive instead | ||||
|      */ | ||||
|     if (input === '18') { | ||||
|       spyHttpClient.mockReturnValueOnce( | ||||
|         Promise.resolve({ | ||||
|           message: { | ||||
|             statusCode: 404 | ||||
|           } | ||||
|         }) | ||||
|       ); | ||||
|     } | ||||
| 
 | ||||
|     const result = await distribution['findPackageForDownload'](input); | ||||
| 
 | ||||
|     jest.restoreAllMocks(); | ||||
| 
 | ||||
|     expect(result.version).toBe(expectedVersion); | ||||
|     const osType = distribution.getPlatform(); | ||||
|     const archiveType = getDownloadArchiveExtension(); | ||||
|  | @ -65,7 +93,7 @@ describe('findPackageForDownload', () => { | |||
|       jest.spyOn(os, 'arch').mockReturnValue(osArch); | ||||
|       jest.spyOn(os, 'platform').mockReturnValue('linux'); | ||||
| 
 | ||||
|       const version = '17'; | ||||
|       const version = '18'; | ||||
|       const distro = new OracleDistribution({ | ||||
|         version, | ||||
|         architecture: '', // to get default value
 | ||||
|  | @ -79,7 +107,7 @@ describe('findPackageForDownload', () => { | |||
|       } | ||||
|       const archiveType = getDownloadArchiveExtension(); | ||||
|       const result = await distro['findPackageForDownload'](version); | ||||
|       const expectedUrl = `https://download.oracle.com/java/17/latest/jdk-17_${osType}-${distroArch}_bin.${archiveType}`; | ||||
|       const expectedUrl = `https://download.oracle.com/java/18/archive/jdk-18_${osType}-${distroArch}_bin.${archiveType}`; | ||||
| 
 | ||||
|       expect(result.url).toBe(expectedUrl); | ||||
|     } | ||||
|  | @ -92,8 +120,5 @@ describe('findPackageForDownload', () => { | |||
|     await expect(distribution['findPackageForDownload']('11')).rejects.toThrow( | ||||
|       /Oracle JDK is only supported for JDK 17 and later/ | ||||
|     ); | ||||
|     await expect(distribution['findPackageForDownload']('18')).rejects.toThrow( | ||||
|       /Could not find Oracle JDK for SemVer */ | ||||
|     ); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
|  | @ -227,22 +227,3 @@ describe('findPackageForDownload', () => { | |||
|     ).rejects.toThrow(/Could not find satisfied version for semver */); | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| describe('convertVersionToSemver', () => { | ||||
|   it.each([ | ||||
|     [[12], '12'], | ||||
|     [[12, 0], '12.0'], | ||||
|     [[12, 0, 2], '12.0.2'], | ||||
|     [[12, 0, 2, 1], '12.0.2+1'], | ||||
|     [[12, 0, 2, 1, 3], '12.0.2+1'] | ||||
|   ])('%s -> %s', (input: number[], expected: string) => { | ||||
|     const distribution = new ZuluDistribution({ | ||||
|       version: '18', | ||||
|       architecture: 'x86', | ||||
|       packageType: 'jdk', | ||||
|       checkLatest: false | ||||
|     }); | ||||
|     const actual = distribution['convertVersionToSemver'](input); | ||||
|     expect(actual).toBe(expected); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
|  | @ -77,9 +77,9 @@ describe('toolchains tests', () => { | |||
|     }; | ||||
| 
 | ||||
|     const result = `<?xml version="1.0"?>
 | ||||
| <toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0" | ||||
|   xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" | ||||
|   xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd"> | ||||
| <toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" | ||||
|   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|   xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd"> | ||||
|   <toolchain> | ||||
|     <type>jdk</type> | ||||
|     <provides> | ||||
|  | @ -248,9 +248,9 @@ describe('toolchains tests', () => { | |||
|     }; | ||||
| 
 | ||||
|     const expectedToolchains = `<?xml version="1.0"?>
 | ||||
| <toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0" | ||||
|   xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" | ||||
|   xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd"> | ||||
| <toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" | ||||
|   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|   xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd"> | ||||
|   <toolchain> | ||||
|     <type>jdk</type> | ||||
|     <provides> | ||||
|  |  | |||
|  | @ -1,6 +1,10 @@ | |||
| import * as cache from '@actions/cache'; | ||||
| import * as core from '@actions/core'; | ||||
| import {isVersionSatisfies, isCacheFeatureAvailable} from '../src/util'; | ||||
| import { | ||||
|   convertVersionToSemver, | ||||
|   isVersionSatisfies, | ||||
|   isCacheFeatureAvailable | ||||
| } from '../src/util'; | ||||
| 
 | ||||
| jest.mock('@actions/cache'); | ||||
| jest.mock('@actions/core'); | ||||
|  | @ -63,3 +67,16 @@ describe('isCacheFeatureAvailable', () => { | |||
|     expect(isCacheFeatureAvailable()).toBe(true); | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| describe('convertVersionToSemver', () => { | ||||
|   it.each([ | ||||
|     ['12', '12'], | ||||
|     ['12.0', '12.0'], | ||||
|     ['12.0.2', '12.0.2'], | ||||
|     ['12.0.2.1', '12.0.2+1'], | ||||
|     ['12.0.2.1.0', '12.0.2+1.0'] | ||||
|   ])('%s -> %s', (input: string, expected: string) => { | ||||
|     const actual = convertVersionToSemver(input); | ||||
|     expect(actual).toBe(expected); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue