mirror of
				https://github.com/actions/setup-java.git
				synced 2025-11-04 00:44:20 +00:00 
			
		
		
		
	Fix archive suffix for Windows.
This commit is contained in:
		
							parent
							
								
									2828873ff8
								
							
						
					
					
						commit
						f073089abe
					
				@ -1,34 +1,4 @@
 | 
				
			|||||||
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
 | 
					import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
 | 
				
			||||||
import { ArchitectureOptions } from '../../src/distributions/microsoft/models';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
describe('getArchitectureOptions', () => {
 | 
					 | 
				
			||||||
  it.each([
 | 
					 | 
				
			||||||
    ['x64', { bitness: '64', arch: 'x86' }],
 | 
					 | 
				
			||||||
    ['aarch64', { bitness: '64', arch: 'arm' }]
 | 
					 | 
				
			||||||
  ] as [string, ArchitectureOptions][])('parse architecture %s -> %s', (input, expected) => {
 | 
					 | 
				
			||||||
    const distributions = new MicrosoftDistributions({
 | 
					 | 
				
			||||||
      architecture: input,
 | 
					 | 
				
			||||||
      checkLatest: false,
 | 
					 | 
				
			||||||
      packageType: '',
 | 
					 | 
				
			||||||
      version: ''
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(distributions['getArchitectureOptions']()).toEqual(expected);
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  it.each(['armv6', 's390x'])('not support architecture %s', input => {
 | 
					 | 
				
			||||||
    const distributions = new MicrosoftDistributions({
 | 
					 | 
				
			||||||
      architecture: input,
 | 
					 | 
				
			||||||
      checkLatest: false,
 | 
					 | 
				
			||||||
      packageType: '',
 | 
					 | 
				
			||||||
      version: ''
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    expect(() => distributions['getArchitectureOptions']()).toThrow(
 | 
					 | 
				
			||||||
      /Architecture '\w+' is not supported\. Supported architectures: .*/
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('findPackageForDownload', () => {
 | 
					describe('findPackageForDownload', () => {
 | 
				
			||||||
  let distribution: MicrosoftDistributions;
 | 
					  let distribution: MicrosoftDistributions;
 | 
				
			||||||
@ -46,34 +16,39 @@ describe('findPackageForDownload', () => {
 | 
				
			|||||||
    [
 | 
					    [
 | 
				
			||||||
      '17.x',
 | 
					      '17.x',
 | 
				
			||||||
      '17.0.1',
 | 
					      '17.0.1',
 | 
				
			||||||
      'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.tar.gz'
 | 
					      'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    [
 | 
					    [
 | 
				
			||||||
      '16.0.x',
 | 
					      '16.0.x',
 | 
				
			||||||
      '16.0.2',
 | 
					      '16.0.2',
 | 
				
			||||||
      'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.tar.gz'
 | 
					      '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',
 | 
				
			||||||
      'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.tar.gz'
 | 
					      'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
  ])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
 | 
					  ])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
 | 
				
			||||||
    const result = await distribution['findPackageForDownload'](input);
 | 
					    const result = await distribution['findPackageForDownload'](input);
 | 
				
			||||||
    expect(result.version).toBe(expectedVersion);
 | 
					    expect(result.version).toBe(expectedVersion);
 | 
				
			||||||
    var os: string;
 | 
					    var os: string;
 | 
				
			||||||
 | 
					    var archive: string;
 | 
				
			||||||
    switch (process.platform) {
 | 
					    switch (process.platform) {
 | 
				
			||||||
      case 'darwin':
 | 
					      case 'darwin':
 | 
				
			||||||
        os = 'macos';
 | 
					        os = 'macos';
 | 
				
			||||||
 | 
					        archive = 'tar.gz';
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      case 'win32':
 | 
					      case 'win32':
 | 
				
			||||||
        os = 'windows';
 | 
					        os = 'windows';
 | 
				
			||||||
 | 
					        archive = 'zip';
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      default:
 | 
					      default:
 | 
				
			||||||
        os = process.platform.toString();
 | 
					        os = process.platform.toString();
 | 
				
			||||||
 | 
					        archive = 'tar.gz';
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    expect(result.url).toBe(expectedUrl.replace('{{OS_TYPE}}', os));
 | 
					    const url = expectedUrl.replace('{{OS_TYPE}}', os).replace('{{ARCHIVE_TYPE}}', archive);
 | 
				
			||||||
 | 
					    expect(result.url).toBe(url);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('should throw an error', async () => {
 | 
					  it('should throw an error', async () => {
 | 
				
			||||||
@ -92,13 +67,14 @@ describe('getPlatformOption', () => {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it.each([
 | 
					  it.each([
 | 
				
			||||||
    ['linux', 'linux'],
 | 
					    ['linux', 'tar.gz', 'linux'],
 | 
				
			||||||
    ['darwin', 'macos'],
 | 
					    ['darwin', 'tar.gz', 'macos'],
 | 
				
			||||||
    ['win32', 'windows']
 | 
					    ['win32', 'zip', 'windows']
 | 
				
			||||||
  ])('os version %s -> %s', (input, expected) => {
 | 
					  ])('os version %s -> %s', (input, expectedArchive, expectedOs) => {
 | 
				
			||||||
    const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
 | 
					    const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    expect(actual).toEqual(expected);
 | 
					    expect(actual.archive).toEqual(expectedArchive);
 | 
				
			||||||
 | 
					    expect(actual.os).toEqual(expectedOs);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
 | 
					  it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										6644
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6644
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -3,7 +3,7 @@ import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from
 | 
				
			|||||||
import semver from 'semver';
 | 
					import semver from 'semver';
 | 
				
			||||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
 | 
					import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
 | 
				
			||||||
import * as core from '@actions/core';
 | 
					import * as core from '@actions/core';
 | 
				
			||||||
import { ArchitectureOptions, MicrosoftVersion, OsVersions } from './models';
 | 
					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';
 | 
				
			||||||
@ -41,12 +41,14 @@ export class MicrosoftDistributions extends JavaBase {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
 | 
					  protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
 | 
				
			||||||
 | 
					    if (this.architecture !== 'x64' && this.architecture != 'aarch64') {
 | 
				
			||||||
 | 
					      throw new Error(`Unsupported architecture: ${this.architecture}`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    const availableVersionsRaw = await this.getAvailableVersions();
 | 
					    const availableVersionsRaw = await this.getAvailableVersions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const opts = this.getPlatformOption();
 | 
				
			||||||
    const availableVersions = availableVersionsRaw.map(item => ({
 | 
					    const availableVersions = availableVersionsRaw.map(item => ({
 | 
				
			||||||
      url: `https://aka.ms/download-jdk/microsoft-jdk-${
 | 
					      url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion}-${opts.os}-${this.architecture}.${opts.archive}`,
 | 
				
			||||||
        item.fullVersion
 | 
					 | 
				
			||||||
      }-${this.getPlatformOption()}-${this.architecture}.tar.gz`,
 | 
					 | 
				
			||||||
      version: this.convertVersionToSemver(item)
 | 
					      version: this.convertVersionToSemver(item)
 | 
				
			||||||
    }));
 | 
					    }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -83,39 +85,30 @@ export class MicrosoftDistributions extends JavaBase {
 | 
				
			|||||||
        minorVersion: 0,
 | 
					        minorVersion: 0,
 | 
				
			||||||
        patchVersion: 2,
 | 
					        patchVersion: 2,
 | 
				
			||||||
        fullVersion: '16.0.2.7.1'
 | 
					        fullVersion: '16.0.2.7.1'
 | 
				
			||||||
      },
 | 
					      }
 | 
				
			||||||
      {
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // M1 is only supported for Java 16 & 17
 | 
				
			||||||
 | 
					    if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
 | 
				
			||||||
 | 
					      jdkVersions.push({
 | 
				
			||||||
        majorVersion: 11,
 | 
					        majorVersion: 11,
 | 
				
			||||||
        minorVersion: 0,
 | 
					        minorVersion: 0,
 | 
				
			||||||
        patchVersion: 13,
 | 
					        patchVersion: 13,
 | 
				
			||||||
        fullVersion: '11.0.13.8.1'
 | 
					        fullVersion: '11.0.13.8.1'
 | 
				
			||||||
      }
 | 
					      });
 | 
				
			||||||
    ];
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return jdkVersions;
 | 
					    return jdkVersions;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private getArchitectureOptions(): ArchitectureOptions {
 | 
					  private getPlatformOption(platform: NodeJS.Platform = process.platform): PlatformOptions {
 | 
				
			||||||
    switch (this.architecture) {
 | 
					 | 
				
			||||||
      case 'x64':
 | 
					 | 
				
			||||||
        return { bitness: '64', arch: 'x86' };
 | 
					 | 
				
			||||||
      case 'aarch64':
 | 
					 | 
				
			||||||
        return { bitness: '64', arch: 'arm' };
 | 
					 | 
				
			||||||
      default:
 | 
					 | 
				
			||||||
        throw new Error(
 | 
					 | 
				
			||||||
          `Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}`
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  private getPlatformOption(platform: NodeJS.Platform = process.platform): OsVersions {
 | 
					 | 
				
			||||||
    switch (platform) {
 | 
					    switch (platform) {
 | 
				
			||||||
      case 'darwin':
 | 
					      case 'darwin':
 | 
				
			||||||
        return 'macos';
 | 
					        return { archive: 'tar.gz', os: 'macos' };
 | 
				
			||||||
      case 'win32':
 | 
					      case 'win32':
 | 
				
			||||||
        return 'windows';
 | 
					        return { archive: 'zip', os: 'windows' };
 | 
				
			||||||
      case 'linux':
 | 
					      case 'linux':
 | 
				
			||||||
        return 'linux';
 | 
					        return { archive: 'tar.gz', os: 'linux' };
 | 
				
			||||||
      default:
 | 
					      default:
 | 
				
			||||||
        throw new Error(
 | 
					        throw new Error(
 | 
				
			||||||
          `Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}`
 | 
					          `Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}`
 | 
				
			||||||
 | 
				
			|||||||
@ -1,11 +1,9 @@
 | 
				
			|||||||
export type Bitness = '32' | '64';
 | 
					export type OsVersions = 'linux' | 'macos' | 'windows';
 | 
				
			||||||
export type ArchType = 'arm' | 'ppc' | 'sparc' | 'x86';
 | 
					export type ArchiveType = 'tar.gz' | 'zip';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type OsVersions = 'linux' | 'linux-musl' | 'macos' | 'solaris' | 'windows';
 | 
					export interface PlatformOptions {
 | 
				
			||||||
 | 
					  archive: ArchiveType;
 | 
				
			||||||
export interface ArchitectureOptions {
 | 
					  os: OsVersions;
 | 
				
			||||||
  bitness: Bitness;
 | 
					 | 
				
			||||||
  arch: ArchType;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface MicrosoftVersion {
 | 
					export interface MicrosoftVersion {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user