mirror of
				https://github.com/actions/setup-java.git
				synced 2025-10-31 22:40:54 +00:00 
			
		
		
		
	fix test and json
This commit is contained in:
		
					parent
					
						
							
								244aafd0a2
							
						
					
				
			
			
				commit
				
					
						ee1310e14d
					
				
			
		
					 6 changed files with 43 additions and 157 deletions
				
			
		|  | @ -1,7 +1,12 @@ | ||||||
| import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer'; | import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer'; | ||||||
|  | import * as tc from '@actions/tool-cache'; | ||||||
|  | import data from '../../versions-manifest.json'; | ||||||
|  | import * as core from '@actions/core'; | ||||||
| 
 | 
 | ||||||
| describe('findPackageForDownload', () => { | describe('findPackageForDownload', () => { | ||||||
|   let distribution: MicrosoftDistributions; |   let distribution: MicrosoftDistributions; | ||||||
|  |   let spyGetManifestFromRepo: jest.SpyInstance; | ||||||
|  |   let spyDebug: jest.SpyInstance; | ||||||
| 
 | 
 | ||||||
|   beforeEach(() => { |   beforeEach(() => { | ||||||
|     distribution = new MicrosoftDistributions({ |     distribution = new MicrosoftDistributions({ | ||||||
|  | @ -10,12 +15,20 @@ describe('findPackageForDownload', () => { | ||||||
|       packageType: 'jdk', |       packageType: 'jdk', | ||||||
|       checkLatest: false |       checkLatest: false | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     spyGetManifestFromRepo = jest.spyOn(tc, 'getManifestFromRepo'); | ||||||
|  |     spyGetManifestFromRepo.mockImplementation(() => { | ||||||
|  |       return data; | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     spyDebug = jest.spyOn(core, 'debug'); | ||||||
|  |     spyDebug.mockImplementation(() => {}); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   it.each([ |   it.each([ | ||||||
|     [ |     [ | ||||||
|       '17.0.1', |       '17.0.1', | ||||||
|       '17.0.1', |       '17.0.1+12.1', | ||||||
|       'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' |       'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' | ||||||
|     ], |     ], | ||||||
|     [ |     [ | ||||||
|  | @ -25,12 +38,12 @@ describe('findPackageForDownload', () => { | ||||||
|     ], |     ], | ||||||
|     [ |     [ | ||||||
|       '16.0.x', |       '16.0.x', | ||||||
|       '16.0.2', |       '16.0.2+7.1', | ||||||
|       'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' |       'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' | ||||||
|     ], |     ], | ||||||
|     [ |     [ | ||||||
|       '11.0.13', |       '11.0.13', | ||||||
|       '11.0.13', |       '11.0.13+8.1', | ||||||
|       'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' |       'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' | ||||||
|     ], |     ], | ||||||
|     [ |     [ | ||||||
|  | @ -67,32 +80,3 @@ describe('findPackageForDownload', () => { | ||||||
|     ); |     ); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
| 
 |  | ||||||
| describe('getPlatformOption', () => { |  | ||||||
|   const distributions = new MicrosoftDistributions({ |  | ||||||
|     architecture: 'x64', |  | ||||||
|     version: '11', |  | ||||||
|     packageType: 'jdk', |  | ||||||
|     checkLatest: false |  | ||||||
|   }); |  | ||||||
| 
 |  | ||||||
|   it.each([ |  | ||||||
|     ['linux', 'tar.gz', 'linux'], |  | ||||||
|     ['darwin', 'tar.gz', 'macos'], |  | ||||||
|     ['win32', 'zip', 'windows'] |  | ||||||
|   ])('os version %s -> %s', (input, expectedArchive, expectedOs) => { |  | ||||||
|     const actual = distributions['getPlatformOption'](input as NodeJS.Platform); |  | ||||||
| 
 |  | ||||||
|     expect(actual.archive).toEqual(expectedArchive); |  | ||||||
|     expect(actual.os).toEqual(expectedOs); |  | ||||||
|   }); |  | ||||||
| 
 |  | ||||||
|   it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])( |  | ||||||
|     'not support os version %s', |  | ||||||
|     input => { |  | ||||||
|       expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow( |  | ||||||
|         /Platform '\w+' is not supported\. Supported platforms: .+/ |  | ||||||
|       ); |  | ||||||
|     } |  | ||||||
|   ); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
							
								
								
									
										45
									
								
								dist/setup/index.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										45
									
								
								dist/setup/index.js
									
										
									
									
										vendored
									
									
								
							|  | @ -102431,32 +102431,13 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { | ||||||
|             if (this.packageType !== 'jdk') { |             if (this.packageType !== 'jdk') { | ||||||
|                 throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type'); |                 throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type'); | ||||||
|             } |             } | ||||||
|             const availableVersionsRaw = yield this.getAvailableVersions(); |             const manifest = yield this.getAvailableVersions(); | ||||||
|             if (!availableVersionsRaw) { |             if (!manifest) { | ||||||
|                 throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); |                 throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); | ||||||
|             } |             } | ||||||
|             const foundRelease = yield tc.findFromManifest(range, true, availableVersionsRaw, this.architecture); |             const foundRelease = yield tc.findFromManifest(range, true, manifest, this.architecture); | ||||||
|             // const opts = this.getPlatformOption();
 |  | ||||||
|             // const availableVersions = availableVersionsRaw.map(item => ({
 |  | ||||||
|             //   url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${
 |  | ||||||
|             //     this.architecture // https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz
 |  | ||||||
|             //   }.${opts.archive}`,
 |  | ||||||
|             //   version: this.convertVersionToSemver(item)
 |  | ||||||
|             // }));
 |  | ||||||
|             // const satisfiedVersion = availableVersions
 |  | ||||||
|             //   .filter(item => isVersionSatisfies(range, item.version))
 |  | ||||||
|             //   .sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
 |  | ||||||
|             // if (!satisfiedVersion) {
 |  | ||||||
|             //   const availableOptions = availableVersions.map(item => item.version).join(', ');
 |  | ||||||
|             //   const availableOptionsMessage = availableOptions
 |  | ||||||
|             //     ? `\nAvailable versions: ${availableOptions}`
 |  | ||||||
|             //     : '';
 |  | ||||||
|             //   throw new Error(
 |  | ||||||
|             //     `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}`
 |  | ||||||
|             //   );
 |  | ||||||
|             // }
 |  | ||||||
|             if (!foundRelease) { |             if (!foundRelease) { | ||||||
|                 throw new Error(`Could not find satisfied version for SemVer ${range}. ${availableVersionsRaw |                 throw new Error(`Could not find satisfied version for SemVer ${range}. ${manifest | ||||||
|                     .map(item => item.version) |                     .map(item => item.version) | ||||||
|                     .join(', ')}`);
 |                     .join(', ')}`);
 | ||||||
|             } |             } | ||||||
|  | @ -102472,24 +102453,6 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { | ||||||
|             return manifest; |             return manifest; | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|     getPlatformOption(platform = process.platform /* for testing */) { |  | ||||||
|         switch (platform) { |  | ||||||
|             case 'darwin': |  | ||||||
|                 return { archive: 'tar.gz', os: 'macos' }; |  | ||||||
|             case 'win32': |  | ||||||
|                 return { archive: 'zip', os: 'windows' }; |  | ||||||
|             case 'linux': |  | ||||||
|                 return { archive: 'tar.gz', os: 'linux' }; |  | ||||||
|             default: |  | ||||||
|                 throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     convertVersionToSemver(version) { |  | ||||||
|         const major = version.version[0]; |  | ||||||
|         const minor = version.version[1]; |  | ||||||
|         const patch = version.version[2]; |  | ||||||
|         return `${major}.${minor}.${patch}`; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| exports.MicrosoftDistributions = MicrosoftDistributions; | exports.MicrosoftDistributions = MicrosoftDistributions; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ import { JavaBase } from '../base-installer'; | ||||||
| import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models'; | import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models'; | ||||||
| import { extractJdkFile, getDownloadArchiveExtension } from '../../util'; | import { extractJdkFile, getDownloadArchiveExtension } from '../../util'; | ||||||
| import * as core from '@actions/core'; | import * as core from '@actions/core'; | ||||||
| import { MicrosoftVersion, PlatformOptions } from './models'; |  | ||||||
| import * as tc from '@actions/tool-cache'; | import * as tc from '@actions/tool-cache'; | ||||||
| import fs from 'fs'; | import fs from 'fs'; | ||||||
| import path from 'path'; | import path from 'path'; | ||||||
|  | @ -54,44 +53,17 @@ export class MicrosoftDistributions extends JavaBase { | ||||||
|       throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type'); |       throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const availableVersionsRaw = await this.getAvailableVersions(); |     const manifest = await this.getAvailableVersions(); | ||||||
| 
 | 
 | ||||||
|     if (!availableVersionsRaw) { |     if (!manifest) { | ||||||
|       throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); |       throw new Error('Could not load manifest for Microsoft Build of OpenJDK'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const foundRelease = await tc.findFromManifest( |     const foundRelease = await tc.findFromManifest(range, true, manifest, this.architecture); | ||||||
|       range, |  | ||||||
|       true, |  | ||||||
|       availableVersionsRaw, |  | ||||||
|       this.architecture |  | ||||||
|     ); |  | ||||||
| 
 |  | ||||||
|     // const opts = this.getPlatformOption();
 |  | ||||||
|     // const availableVersions = availableVersionsRaw.map(item => ({
 |  | ||||||
|     //   url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${
 |  | ||||||
|     //     this.architecture // https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz
 |  | ||||||
|     //   }.${opts.archive}`,
 |  | ||||||
|     //   version: this.convertVersionToSemver(item)
 |  | ||||||
|     // }));
 |  | ||||||
| 
 |  | ||||||
|     // const satisfiedVersion = availableVersions
 |  | ||||||
|     //   .filter(item => isVersionSatisfies(range, item.version))
 |  | ||||||
|     //   .sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
 |  | ||||||
| 
 |  | ||||||
|     // if (!satisfiedVersion) {
 |  | ||||||
|     //   const availableOptions = availableVersions.map(item => item.version).join(', ');
 |  | ||||||
|     //   const availableOptionsMessage = availableOptions
 |  | ||||||
|     //     ? `\nAvailable versions: ${availableOptions}`
 |  | ||||||
|     //     : '';
 |  | ||||||
|     //   throw new Error(
 |  | ||||||
|     //     `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}`
 |  | ||||||
|     //   );
 |  | ||||||
|     // }
 |  | ||||||
| 
 | 
 | ||||||
|     if (!foundRelease) { |     if (!foundRelease) { | ||||||
|       throw new Error( |       throw new Error( | ||||||
|         `Could not find satisfied version for SemVer ${range}. ${availableVersionsRaw |         `Could not find satisfied version for SemVer ${range}. ${manifest | ||||||
|           .map(item => item.version) |           .map(item => item.version) | ||||||
|           .join(', ')}` |           .join(', ')}` | ||||||
|       ); |       ); | ||||||
|  | @ -113,28 +85,4 @@ export class MicrosoftDistributions extends JavaBase { | ||||||
| 
 | 
 | ||||||
|     return manifest; |     return manifest; | ||||||
|   } |   } | ||||||
| 
 |  | ||||||
|   private getPlatformOption( |  | ||||||
|     platform: NodeJS.Platform = process.platform /* for testing */ |  | ||||||
|   ): PlatformOptions { |  | ||||||
|     switch (platform) { |  | ||||||
|       case 'darwin': |  | ||||||
|         return { archive: 'tar.gz', os: 'macos' }; |  | ||||||
|       case 'win32': |  | ||||||
|         return { archive: 'zip', os: 'windows' }; |  | ||||||
|       case 'linux': |  | ||||||
|         return { archive: 'tar.gz', os: 'linux' }; |  | ||||||
|       default: |  | ||||||
|         throw new Error( |  | ||||||
|           `Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'` |  | ||||||
|         ); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   private convertVersionToSemver(version: MicrosoftVersion): string { |  | ||||||
|     const major = version.version[0]; |  | ||||||
|     const minor = version.version[1]; |  | ||||||
|     const patch = version.version[2]; |  | ||||||
|     return `${major}.${minor}.${patch}`; |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,12 +1,2 @@ | ||||||
| type OsVersions = 'linux' | 'macos' | 'windows'; | type OsVersions = 'linux' | 'macos' | 'windows'; | ||||||
| type ArchiveType = 'tar.gz' | 'zip'; | type ArchiveType = 'tar.gz' | 'zip'; | ||||||
| 
 |  | ||||||
| export interface PlatformOptions { |  | ||||||
|   archive: ArchiveType; |  | ||||||
|   os: OsVersions; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export interface MicrosoftVersion { |  | ||||||
|   downloadUrl?: string; |  | ||||||
|   version: Array<number>; |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
|     "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ |     "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||||||
|     // "allowJs": true,                       /* Allow javascript files to be compiled. */ |     // "allowJs": true,                       /* Allow javascript files to be compiled. */ | ||||||
|     // "checkJs": true,                       /* Report errors in .js files. */ |     // "checkJs": true,                       /* Report errors in .js files. */ | ||||||
|  |     "resolveJsonModule": true, | ||||||
|     // "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ |     // "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||||||
|     // "declaration": true,                   /* Generates corresponding '.d.ts' file. */ |     // "declaration": true,                   /* Generates corresponding '.d.ts' file. */ | ||||||
|     // "declarationMap": true,                /* Generates a sourcemap for each corresponding '.d.ts' file. */ |     // "declarationMap": true,                /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||||||
|  |  | ||||||
|  | @ -79,34 +79,34 @@ | ||||||
|         "release_url": "https://aka.ms/download-jdk", |         "release_url": "https://aka.ms/download-jdk", | ||||||
|         "files": [ |         "files": [ | ||||||
|           { |           { | ||||||
|             "filename": "microsoft-jdk-16.0.2+7.1-macos-x64.tar.gz", |             "filename": "microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz", | ||||||
|             "arch": "x64", |             "arch": "x64", | ||||||
|             "platform": "darwin", |             "platform": "darwin", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-macos-x64.tar.gz" |             "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", |             "filename": "microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz", | ||||||
|             "arch": "x64", |             "arch": "x64", | ||||||
|             "platform": "linux", |             "platform": "linux", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-linux-x64.tar.gz" |             "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", |             "filename": "microsoft-jdk-16.0.2.7.1-windows-x64.zip", | ||||||
|             "arch": "x64", |             "arch": "x64", | ||||||
|             "platform": "win32", |             "platform": "win32", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-windows-x64.zip" |             "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", |             "filename": "microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz", | ||||||
|             "arch": "aarch64", |             "arch": "aarch64", | ||||||
|             "platform": "darwin", |             "platform": "darwin", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-macos-aarch64.tar.gz" |             "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", |             "filename": "microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz", | ||||||
|             "arch": "aarch64", |             "arch": "aarch64", | ||||||
|             "platform": "linux", |             "platform": "linux", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2+7.1-linux-aarch64.tar.gz" |             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz" | ||||||
|           } |           } | ||||||
|         ] |         ] | ||||||
|     }, |     }, | ||||||
|  | @ -153,28 +153,28 @@ | ||||||
|         "release_url": "https://aka.ms/download-jdk", |         "release_url": "https://aka.ms/download-jdk", | ||||||
|         "files": [ |         "files": [ | ||||||
|           { |           { | ||||||
|             "filename": "microsoft-jdk-11.0.13+8.1-macos-x64.tar.gz", |             "filename": "microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz", | ||||||
|             "arch": "x64", |             "arch": "x64", | ||||||
|             "platform": "darwin", |             "platform": "darwin", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-macos-x64.tar.gz" |             "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", |             "filename": "microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz", | ||||||
|             "arch": "x64", |             "arch": "x64", | ||||||
|             "platform": "linux", |             "platform": "linux", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-linux-x64.tar.gz" |             "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", |             "filename": "microsoft-jdk-11.0.13.8.1-windows-x64.zip", | ||||||
|             "arch": "x64", |             "arch": "x64", | ||||||
|             "platform": "win32", |             "platform": "win32", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-windows-x64.zip" |             "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", |             "filename": "microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz", | ||||||
|             "arch": "aarch64", |             "arch": "aarch64", | ||||||
|             "platform": "linux", |             "platform": "linux", | ||||||
|             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13+8.1-linux-aarch64.tar.gz" |             "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz" | ||||||
|           } |           } | ||||||
|         ] |         ] | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue